Supervisor
supervisor是进程管理工具
安装
supervisor对python3支持不好,须使用python2
sudo pip install supervisor
配置
运行echo_supervisord_conf命令输出默认的配置项,可以如下操作将默认配置保存到文件中
echo_supervisord_conf > supervisord.conf
vim 打开编辑supervisord.conf文件,修改
[include]
files = relative/directory/*.ini
为
[include]
files = /etc/supervisor/*.conf
include选项指明包含的其他配置文件。
将编辑后的supervisord.conf文件复制到/etc/目录下
sudo cp supervisord.conf /etc/
然后我们在/etc目录下新建子目录supervisor(与配置文件里的选项相同),并在/etc/supervisor/中新建tuotiao管理的配置文件toutiao.conf。
[inet_http_server] ; inet (TCP) server disabled by default
port=0.0.0.0:9001 ; ip_address:port specifier, *:port for all iface
username=chen ; default is no username (open server)
password=123 ; default is no password (open server)
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=chris ; should be same as in [*_http_server] if set
;password=123 ; should be same as in [*_http_server] if set
;prompt=mysupervisor ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history ; use readline history if available
[group:toutiao]
programs=toutiao-app
[program:toutiao-app]
command=/home/python/scripts/toutiao_app.sh
directory=/home/python/toutiao-backend
user=python
autorestart=true
redirect_stderr=false
loglevel=info
stopsignal=KILL
stopasgroup=true
killasgroup=true
[program:im]
command=/home/python/scripts/im.sh
directory=/home/python/toutiao-backend
user=python
autorestart=true
redirect_stderr=false
loglevel=info
stopsignal=KILL
stopasgroup=true
killasgroup=true
[program:caipiao]
command= nohup python3 app.py > python.log 2>&1 & ; 被监控的进程启动命令
directory=/root/caipiao/ ; 执行前要不要先cd到目录去,一般不用
priority=1 ;数字越高,优先级越高
numprocs=1 ; 启动几个进程
autostart=true ; 随着supervisord的启动而启动
autorestart=true ; 自动重启。。当然要选上了
startretries=10 ; 启动失败时的最多重试次数
exitcodes=0 ; 正常退出代码(是说退出代码是这个时就不再重启了吗?待确定)
stopsignal=KILL ; 用来杀死进程的信号
stopwaitsecs=10 ; 发送SIGKILL前的等待时间
redirect_stderr=true ; 重定向stderr到stdout
[program:ss]
command= nohup ssserver -c /etc/shadowsocks.json & ; 被监控的进程启动命令
directory=/root/ ; 执行前要不要先cd到目录去,一般不用
priority=1 ;数字越高,优先级越高
numprocs=1 ; 启动几个进程
autostart=true ; 随着supervisord的启动而启动
autorestart=true ; 自动重启。。当然要选上了
startretries=10 ; 启动失败时的最多重试次数
exitcodes=0 ; 正常退出代码(是说退出代码是这个时就不再重启了吗?待确定)
stopsignal=KILL ; 用来杀死进程的信号
stopwaitsecs=10 ; 发送SIGKILL前的等待时间
redirect_stderr=true ; 重定向stderr到stdout
stopasgroup=true ;stop program之时一并stop其子进程
killasgroup=true ;在停止program子进程的时候,发送kill信号
启动
supervisord -c /etc/supervisord.conf
查看 supervisord 是否在运行:
ps aux | grep supervisord
supervisorctl
我们可以利用supervisorctl来管理supervisor。
supervisorctl
> status # 查看程序状态
> start apscheduler # 启动 apscheduler 单一程序
> stop toutiao:* # 关闭 toutiao组 程序
> start toutiao:* # 启动 toutiao组 程序
> restart toutiao:* # 重启 toutiao组 程序
> update # 重启配置文件修改过的程序
执行status命令时,显示如下信息说明程序运行正常:
supervisor> status
toutiao:toutiao-app RUNNING pid 32091, uptime 00:00:02
shadowsocks
配置
1. yum install python-setuptools && easy_install pip
2. pip install shadowsocks
3. vi /etc/shadowsocks.json
{
"server": "0.0.0.0",
"port_password":{
"端口号":"密码"
},
"method": "aes-256-cfb",
"timeout": 300,
"mode": "tcp_and_udp",
"workers":2
}
启动
ssserver -c /etc/shadowsocks.json
ssserver -c /etc/shadowsocks.json -d start # 后台运行
ssserver -c /etc/shadowsocks.json -d stop #停止