supervisor 部署
1.下载epel源,安装supervisor
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.rep yum install supervisor -y
2.生成supervisor的初始化配置文件
echo_supervisord_conf > /etc/supervisor/supervisord.conf [root@localhost supervisor]# grep -Ev "^;|^$" /etc/supervisor/supervisord.conf [unix_http_server] file=/etc/supervisor/supervisor.sock ; (the path to the socket file) # 开启web访问 [inet_http_server] ; inet (TCP) server disabled by default port = 192.168.1.21:9001 ; (ip_address:port specifier, *:port for all iface) username = user ; (default is no username (open server)) password = 123 ; (default is no password (open server)) # supervisord日志相关配置 [supervisord] logfile=/etc/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log) logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB) logfile_backups=10 ; (num of main logfile rotation backups;default 10) loglevel=info ; (log level;default info; others: debug,warn,trace) pidfile=/etc/supervisor/supervisord.pid ; (supervisord pidfile;default supervisord.pid) nodaemon=false ; (start in foreground if true;default false) minfds=1024 ; (min. avail startup file descriptors;default 1024) minprocs=200 ; (min. avail process descriptors;default 200) [rpcinterface:supervisor] supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface [supervisorctl] serverurl=unix:///etc/supervisor/supervisor.sock ; use a unix:// URL for a unix socket
3.单独配置进程守护
vim /etc/supervisor/uwsgi.ini [program:uwsgi] command = /usr/local/python3/bin/uwsgi --ini /data/wwwroot/pyweb/uwsgi.ini ;process_name=%(program_name)s ; process_name expr (default %(program_name)s) ;numprocs=1 ; number of processes copies to start (def 1) ;directory=/tmp ; directory to cwd to before exec (def no cwd) ;umask=022 ; umask for process (default None) # 启动优先级,数值小的优先级高 ;priority=999 ; supervisord启动时启动,异常退出自动重启 autostart = true autorestart = true ; 5s没有异常退出,启动失败重试3次 startsecs = 5 startretries = 3 ;exitcodes=0,2 ; 'expected' exit codes for process (default 0,2) ;stopsignal=QUIT ; signal used to kill process (default TERM) ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) ;user=chrism ; setuid to this UNIX account to run the program ; stderr日志重定向到stdout,日志文件,最大值,备份数 redirect_stderr = true stdout_logfile = /etc/supervisor/logs/uwsgi.log stdout_logfile_maxbytes = 50MB stdout_logfile_backups = 15 ;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) ;stdout_events_enabled=false ; emit events on stdout writes (default false) ;redirect_stderr为false时生效,日志文件,最大值,备份数 ;stderr_logfile = /etc/supervisor.d/uwsgi_err.log ;stderr_logfile_maxbytes = 50MB ;stderr_logfile_backups = 15 ;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) ;stderr_events_enabled=false ; emit events on stderr writes (default false) ;environment=A=1,B=2 ; process environment additions (def no adds) ;serverurl=AUTO ; override serverurl computation (childutils)
4.启动,停止,重启
supervisorctl stop uwsgi # 停止XXX进程 supervisorctl start uwsgi # 启动XXX进程 supervisorctl restart uwsgi # 重启XXX进程 supervisorctl update all # 更新所有进程 supervisorctl start all # 启动所有进程 supervisorctl restart all # 重启所有进程 supervisorctl reload # 修改完配置文件后重新启动supervisor supervisorctl status # 查看supervisor监管的进程状态 # 启动服务端 supervisord -c /etc/supervisor/supervisord.conf
5.开机自启动
vim /lib/systemd/system/supervisord.service # supervisord service for systemd (CentOS 7.0+) [Unit] Description=Supervisor daemon [Service] Type=forking ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown ExecReload=/usr/bin/supervisorctl $OPTIONS reload KillMode=process Restart=on-failure RestartSec=60s [Install] WantedBy=multi-user.target
systemctl start nginx.service #启动nginx服务 systemctl enable nginx.service #设置开机自启动 systemctl disable nginx.service #停止开机自启动 systemctl status nginx.service #查看服务当前状态 systemctl restart nginx.service #重新启动服务 systemctl list-units --type=service #查看所有已启动的服务

浙公网安备 33010602011771号