這篇整理的是在 CentOS 上安裝 libev 版 shadowsocks 的過程。libev 版本最大的優點是極省資源——記憶體占用大約 600k 上下,CPU 消耗也很低,甚至塞得進刷了 OpenWRT 的路由器裡。
支援 CentOS 32 位與 64 位,記憶體 128M 以上即可。
預設的連線參數是這樣的:伺服器埠自行指定(不填則為 8989)、本地端埠 1080、密碼自行設定(不填則為預設值)。
用 root 登入後執行:
wget --no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-libev.sh chmod +x shadowsocks-libev.sh ./shadowsocks-libev.sh 2>&1 | tee shadowsocks-libev.log
安裝完成時,腳本會把連線資訊印出來:
Congratulations, shadowsocks-libev install completed! Your Server IP: your_server_ip Your Server Port: your_server_port Your Password: your_password Your Local IP: 127.0.0.1 Your Local Port: 1080 Your Encryption Method: aes-256-cfb
腳本安裝完會自動起進程,也已經寫入開機自啟動。要確認進程是否存在:
ps -ef | grep ss-server | grep -v ps | grep -v grep
日常操作靠 init 腳本:
/etc/init.d/shadowsocks start /etc/init.d/shadowsocks stop /etc/init.d/shadowsocks restart /etc/init.d/shadowsocks status
卸載很乾脆:
./shadowsocks-libev.sh uninstall
如果是從舊版本升級,流程是「先卸載、再跑一次新腳本」,這樣才能確保裝到最新版。
修改 /etc/shadowsocks-libev/config.json,讓 server 同時監聽兩種位址:
{
"server": ["[::0]", "0.0.0.0"],
"server_port": your_server_port,
"local_address": "127.0.0.1",
"local_port": 1080,
"password": "your_password",
"timeout": 600,
"method": "aes-256-cfb"
}
要注意的是,libev 版不能靠改設定檔開多埠,只能開多進程。真的需要多埠,請改用 Python 版或 Go 版。
不想依賴第三方腳本,也可以自己包一支。以 CentOS 7 為例,重點是先用 pip 裝 shadowsocks,再註冊成 systemd 服務:
#!/bin/bash
CONFIG_FILE=/etc/shadowsocks.json
SERVICE_FILE=/etc/systemd/system/shadowsocks.service
SS_PASSWORD=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
SS_PORT=8388
SS_METHOD=aes-256-cfb
SS_IP=$(ip route get 1 | awk '{print $NF;exit}')
curl "https://bootstrap.pypa.io/get-pip.py" -o /tmp/get-pip.py
python /tmp/get-pip.py
pip install --upgrade pip
pip install shadowsocks
cat <
跑完把印出來的 server、port、password、method 四項抄下來,用戶端就能直接連了。
用戶端
圖形介面的用戶端可以從 SourceForge 的 shadowsocksgui 專案頁面下載。若安裝過程遇到問題,建議先翻過官方的 Shadowsocks Troubleshooting 再提問,多數狀況在那裡就有答案。