CentOS 7 搭建 Shadowsocks

1. 安装 python

1
yum install python

2. 安装 pip

1
yum install python-pip

如果 python-pip 找不到,则需要先安装 epel 扩展源,然后再安装 python-pip 就可以了

1
2
yum -y install epel-release
yum install python-pip

3. 安装 Shadowsocks

1
pip install shadowsocks

4. 配置 Shadowsocks

创建文件 /etc/shadowsocks.json ,内容如下:

1
2
3
4
5
6
7
8
{
"server":"0.0.0.0",
"server_port":8388,
"local_port":1080,
"password":"12345678",
"timeout":600,
"method":"aes-256-cfb"
}

说明:

  • method为加密方法,可选aes-128-cfb, aes-192-cfb, aes-256-cfb, bf-cfb, cast5-cfb, des-cfb, rc4-md5, chacha20, salsa20, rc4, table
  • server_port 为服务监听端口, 这个需要在 vultr或者服务器管理界面开启
  • port_password 为多用户的时候,配置的 port: pass 的json串

5. 配置自启动

新建启动脚本文件 /etc/systemd/system/shadowsocks.service ,内容如下:

1
2
3
4
5
6
7
8
9
[Unit]
Description=Shadowsocks

[Service]
TimeoutStartSec=0
ExecStart=/usr/bin/ssserver -c /etc/shadowsocks.json

[Install]
WantedBy=multi-user.target

执行以下命令启动 Shadowsocks 服务:

1
2
3
4
5
6
7
8
9
10
11
# 设置开机自启命令
systemctl enable shadowsocks

# 启动命令
systemctl start shadowsocks

# 查看状态命令
systemctl status shadowsocks

# 停止服务
systemctl stop shadowsocks

6. CentOS 开放端口

1
2
3
4
5
6
7
8
# 在指定区域打开端口
firewall-cmd --zone=public --add-port=8388/tcp --permanent

# 重启防火墙
firewall-cmd --reload

# 查看指定区域所有打开的端口
firewall-cmd --zone=public --list-ports

使用脚本自动部署

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
echo "centos7 shadowsocks deploy!"

yum install python

yum -y install epel-release
yum install python-pip

pip install shadowsocks

# 创建文件 /etc/shadowsocks.json
echo '{
"server":"0.0.0.0",
"server_port":8388,
"local_port":1080,
"password":"12345678",
"timeout":600,
"method":"aes-256-cfb"
}' > /etc/shadowsocks.json

# 创建启动脚本文件 /etc/systemd/system/shadowsocks.service
echo '[Unit]
Description=Shadowsocks
[Service]
TimeoutStartSec=0
ExecStart=/usr/bin/ssserver -c /etc/shadowsocks.json
[Install]
WantedBy=multi-user.target' > /etc/systemd/system/shadowsocks.service

# 设置开机自启命令
systemctl enable shadowsocks

# 启动命令
systemctl start shadowsocks

# 查看状态命令
systemctl status shadowsocks

# 在指定区域打开端口
firewall-cmd --zone=public --add-port=8388/tcp --permanent

# 重启防火墙
firewall-cmd --reload

# 查看指定区域所有打开的端口
firewall-cmd --zone=public --list-ports

echo "finish!"

本文参考:
https://www.4spaces.org/install-shadowsocks-on-centos-7/
https://www.4spaces.org/centos-open-porter/