supervisor installation and configuration guide

supervisor: is a process management tool written in python to start, restart, and close processes.
Note: Supervisor can only manage non-daemon processes, which means Supervisor cannot manage daemon processes. Otherwise, an Exited too quickly (process log may have details) exception is displayed. For example, Tomcat is started as a daemon process by default, so it needs to be changed to catalina.sh run, which runs as a foreground process. The daemon process and non-daemon process will not be explained in detail here, you can Baidu by yourself.
The specific introduction about supervisor can be viewed on the official website: http://supervisord.org/installing.html If the English is not good, you can use Google Chrome to translate the page! This article only operates on supervisor installation and configuration!

Download from the official website: https://pypi.org/project/supervisor/#files //Of course, the official website says that there are three ways to install, this article uses the download tar package to decompress and execute the python script under centos7 to install:

wget https://files.pythonhosted.org/packages/44/60/698e54b4a4a9b956b2d709b4b7b676119c833d811d53ee2500f1b5e96dc3/supervisor-3.3.4.tar.gz

tar -xf supervisor-3.3.4.tar.gz -C /usr/local/ (-C parameter is to decompress to /usr/local/ under this path)

cd /usr/local/supervisor-3.3.4/ (Go to the decompression directory to find the setup.py script to execute)

python setup.py install

Installed...

Execute the command in the terminal: echo_supervisord_conf
can print a "sample" Supervisor configuration file on the stdout of the terminal;
then execute echo_supervisord_conf > /etc/supervisor/supervisord.conf (the path of the configuration file can also be placed elsewhere, not necessarily under etc.) , but if you put it elsewhere, you need to specify the path to the configuration file followed by the parameter "-c" after the service program when starting the service. If you put it under etc, the system will automatically find the configuration. file);
there is a detailed explanation about the configuration file supervisord.conf, as follows:
; The semicolon indicates a comment

[unix_http_server]
file=/usr/local/supervisor-3.3.4/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=/usr/local/supervisor-3.3.4/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=pidfile=/usr/local/supervisor-3.3.4/supervisord.pid ;通过UNIX socket连接supervisord,路径与unix_http_server部分的file一致
;serverurl=http://127.0.0.1:9001 ; 通过HTTP的方式连接supervisord

[program:tomcat]是被管理的进程配置参数,tomcat是进程的名称,原文用xx表示,tomcat是我要监控的对象
[program:tomcat]
command=/usr/local/tomcat/bin/catalina.sh run ; 程序启动命令
autostart=true       ; 在supervisord启动的时候也自动启动
startsecs=10         ; 启动10秒后没有异常退出,就表示进程正常启动了,默认为1秒
autorestart=true     ; 程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启
startretries=3       ; 启动失败自动重试次数,默认是3
user=root          ; 用哪个用户启动进程,默认是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=stdout_logfile=/usr/local/tomcat/logs/catalina.out
stopasgroup=true     ;默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
killasgroup=true     ;默认为false,向进程组发送kill信号,包括子进程

;包含其它配置文件
[include]
files = /etc/supervisor/conf.d/*.conf    ;可以指定一个或多个以.conf结束的配置文件,有的是以*.ini 结尾的,这个是自定义的 不影响;

Why have [include ]? When we want to monitor a lot of program processes, if they are all written in this configuration file like tomcat, it will be very inconvenient and messy to manage! Therefore, it is necessary to [include] to manage the configuration files of other program processes at this time
. Create a conf.d folder under /etc/supervisor/ and then touch tomcat.conf to
edit tomcat.conf:

[program:tomcat]
command=/usr/local/tomcat/bin/catalina.sh run
user=root
autorstart=true
autorestart=true
startsecs=10
startretries=3
redirect_stderr=true
stdout_logfile=/usr/local/tomcat/logs/log.txt
stderr_logfile=/usr/local/tomcat/logs/err.txt
environment=LC_ALL="C.UTF-8",LANG="C.UTF-8"

cd /usr/local/supervisor-3.3.4/supervisor You can find that supervisord.py
is the startup program of supervisord. In the bash environment, you can directly start the execution command: ./supervisord.py can also be started like python supervisord.py. These two Either way without specifying the path to the configuration file (supervisord.conf) there will be a warning message:
supervisor installation and configuration guide
"User Warning: Supervisor is running as root in the default location (including its current working directory) Search its configuration files; you may want to specify a "-c" parameter, specifying the absolute path to the configuration file for increased security.
"Supervisor" is used as the root, it is searching"
so it is best to add when executing supervisord.py On the configuration file path: python supervisord.py -c /etc/supervisor/supervisord.conf or directly execute: supervisord -c /etc/supervisor/supervisord.conf can be

After startup, you can enter the ip address in the browser: 9001. When you log in, there are username and password in the configuration file. The default configuration is username: user password 123;

If you log in and see that the interface below
supervisor installation and configuration guide
tomcat is normal, you just configured it. Later, I configured httpd and zabbix separately, and neither can monitor the query. The reason is that it is the problem of the daemon process and the non-daemon process mentioned at the beginning!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325184328&siteId=291194637