Detailed explanation of the process management tool Supervisor in the Linux environment

Detailed explanation of the process management tool Supervisor in the Linux environment

Author | Adon
source | IT's Jiege trip (ID: Jake_Internet)
reprint please contact an authorized (micro letter ID: Hc220066)
Linux tool of process management
supervisor using the Detailed
Description
using the document: http://supervisord.org/

Supervisor is a c/s service developed by Python and a process management tool under the Linux system.

Can monitor, start, stop, restart one or more processes

When a process is managed by supervisor, when a process is killed accidentally, supervisor will automatically restart it when it detects that the process is dead. It is very convenient to achieve the automatic recovery function of the process, no need to write a script to control it.

Installation
1. Use pip to install

# pip install supervisor

2. Use yum to install

# yum install -y epel-release
# yum install -y supervisor

Use
1. Supervisor installed with pip

# 配置supervisor
# sudo mkdir /etc/supervisor
# echo_supervisord_conf > /etc/supervisor/supervisord.conf

2. The supervisor installed with yum
will generate a supervisor.conf file and a supervisor.d file directory in /etc/


[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=0.0.0.0: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结束的配置文件
file = relative/directory/*.conf   ;也可以写成以.conf结尾的配置文件

For process management configuration parameters, a configuration file should be written for each process and placed in the directory specified by include and included in the supervisord.conf file.
The supervisor.d directory is used to store user-defined process configuration:

# start_es.conf
[program:nginx]
command=/usr/local/nginx/sbin/nginx -g 'daemon off;'
stdout_logfile=/etc/supervisor/logs/run.log
stderr_logfile=/etc/supervisor/logs/error.log
autostart=true
autorestart=true
startsecs=60
stopasgroup=true
ikillasgroup=true
startretries=1
redirect_stderr=true

Note: supervisor cannot monitor background processes, and command cannot be a background run command

supervisor service start


supervisor -c /etc/supervisor.conf

Supervisor commonly used commands


supervisorctl是supervisord的命令行工具
- supervisorctl:查看所有进程的状态
- supervisorctl stop <name>: 停止进程
- supervisorctl start <name>: 启动进程
- supervisorctl restart <name>: 重启进程
- supervisorctl update: 配置文件修改后可以使用该命令加载新的配置
- supervisorctl reload: 重新启动配置中的所有程序

Cluster management
cesii

Installation reference

https://github.com/Gamegos/cesi/blob/master/README.md


配置文件
[node:local]                            ### 设置监控的各个机器
username = user
password = 123
host = 192.168.1.10
port = 9001

;[node:<node_name2>]                    ### 如果有多台机器,就依次添加
;username = <username>
;password = <password>
;host = <hostname>
;port = <port>

;[environment:<environment_name>]
;members = <node_name>, <node_name2>

[cesi]
database = /opt/cesi/userinfo.db    ### 设置db路径
activity_log = /data/logs/cesi/cesi.log   ### 设置log路径
host = 0.0.0.0

最后使用http://ip:5000,登录查看相关信息

Guess you like

Origin blog.51cto.com/15067236/2606360