—————— 安装必备程序 ——————
yum install epel-release -y
yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto c-ares-devel libev-devel libsodium-devel mbedtls-devel -y
yum install git build-essential openssl-devel gcc -y
yum install udns-devel
—————— 下载源码并编译安装 ——————
#git clone https://github.com/madeye/shadowsocks-libev.git
git clone https://github.com/shadowsocks/shadowsocks-libev.git
cd shadowsocks-libev
./configure
#make && make install
git submodule init && git submodule update
./autogen.sh && ./configure && make
make install
cd ..
rm -rf shadowsocks-libev
编译时候默认是编译帮助文档的,由于依赖包体积过大可以选择不编译手册(documentation)
./autogen.sh
./configure --disable-documentation
# 四线程编译并安装
make -j4 install
—————— 启动 ——————
nohup /usr/local/bin/ss-server -s IP地址 -p 端口 -k 密码 -m 加密方式 &
—————— 后台启动 ——————
nohup /usr/local/bin/ss-server -s 11.22.33.44 -p 12345 -k 12345678 -m aes-256-cfb -u &
—————— 如何在使用nohup的时候不让它生成nohup.out ——————
刚才又试了一下,这样也可以:
nohup yourprog >/dev/null 2>/dev/null &
或者
nohup yourprog &>/dev/null
—————— 综合后台启动 ——————
nohup /usr/local/bin/ss-server -s 11.22.33.44 -p 12345 -k 12345678 -m aes-256-cfb -u > /dev/null 2>&1 &
—————— 杀死进程 ——————
ps -ef | grep "ss-server" 会看到“/usr/local/bin/ss-server .......”的进
kill掉即可,比如: kill 29899
or
killall ss-server
—————— 开机启动 ——————
echo "nohup /usr/local/bin/ss-server -s 11.22.33.44 -p 12345 -k 12345678 -m aes-256-cfb -u > /dev/null 2>&1 &" >> /etc/rc.local
—————— 保护进程 ——————
如果 ShadowSocks 经常掉线就在 /root/shadowsocks-libuv/ 下新建一个 check.sh 文件,加入以下脚本
#!/bin/bash
if
ps -ef|grep "ss-server" | grep -v "grep"
then
echo "Running!"
else
echo "Stopped!"
nohup /usr/local/bin/ss-server -s 11.22.33.44 -p 12345 -k 12345678 -m aes-256-cfb -u > /dev/null 2>&1 &
fi
chmod +x /root/shadowsocks-libuv/check.sh
crontab -e
*/5 * * * * /root/shadowsocks-libuv/check.sh
即每 5 分钟执行一次监控脚本,如果 ShadowSocks 的服务不在运行就自动启动。
参考:
1.Centos搭建Shadowsocks的教程
https://bbs.zephyrxt.com/thread-16637-1-1.html
https://bbs.zephyrxt.com/thread-17350-1-1.html
3.shadowsocks-libev管理脚本的使用(Linux系统)
https://bbs.zephyrxt.com/thread-17353-1-1.html
4.用 Supervisor 运行 Shadowsocks
https://bbs.zephyrxt.com/thread-17351-1-1.html
5.linux命令之nohup
https://bbs.zephyrxt.com/thread-17352-1-1.html
6.不编译shadowsocks的文档
https://bbs.zephyrxt.com/thread-18558-1-1.html
7.【已解决】连接不上服务器,Error: connect ETIMEDOUT
https://bbs.zephyrxt.com/thread-18597-1-1.html
https://bbs.zephyrxt.com/thread-18598-1-1.html