在 Raspberry Pi 上安装shadowsocks

Raspberry Pi 3使用一个 1.2GHz 四核 Broadcom BCM2837 64 bit ARMv8 CPU,自带wifi蓝牙模块,编译运行shadowsock绰绰有余。Raspberry官方使用Raspbian,是debian jessie的变种。使用apt-get安装和管理包也很方便。

使用Debian下shadowsocks-libev一键安装脚本安装shadowsocks。

suppose之前raspberry编译环境已经设好, sudo apt-get install build-essential已经装过。

wget --no-check-certificate https://raw.githubusercontent.com/teddysun/shadowsocks_install/master/shadowsocks-libev-debian.sh
chmod +x shadowsocks-libev-debian.sh

由于这个脚本会检查系统是否为debian/ubuntu,所以第一步系统检测就通不过。解决的办法是把/etc/issue里面的Raspbian改成Debian,对系统没有任何影响,之后也可以改回来。

运行安装脚本./shadowsocks-libev-debian.sh以后,会问你需要使用的端口和密码,自行选定即可。之后脚本就会下载安装依赖的安装包,最新版的shadowsocks-libev进行本地编译。由于Raspberry Pi有四核,很快可以编译完。编译完成后会自动生成配置文件,脚本显示实例如下:

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

Welcome to visit:https://teddysun.com/358.html
Enjoy it!

自己也可以去/etc/shadowsocks-libev/config.json修改配置。

本脚本安装完成后,已将 Shadowsocks-libev 加入开机自启动。

使用命令:
启动:/etc/init.d/shadowsocks start
停止:/etc/init.d/shadowsocks stop
重启:/etc/init.d/shadowsocks restart
查看状态:/etc/init.d/shadowsocks status

但是有个问题,系统重启第一次运行时,ss-server不能解析地址,需要重启服务一次。大概ss启动的时候,网络还没有起来,ss无法获得dns server的地址,于是地址解析失败。

解决的方法有两种,一是在raspi-config里面设定Wait for Network at Boot

二是在/etc/init.d/shadowsock里面给ss-server指定dns server:

do_start() {
if check_running; then
echo "$NAME (pid $PID) is already running..."
return 0
fi
$DAEMON -u -d 192.168.x.x -c $CONF -f $PID_FILE
if check_running; then
echo "Starting $NAME success"
else
echo "Starting $NAME failed"
RET_VAL=1
fi
}
[-d <addr>] Name servers for internal DNS resolver.
Apr 14 02:32:27 raspberrypi /usr/local/bin/ss-server[502]: tcp server listening at 0.0.0.0:1234
Apr 14 02:32:27 raspberrypi /usr/local/bin/ss-server[502]: failed to resolve server name 0.0.0.0
Apr 14 02:32:27 raspberrypi /usr/local/bin/ss-server[502]: failed to listen on any address

add “server”:[“::0”, “0.0.0.0”] in config.json

{
"server":["0.0.0.0","::0"],
"server_port": 10001,
"method": "aes-256-gcm",
"password": "$ss_server_password",
"timeout": 300,
"fast_open": true,
"reuse_port": true,
"mode": "tcp_and_udp",
"user": "nobody"
}

Written by

自由撰稿人,时评人,平等公义追求者

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store