centos7安装supervisor

1、yum安装supervisor

yum install -y supervisor
image.png

或者


image.png

2、安装成功后加入开机自启

systemctl enable supervisord
image.png

3、systemctl start supervisord # 启动supervisord服务

systemctl start supervisord

4、 systemctl status supervisord # 查看supervisord服务状态

systemctl status supervisord
image.png

或者 ps -ef|grep supervisord # 查看是否存在supervisord进程


image.png

5、修改/etc/supervisor.conf配置文件

出于安全考虑,默认配置是没有开启web管理界面,需要修改supervisord.conf配置文件打开http访权限,将下面的配置:

;[inet_http_server]         
; inet (TCP) server disabled by default;port=127.0.0.1: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))

修改成:

[inet_http_server]         ; inet (TCP) server disabled by default
port=0.0.0.0: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))

这样就可以通过 http://ip:9001访问到supervisor的页面功能

项目配置进程

1、在 /etc/supervisor.conf配置文件的最后一行

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

[include]
files = supervisord.d/*.ini

可以看到include下面就是存放项目进行的文件,都在 /etc/supervisord.d文件夹中,以.ini结尾的文件

2、在/etc/supervisord.d创建文件,如testJob.ini,编辑如下

[program:testJob]
command= /www/server/php/56/bin/php think queue:work --queue testJob --daemon
directory=/www/wwwroot/lfl.laiima.com/niushop_b2b2c
process_name=%(process_num)02d
;numprocs=5 ;启动几个进程
autostart=true ;随着supervisord的启动而启动
autorestart=true ;自动启动
startsecs=1 ;程序重启时候停留在runing状态的秒数
startretries=5 ;启动失败时的最多重试次数
redirect_stderr=true ;重定向stderr到stdout
;stdout_logfile=/etc/supervisor.d/supervisor.log ;stdout文件

testJob:队列名称
/www/server/php/56/bin/php:项目中的php文件
directory:项目目录

保存退出,systemctl restart supervisord重启服务,
这时在web页面时能看到有testJob


image.png

运行ystemctl status supervisord查看状态同样能看到


image.png

常用命令:

systemctl stop supervisord    停止服务
systemctl start supervisord   开启服务
systemctl status supervisord  查看状态
systemctl reload supervisord  重载配置
systemctl restart supervisord 重启
ps -ef|grep supervisord 查看是否启动成功
netstat -tunlp|grep 端口号   查看端口号
systemctl enable supervisord 设置开机自启
supervisorctl reload //重载
supervisorctl status:查看所有进程的状态
supervisorctl stop demo:停止demo
supervisorctl start demo:启动demo
supervisorctl restart demo: 重启demo
supervisorctl update :配置文件修改后可以使用该命令加载新的配置

项目进程ini文件的一些可配置选项

[program:nginx]                                    ; 程序名.
command=/usr/sbin/nginx -g 'daemon off;'           ; 启动程序所使用的命令.
process_name=%(program_name)s_%(process_num)02d    ; 程序进程名.
numprocs=1                                         ; 进程数量.
directory=/usr                                     ; 工作目录.
umask=022                                          ; 进程生成文件权限掩码.
priority=999                                       ; 程序启动优先级.

autostart=true                                     ; 当"Supervisord"启动时自动启动该程序.
startsecs=1                                        ; 完成启动等待时间.
startretries=3                                     ; 启动程序重试次数.
autorestart=true                                   ; 当程序因故障退出时自动重启程序.

exitcodes=0                                        ; 程序退出状态码.
stopsignal=TERM                                    ; 程序停止信号. 
stopwaitsecs=10                                    ; 程序停止等待时间,超时则强制退出程序.
stopasgroup=true                                   ; 停止程序进程组.
killasgroup=true                                   ; 强制停止程序进程组.

user=root                                          ; 程序运行用户.
 
redirect_stderr=true                               ; 将"stderr"重定向到"stdout".
stdout_logfile=/usr/local/supervisor/logs/nginxlog/nginx_stdout.log ; "stdout"输出到日志文件中.
stdout_logfile_maxbytes=50MB                       ; stdout日志文件最大大小.
stdout_logfile_backups=10                          ; stdout日志文件保留数量.
;stdout_capture_maxbytes=0                         ; 关闭stdout日志事件捕获功能.
;stdout_events_enabled=false                       ; 关闭stdout日志事件功能.
;stdout_syslog=false                               ; 禁用将stdout输出到syslog.

;stderr_logfile=/usr/local/supervisor/logs/nginxlog/nginx_stderr.log  ; "stderr"输出到日志文件中.
;stderr_logfile_maxbytes=50MB                      ; stderr日志文件最大大小.
;stderr_logfile_backups=10                         ; stderr日志文件保留数量.
;stderr_capture_maxbytes=0                         ; 关闭stderr日志事件捕获功能.
;stderr_events_enabled=false                       ; 关闭stderr日志事件功能.
;stderr_syslog=false                               ; 禁用将stderr输出到syslog.

;environment=A="1",B="2"                           ; 程序内部使用的环境变量.
;serverurl=AUTO                                    ; HTTP Server连接地址.

你可能感兴趣的:(centos7安装supervisor)