supervisor novice installation and configuration issues

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/cocotww/article/details/101112248

supervisor installation and configuration issues

Brief introduction

supervisor is developed with a client Python / server services, it is a process management tool under Linux / Unix systems. You can easily monitor, start, stop, restart one or more processes. Management supervisor with the process, when a process is killed unexpectedly, supervisor to monitor the process of death, it will automatically restart, it is convenient to do the process of automatic recovery functions, eliminating the need to write shell scripts to control himself.

installation

yum installation

yum install epel-release
yum install -y supervisor

The default configuration file is placed in /etc/supervisord.conf which
supervisor is among the yum version 2.x, such as the use of supervisorctl stop command causes the program to get stuck, and the web version does not support the configuration panel, not recommended
if you have yum installed after over, supervisor can use the upgrade version pip

pip install -U supervisor 
echo_supervisord_conf > /etc/supervisord.conf

pip installation

pip install supervisor

After successful installation, you can run

echo_supervisord_conf > /etc/supervisord.conf

Generate configuration files
configuration file description

[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=127.0.0.1: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结束的配置文件
include示例:

[include]
files = /opt/absolute/filename.ini /opt/absolute/*.ini foo.conf config??.ini

Common Commands

supervisorctl status					//当前项目列表
supervisorctl stop program_name			//停止该项目
supervisorctl start program_name		//开启该项目
supervisorctl restart program_name		//重启该项目
supervisorctl reload					//重新载入配置

Web Management Interface

Supervisor Web management interface
for security reasons, the default configuration is not open web management interface, you need to modify the configuration file is opened supervisord.conf visit http rights, the following configuration:

;[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))

change into

[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))

Start-up Supervisor service

Configure the service type of service

#!/bin/bash
#
# supervisord   This scripts turns supervisord on
#
# Author:       Mike McGrath <[email protected]> (based off yumupdatesd)
#
# chkconfig:    - 95 04
#
# description:  supervisor is a process control utility.  It has a web based
#               xmlrpc interface as well as a few other nifty features.
# processname:  supervisord
# config: /etc/supervisor/supervisord.conf
# pidfile: /tmp/supervisord.pid
#
# source function library
. /etc/rc.d/init.d/functions
PIDFILE=/tmp/supervisord.pid
RETVAL=0
start() {
    echo -n $"Starting supervisord: "
    daemon "supervisord --pidfile=$PIDFILE -c /etc/supervisor/supervisord.conf"				###该处修改为配置文件位置
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/supervisord
}
stop() {
    echo -n $"Stopping supervisord: "
    killproc supervisord
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/supervisord
}
restart() {
    stop
    start
}
case "$1" in
  start)
    start
    ;;
  stop) 
    stop
    ;;
  restart|force-reload|reload)
    restart
    ;;
  condrestart)
    [ -f /var/lock/subsys/supervisord ] && restart
    ;;
  status)
    status supervisord
    RETVAL=$?
    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
    exit 1
esac
exit $RETVAL

Save the above script content to the /etc/rc.d/init.d/supervisorfile, modify the file permissions to 755, and set the boot

chmod 755 /etc/rc.d/init.d/supervisor 
chkconfig supervisor on

FAQ summary:

unix:///var/run/supervisor/supervisor.sock refused connection

This error is most

[unix_http_server]
file=/var/run/supervisor/supervisor.sock   ;UNIX socket 文件,supervisorctl 会使用

with

[supervisorctl]
serverurl=unix:///var/run/supervisor/supervisor.sock ;通过UNIX socket连接supervisord,路径与unix_http_server部分的file一致

Causing the two addresses do not correspond
or
do not have permission to run the following file 777

Error: Cannot open an HTTP server: socket.error reported errno.EADDRNOTAVAIL

Because of

[inet_http_server]         ; inet (TCP) server disabled by default
port=0.0.0.0:9001          ; (ip_address:port specifier, *:port for all iface)

Caused by configuration, check out the port has not been accounted for, are not accounted for off conventional solution is to talk about ip is set to 0.0.0.0open to a person who represents or is shut down web configuration items

Guess you like

Origin blog.csdn.net/cocotww/article/details/101112248