Centos服务器使用ssr代理


0, 使用pip安装shadowsocks

1
2
yum install python-pip -y
pip install https://github.com/shadowsocks/shadowsocks/archive/master.zip -U

1, 配置shadowsocks

创建shadowsocks配置文件,并填入ssr连接参数

1
2
3
4
5
6
7
8
9
10
11
12
vim /etc/shadowsocks.json
{
"server":"8.8.8.8",
"server_port":6553,
"local_address": "127.0.0.1",
"local_port":1080,
"password":"abc-123",
"timeout":300,
"method":"aes-256-cfb",
"fast_open": false,
"workers": 1
}

fast_open:true或false。
开启fast_open以降低延迟,但要求Linux内核在3.7+。
如果需要开启fast_open

1
echo 3 > /proc/sys/net/ipv4/tcp_fastopen

简单测试

1
2
nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1 &
curl --socks5 127.0.0.1:1080 http://httpbin.org/ip

返回以下结果为运行成功

1
2
3
{
"origin": "8.8.8.8"
}

编写systemd管理文件

1
2
3
4
5
6
7
8
9
10
11
cat > /usr/lib/systemd/system/ssr.service << EOF
[Unit]
Description=Shadowsocks

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

[Install]
WantedBy=multi-user.target
EOF

kill掉之前nohup开启的临时测试进程

1
2
3
systemctl daemon-reload
systemctl start ssr
systemctl enable ssr

2, 安装并配置代理程序

1
2
3
4
5
6
yum install -y privoxy.x86_64
echo 'forward-socks5t / 127.0.0.1:1080 .' >> /etc/privoxy/config
echo 'export http_proxy=http://127.0.0.1:8118' >> /etc/profile
echo 'export https_proxy=http://127.0.0.1:8118' >> /etc/profile
source /etc/profile
systemctl restart privoxy

Snipaste_2020-07-03_17-30-04.png