1. 安装
#python2版本
pip2 install supervisor
#python3 supervisor4版本
pip3 install git+https://github.com/Supervisor/supervisor@master
2. 配置
mkdir /etc/supervisor
echo_supervisord_conf > /etc/supervisor/supervisord.conf
3. 配置模板说明
[unix_http_server]
file=/tmp/supervisor.sock ;UNIX socket 文件,supervisorctl 会使用
;chmod=0700 ;socket文件的mode,默认是0700
;chown=nobody:nogroup ;socket文件的owner,格式:uid:gid
;[inet_http_server] ;HTTP服务器,提供web管理界面
;port=127.0.0.1:9001 ;Web管理后台运行的IP和端口,如果开放到公网,需要注意安全性
;username=user ;登录管理后台的用户名
;password=123 ;登录管理后台的密码
[supervisord]
logfile=/tmp/supervisord.log ;日志文件,默认是 $CWD/supervisord.log
logfile_maxbytes=50MB ;日志文件大小,超出会rotate,默认 50MB,如果设成0,表示不限制大小
logfile_backups=10 ;日志文件保留备份数量默认10,设为0表示不备份
loglevel=info ;日志级别,默认info,其它: debug,warn,trace
pidfile=/tmp/supervisord.pid ;pid 文件
nodaemon=false ;是否在前台启动,默认是false,即以 daemon 的方式启动
minfds=1024 ;可以打开的文件描述符的最小值,默认 1024
minprocs=200 ;可以打开的进程数的最小值,默认 200
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ;通过UNIX socket连接supervisord,路径与unix_http_server部分的file一致
;serverurl=http://127.0.0.1:9001 ; 通过HTTP的方式连接supervisord
; [program:xx]是被管理的进程配置参数,xx是进程的名称
[program:xx]
command=/opt/apache-tomcat-8.0.35/bin/catalina.sh run ; 程序启动命令
autostart=true ; 在supervisord启动的时候也自动启动
startsecs=10 ; 启动10秒后没有异常退出,就表示进程正常启动了,默认为1秒
autorestart=true ; 程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启
startretries=3 ; 启动失败自动重试次数,默认是3
user=tomcat ; 用哪个用户启动进程,默认是root
priority=999 ; 进程启动优先级,默认999,值小的优先启动
redirect_stderr=true ; 把stderr重定向到stdout,默认false
stdout_logfile_maxbytes=20MB ; stdout 日志文件大小,默认50MB
stdout_logfile_backups = 20 ; stdout 日志文件备份数,默认是10
; stdout 日志文件,需要注意当指定目录不存在时无法正常启动,所以需要手动创建目录(supervisord 会自动创建日志文件)
stdout_logfile=/opt/apache-tomcat-8.0.35/logs/catalina.out
stopasgroup=false ;默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
killasgroup=false ;默认为false,向进程组发送kill信号,包括子进程
;包含其它配置文件
[include]
files = relative/directory/*.ini ;可以指定一个或多个以.ini结束的配置文件
4. 服务方式启动
vi /usr/lib/systemd/system/supervisor.service
# supervisord service for systemd (CentOS 7.0+)
# by ET-CS (https://github.com/ET-CS)
[Unit]
Description=Supervisor daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/bin/supervisord -c /etc/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable supervisor.service
编译安装配置实例
vi /etc/supervisord.conf
[unix_http_server]
file=/tmp/supervisor.sock
[inet_http_server]
port=0.0.0.0:9001
username=admin
password=xxxxxxxx
[supervisord]
logfile=/var/log/supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=info
pidfile=/tmp/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock
[program:bc]
command=/usr/local/bin/uwsgi /var/www/bearychat-outgoing/test-uwsgi.ini
redirect_stderr=true
stdout_logfile=/var/log/uwsgi-bc.log
autostart=true
autorestart=true
startsecs=10
;startretries=3
priority=1
stopasgroup=true
killasgroup=true
[program:devops]
command=/usr/local/bin/uwsgi /var/www/myDjango/devops/devops-uwsgi.ini
redirect_stderr=true
stdout_logfile=/var/log/uwsgi-devops.log
autostart=true
autorestart=true
startsecs=10
startretries=3
priority=2
stopasgroup=true
killasgroup=true
[program:sss]
command=/usr/local/bin/python3.6 /usr/local/bin/ssserver -c /etc/shadowsocks-libev/ssserver.json
redirect_stderr=true
stdout_logfile=/var/log/sss.log
autostart=true
autorestart=true
startsecs=10
startretries=3
priority=3
stopasgroup=true
killasgroup=true
;[include]
;files = relative/directory/*.ini
yum安装配置实例
[unix_http_server]
file=/var/run/supervisor/supervisor.sock
[inet_http_server]
port=127.0.0.1:9001
username=admin
password=xxxxxxxx
[supervisord]
logfile=/var/log/supervisor/supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=info
pidfile=/var/run/supervisord.pid
nodaemon=false
minfds=1024
minprocs=200
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///var/run/supervisor/supervisor.sock ; use a unix:// URL for a unix socket
[program:bc]
command=/usr/local/bin/uwsgi /var/www/bearychat-outgoing/test-uwsgi.ini
redirect_stderr=true
stdout_logfile=/var/log/uwsgi-bc.log
autostart=true
autorestart=true
startsecs=10
;startretries=3
priority=1
stopasgroup=true
killasgroup=true
[program:devops]
command=/usr/local/bin/uwsgi /var/www/myDjango/devops/devops-uwsgi.ini
redirect_stderr=true
stdout_logfile=/var/log/uwsgi-devops.log
autostart=true
autorestart=true
startsecs=10
startretries=3
priority=2
stopasgroup=true
killasgroup=true
[program:sss]
command=/usr/local/bin/python3.6 /usr/local/bin/ssserver -c /etc/shadowsocks-libev/ssserver.json
redirect_stderr=true
stdout_logfile=/var/log/sss.log
autostart=true
autorestart=true
startsecs=10
startretries=3
priority=3
stopasgroup=true
killasgroup=true
[include]
files = supervisord.d/*.ini