centos7 搭建shadowsocks脚本

博主听同事安利,买了一年的搬瓦工vps服务器,CN2线路,看YouTube 4K视频无压力,网速嗖嗖的,一年49美元,总的来说算是很良心了,妈妈再也不用担心我科学上网了!
下面我安利一下shadowsocks的一键部署,(^__^) 嘻嘻……

新建文件install-shadowsocks.sh,内容如下:

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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
# Install Shadowsocks on CentOS 7

echo "Installing Shadowsocks..."

random-string()
{
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w ${1:-32} | head -n 1
}

CONFIG_FILE=/etc/shadowsocks.json
SERVICE_FILE=/etc/systemd/system/shadowsocks.service
SS_PASSWORD=$(random-string 32)
SS_PORT=8388
SS_METHOD=aes-256-cfb
SS_IP=`ip route get 1 | awk '{print $NF;exit}'`
GET_PIP_FILE=/tmp/get-pip.py

# install pip
curl "https://bootstrap.pypa.io/get-pip.py" -o "${GET_PIP_FILE}"
python ${GET_PIP_FILE}

# install shadowsocks
pip install --upgrade pip
pip install shadowsocks

# create shadowsocls config
cat <<EOF | sudo tee ${CONFIG_FILE}
{
"server": "0.0.0.0",
"server_port": ${SS_PORT},
"password": "${SS_PASSWORD}",
"method": "${SS_METHOD}"
}
EOF

# create service
cat <<EOF | sudo tee ${SERVICE_FILE}
[Unit]
Description=Shadowsocks

[Service]
TimeoutStartSec=0
ExecStart=/usr/bin/ssserver -c ${CONFIG_FILE}

[Install]
WantedBy=multi-user.target
EOF

# start service
systemctl enable shadowsocks
systemctl start shadowsocks

# view service status
sleep 5
systemctl status shadowsocks -l

echo "================================"
echo ""
echo "Congratulations! Shadowsocks has been installed on your system."
echo "You shadowsocks connection info:"
echo "--------------------------------"
echo "server: ${SS_IP}"
echo "server_port: ${SS_PORT}"
echo "password: ${SS_PASSWORD}"
echo "method: ${SS_METHOD}"
echo "--------------------------------"

需要修改的配置:

1
2
3
SS_PASSWORD=$(random-string 32) //密码
SS_PORT=8388 //端口号
SS_METHOD=aes-256-cfb //加密方式

执行以下命令一键安装:

1
2
chmod +x install-shadowsocks.sh
./install-shadowsocks.sh

安装完成后会自动打印出 Shadowsocks 的连接配置信息。比如:

1
2
3
4
5
6
7
8
Congratulations! Shadowsocks has been installed on your system.
You shadowsocks connection info:
--------------------------------
server: 10.0.2.15
server_port: 8388
password: RaskAAcW0IQrVcA7n0QLCEphhng7K4Yc
method: aes-256-cfb
--------------------------------

恭喜你已经可以科学的上网了!(^__^) 嘻嘻……