Supervisor安装与配置

Supervisor是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统。它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor管理的进程,当一个进程意外被杀死,supervisort监听到进程死后,会自动将它重新拉起,很方便的做到进程自动恢复的功能,不再需要自己写shell脚本来控制

网上随便划拉一篇文章都有很多配置详解,在这里不过多叙述,简单的写一下使用流程。
安装命令 很简单 centos-- yum install supervisor
                            ubuntu -- apt-get install supervisor
                          pip3 install supervisor 
总有一个命令适合你。
使用 echo_supervisord_conf > /etc/supervisor/supervisord.conf 这个命令生成配置文件的需要修改一下里面的配置,不然运行会报错的,虽然解决这个报错很easy 但是也很烦

下面贴一下 我的配置 (使用 echo_supervisord_conf > /etc/supervisor/supervisord.conf 这个命令生成配置文件):

supervisord.conf 

;redirect_stderr=false         ; redirect_stderr=true is not allowed for eventlisteners
;stdout_logfile=/a/path        ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10     ; # of stdout logfile backups (0 means none, default 10)
;stdout_events_enabled=false   ; emit events on stdout writes (default false)
;stdout_syslog=false           ; send stdout to syslog with process name (default false)
;stderr_logfile=/a/path        ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10     ; # of stderr logfile backups (0 means none, default 10)
;stderr_events_enabled=false   ; emit events on stderr writes (default false)
;stderr_syslog=false           ; send stderr to syslog with process name (default false)
;environment=A="1",B="2"       ; process environment additions
;serverurl=AUTO                ; override serverurl computation (childutils)

; The sample group section below shows all possible group values.  Create one
; or more 'real' group: sections to create "heterogeneous" process groups.

;[group:thegroupname]
;programs=progname1,progname2  ; each refers to 'x' in [program:x] definitions
;priority=999                  ; the relative start priority (default 999)

; 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 = /etc/supervisor/conf.d/*.conf 

  在 /etc/supervisor/下新建一个conf.d文件夹,随便配置一个conf 文件就好,一般一个项目一个最好。当然也可以使用ini结尾的文件 只需要把files = /etc/supervisor/conf.d/*.conf 改为files =/etc/supervisor/conf.d/*.ini就可以了

贴上一个conf.d 里面的配置仅供参考
[program:uwsgi]
command = uwsgi --ini /app/uwsgi/uwsgi.ini
directory = /app/predict
startsecs = 1         
stopwaitsecs = 0		
autostart = true 
startretries = 3
priority=1 
autorestart = true
redirect_stderr = true     
stdout_logfile_maxbytes = 50MB  
stdout_logfile_backups = 20   
stdout_logfile = /app/predict/log/supervisord.log
stderr_logfile = /app/predict/log/supervisord.err
stopasgroup=true
killasgroup=true
pidfile=/app/predict/log/supervisord.pid

  
当然还有其他配置方法,不一定用echo_supervisord_conf > /etc/supervisor/supervisord.conf 这个命令生成配置文件,也可以自定义,下面附一个自定义的配置文件:

[program:uwsgi]
command = uwsgi --ini /app/uwsgi/uwsgi.ini
directory = /app/predict
startsecs = 1         
stopwaitsecs = 0		
autostart = true 
startretries = 3
priority=1 
autorestart = true
redirect_stderr = true     
stdout_logfile_maxbytes = 50MB  
stdout_logfile_backups = 20   
stdout_logfile = /app/predict/log/supervisord.log
stderr_logfile = /app/predict/log/supervisord.err
stopasgroup=true
killasgroup=true
pidfile=/app/predict/log/supervisord.pid

[supervisord]
loglevel = info

[inet_http_server]         
port=:9001       
username=admin          
password=123        


[supervisorctl]
serverurl=http://127.0.0.1:9001 
username=admin             
password=123                

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface


[include]
files = /etc/supervisor/conf.d/*.ini

  新建一个conf.d 文件夹,创建ini配置文件

[program:nginx]
command = nginx
directory = /app/predict/
startsecs = 1         
stopwaitsecs = 0		
autostart = true       
autorestart = true     
stdout_logfile_maxbytes = 50MB  
stdout_logfile_backups = 20   
stdout_logfile = /app/predict/log/nginx_supervisord.log
stderr_logfile = /app/predict/log/nginx_supervisord.err
stopasgroup=true
killasgroup=true
pidfile=/app/predict/log/supervisord.pid

[supervisord]
loglevel = info

 

这样配置文件就搞完了。

无论你用什么方法最后启动的命令都是指向你的配置文件

使用命令--启动

supervisord -c /etc/supervisor/supervisord.conf #这个相当于服务端

开启客户端

supervisorctl -c /etc/supervisor/supervisord.conf  #客户端

posted @ 2020-05-13 19:47  青春叛逆者  阅读(101)  评论(0编辑  收藏  举报