Centos服务器使用ssr代理

1. 使用pip安装shadowsocks

yum install python-pip -y
pip install shadowsocks

2. 配置shadowsocks

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

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
echo 3 > /proc/sys/net/ipv4/tcp_fastopen

简单测试

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

返回以下结果为运行成功

{
  "origin": "8.8.8.8"
}

编写systemd管理文件

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开启的临时测试进程

systemctl daemon-reload
systemctl start ssr
systemctl enable ssr

3. 安装并配置代理程序

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