使用ssshell管理SS-libev后端

转自glzjin’s github

 

#!/bin/bash

dbaddress=你的数据库地址
dbname=你的数据库名称
dbusername=你的数据库用户名
dbpassword=你的数据库密码
ip=你的服务器 ifconfig-a对外网卡地址,nat过来的请填就局域网IP
nodeid=节点ID
version=你的前端 version,1= ss-panel v2,2= ss-panel v3 官方版,3= ss-panel v3 魔改版
nic=你的网卡名称 比如 eth0 ,ifconfig -a查看,openvz 的 vps 一般为 venet0  

wget https://copr.fedorainfracloud.org/coprs/librehat/shadowsocks/repo/epel-6/librehat-shadowsocks-epel-6.repo -O /etc/yum.repos.d/librehat-shadowsocks-epel-6.repo
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm --quiet    
yum install shadowsocks-libev -y
yum install libpcap-devel -y
wget https://github.com/glzjin/ssshell-jar/raw/master/libjnetpcap.so -O /usr/lib64/libjnetpcap.so
wget https://github.com/glzjin/ssshell-jar/raw/master/libjnetpcap-pcap100.so -O /usr/lib64/libjnetpcap-pcap100.so
chkconfig shadowsocks-libev off
yum install java-1.8.0-openjdk -y
yum install supervisor python-pip -y
yum install ntp -y
pip install supervisor==3.1
chkconfig supervisord on
wget https://github.com/glzjin/ssshell-jar/raw/master/supervisord.conf -O /etc/supervisord.conf
wget https://github.com/glzjin/ssshell-jar/raw/master/supervisord -O /etc/init.d/supervisord
mkdir /root/ssshell
wget https://github.com/glzjin/ssshell-jar/raw/master/ssshell.jar -O /root/ssshell/ssshell.jar 
wget https://github.com/glzjin/ssshell-jar/raw/master/ssshell.conf -O /root/ssshell/ssshell.conf
sed -i  "s/addresshere/${dbaddress}/" /root/ssshell/ssshell.conf 
sed -i "s/addressnamehere/${dbname}/" /root/ssshell/ssshell.conf 
sed -i "s/addressusernamehere/${dbusername}/" /root/ssshell/ssshell.conf 
sed -i "s/addressuserpassword/${dbpassword}/" /root/ssshell/ssshell.conf 
sed -i "s/iphere/${ip}/" /root/ssshell/ssshell.conf 
sed -i "s/nodeidhere/${nodeid}/" /root/ssshell/ssshell.conf 
sed -i "s/versionhere/${version}/" /root/ssshell/ssshell.conf 
sed -i "s/nichere/${nic}/" /root/ssshell/ssshell.conf 
pip install speedtest-cli



chmod 600 /root/ssshell/ssshell.conf
service supervisord start


wget –no-check-certificate https://pypi.python.org/packages/source/s/supervisor/supervisor-3.0.tar.gz

tar -zxvf supervisor-3.0.tar.gz

cd supervisor-3.0

python setup.py install
创建配置文件:
echo_supervisord_conf > /etc/supervisord.conf
修改配置文件:
在supervisord.conf最后增加:


[program:shadowsocks]
command = java -jar ssshell.jar
directory = /root/ssshell
user=root
autostart=true
autorestart=true
stderr_logfile = /var/log/shadowsocks.log
stdout_logfile = /var/log/shadowsocks.log
startsecs=3

使用指定配置文件启动:/usr/bin/supervisord -c /etc/supervisord.conf
-c 表示配置文件的路径,读取这里个配置文件,之前也是可以根据自己的情况放在不同的文件夹下
修改配置文件之后:supervisorctl reload 重载 服务重新启动
debug查看连接日志:supervisorctl tail -f shadowsocks stderr #Ctrl+C 取消查看
设置supervisord开机启动
编辑文件:vi /etc/rc.local
在末尾另起一行添加supervisord,保存退出(和上文类似)。
另centos7还需要为rc.local添加执行权限
chmod +x /etc/rc.local
至此运用supervisord控制shadowsocks开机自启和后台运行设置完成
常用命令
控制命令基本都通过supervisorctl执行,输入help可以看到命令列表。这是一些常用命令:
获得所有程序状态 supervisorctl status
关闭目标程序 supervisorctl stop shadowsocks
启动目标程序 supervisorctl start shadowsocks
关闭所有程序 supervisorctl shutdown
分享到:

评论已关闭。