早睡早起,方能养生
Sleep early rise early, way to keep healthy

Linux服务器安装Shadowsocks

super
2021-03-10 12:41
views 25143

注:本教程仅供学习交流使用,请勿用于非法用途!

 

CentOS

 

1)安装pip

 

yum install python-pip

 

2)安装Shadowsocks

 

tip:因Shadowsocks作者不再维护pip中的Shadowsocks(定格在了2.8.2),我们使用下面的命令来安装最新版的Shadowsocks:

 

pip install https://github.com/shadowsocks/shadowsocks/archive/master.zip

 

如果提示以下错误:

 

 

安装pip3,使用pip3安装即可

 

yum install -y python3-pip

 

pip3 install https://github.com/shadowsocks/shadowsocks/archive/master.zip

 

 

安装完成后使用下面的命令查看Shadowsocks版本:

 

ssserver --version

 

image.png

 

3)创建配置文件:

 

vi /etc/shadowsocks.json

 

粘贴以下内容:

 

 单用户:

 

{
    "server" :"你的IP地址" ,
    "server_port" :8388,
    "local_port" :1080,
    "password" : "your password" ,
    "timeout" :600,
    "method" : "aes-256-gcm"
}

 

多用户:

 

{
    "server":"你的IP地址",
    "local_address": "127.0.0.1",
    "local_port":1080,
    "port_password": {
		"8388": "password1",   # 端口 + 密码,相当于账户 + 密码
		"8389": "password2",
		"8390": "password3",
		"8391": "password4"
	},
	"timeout":300,
	"method":"aes-256-gcm", # 加密方式
	"fast_open": false
}

 

tip: server 为你的服务器ip地址(如果是阿里云/腾讯云(等分内网和外网IP的)服务器,上方请填写你的内网IP

 

 端口相当于账号,password为密码

 

 选择单用户或者多用户配置,选其一内容无误即可

 

4)启动

 

ssserver -c /etc/shadowsocks.json

 

没有报错即为运行成功

 

5)测试

 

 下载 Shadowsocks 客户端连接测试

 

https://github.com/shadowsocks/shadowsocks-windows/releases

 

image.png

 

 记得打开服务器端口,如果是阿里云/腾讯云(等分内网和外网IP的)服务器请把服务器地址填写外网IP

 

image.png

 

右键小飞机,"系统代理" 选择 “全局模式”

 

image.png

 

切换过后小飞机会变色,这个时候试试是否正常访问

 

可以访问,先断开连接,进行最后的配置

 

6)配置后台运行

 

vi /etc/systemd/system/shadowsocks-server.service

 

 粘贴以下内容

 

[Unit]
Description=Shadowsocks Server
After=network.target

[Service]
ExecStart=/usr/bin/ssserver -c /etc/shadowsocks.json
Restart=on-abort

[Install]
WantedBy=multi-user.target

 

 tip:ExecStart项为你的ssserver安装位置 及配置文件的位置。 ssserver一般安装在/usr/bin/ssserver,可使用 whereis ssserver 命令查看其位置

 

保存并退出

 

启动:

 

systemctl start shadowsocks-server

 

 再次测试是否能正常访问

 

7)设置开机启动

 

systemctl enable shadowsocks-server

 

附:

Name说明
server服务器地址,填ip或域名
local_address本地地址
local_port本地端口,一般1080,可任意
server_port服务器对外开的端口
password密码,可以每个服务器端口设置不同密码
port_passwordserver_port + password ,服务器端口加密码的组合
timeout超时重连
method默认: “aes-256-cfb”,见 Encryption
fast_open开启或关闭 TCP_FASTOPEN, 填true / false,需要服务端支持

 

前端启动:ssserver -c /etc/shadowsocks.json

后端启动:ssserver -c /etc/shadowsocks.json -d start

停止:ssserver -c /etc/shadowsocks.json -d stop

重启(修改配置要重启才生效):ssserver -c /etc/shadowsocks.json -d restart



分享
6 条讨论
  • evaluate

    Thank you a lot !!!!

    回复
  • evaluate

    ssserver -c /etc/shadowsocks.json 这部操作会报错=。= Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/shadowsocks/shell.py", line 239, in get_config config = parse_json_in_str(f.read().decode('utf8')) File "/usr/local/lib/python3.6/dist-packages/shadowsocks/shell.py", line 509, in parse_json_in_str return json.loads(data, object_hook=_decode_dict) File "/usr/lib/python3.6/json/__init__.py", line 367, in loads return cls(**kw).decode(s) File "/usr/lib/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.6/json/decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/bin/ssserver", line 11, in <module> load_entry_point('shadowsocks==3.0.0', 'console_scripts', 'ssserver')() File "/usr/local/lib/python3.6/dist-packages/shadowsocks/server.py", line 34, in main config = shell.get_config(False) File "/usr/local/lib/python3.6/dist-packages/shadowsocks/shell.py", line 242, in get_config e.message) AttributeError: 'JSONDecodeError' object has no attribute 'message'

    回复
  • evaluate

    请问解决了吗
    @ #4 Fragments:ssserver -c /etc/shadowsocks.json 这部操作会报错=。= Traceback (most recent call last): File "/usr/local/lib/python3.6/dist-packages/shadowsocks/shell.py", line 239, in get_config config = parse_json_in_str(f.read().decode('utf8')) File "/usr/local/lib/python3.6/dist-packages/shadowsocks/shell.py", line 509, in parse_json_in_str return json.loads(data, object_hook=_decode_dict) File "/usr/lib/python3.6/json/__init__.py", line 367, in loads return cls(**kw).decode(s) File "/usr/lib/python3.6/json/decoder.py", line 339, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/usr/lib/python3.6/json/decoder.py", line 355, in raw_decode obj, end = self.scan_once(s, idx) json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/usr/local/bin/ssserver", line 11, in <module> load_entry_point('shadowsocks==3.0.0', 'console_scripts', 'ssserver')() File "/usr/local/lib/python3.6/dist-packages/shadowsocks/server.py", line 34, in main config = shell.get_config(False) File "/usr/local/lib/python3.6/dist-packages/shadowsocks/shell.py", line 242, in get_config e.message) AttributeError: 'JSONDecodeError' object has no attribute 'message'

    回复
  • evaluate

    木有0.0
    @ #5 1:请问解决了吗

    回复
top