supervisord是运行在python环境下的服务监控程序。所以 在安装supervisord之前必须有python环境

官网:http://supervisord.org/index.html

一: 安装supervisord

  yum install python-setuptools

  easy_install supervisor

  键入: echo_supervisord_conf > /etc/supervisord.conf

  生成一个supervisord的配置文件

  安装就完成了

二: 启动 supervisord

  键入: supervisord 启动服务程序

  键入: supervisordctrl  

    可以进行一系列的命令控制 有(reload,start,stop,restart)

    start: 启动应用程序,可以批处理多个程序

    stop: 停止应用程序,可以批处理多个程序

    restart: 重启应用程序。可以批处理多个程序

三: supervisord 的配置文件

 /etc/supervisord.conf

[sysadmin@kafka_3 ~]$ cat /etc/supervisord.conf |grep -v "^#"|grep -v "^;"

[unix_http_server]
file=/tmp/supervisor.sock   ; the path to the socket file
[supervisord]
logfile=/tmp/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes=50MB        ; max main logfile bytes b4 rotation; default 50MB
logfile_backups=10           ; # of main logfile backups; 0 means none, default 10
loglevel=info                ; log level; default info; others: debug,warn,trace
pidfile=/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon=false               ; start in foreground if true; default false
minfds=1024                  ; min. avail startup file descriptors; default 1024
minprocs=200                 ; min. avail process descriptors;default 200
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket
[include]
files = /etc/supervisor/conf.d/*.conf

 

 使用 supervisord 监控管理的进程必须以 nodaemon 启动 有&符号的还有nohup

 vi /etc/supervisor/conf.d/elasticsearch.conf 

#进程停止信号,可以为TERM, HUP, INT, QUIT, KILL, USR1, or USR2等信号
#默认为TERM 。。当用设定的信号去干掉进程,
[program:elasticsearch]
command= su elkstack /nldata/elasticsearch-5.3.1/bin/elasticsearch  被监控程序指定的运行脚本
directory=/nldata/elasticsearch-5.3.1/bin 被监控程序运行的路径
process_name=%(program_name)s       进程名称
umask=022
priority=100
autostart=true
autorestart=true
startsecs=10      被监控程序启动时持续时间
startretries=3    
stopsignal=TERM
stopwaitsecs=10 stopasgroup=false killasgroup=false user=root redirect_stderr=false stdout_logfile=/nldata/elasticsearch-5.3.1/logs/log.stdout stdout_logfile_maxbytes=100MB stdout_logfile_backups=10 stdout_events_enabled=false stderr_logfile=/nldata/elasticsearch-5.3.1/logs/log.stderr stderr_logfile_maxbytes=100MB stderr_logfile_backups=10 stderr_events_enabled=false

 

 

[program:order-tomcat]
command=/alidata/dxh/tomcat/order-tomcat/bin/catalina.sh  run
directory=/alidata/dxh/tomcat/
process_name=%(program_name)s
umask=022
priority=100
autostart=true
autorestart=true
startsecs=10
startretries=3
stopsignal=INT
stopwaitsecs=10
stopasgroup=false
killasgroup=false
user=root
redirect_stderr=false
stdout_logfile=/var/log/order-tomcat/log.stdout
stdout_logfile_maxbytes=100MB
stdout_logfile_backups=10
stdout_events_enabled=false
stderr_logfile=/var/log/order-tomcat/log.stderr
stderr_logfile_maxbytes=100MB
stderr_logfile_backups=10
stderr_events_enabled=false

 

 四: supervisorctl命令   修改了conf文件需要用到

  reload命令 : 修改了supervisord.conf  要让配置生效 需要reload

  start命令: 启动 supervisorctlstart exx   exx 是supervisord.conf指定的名字[program:exx]

        也可以批处理   supervisorctlstart exx1 xx2 xx3

  stop命令: 批量停止进程

  restart命令:批量重启

  status命令: 查看supervisord监控了什么程序时用这个!

       update:配置更新用

 

五:开机启动文件:

#!/bin/bash
#
# Startup script for the Supervisor server
#
# Tested with CentOS release 6.8
#
# chkconfig: 2345 85 15
# description: Supervisor is a client/server system that allows its users to \
#              monitor and control a number of processes on UNIX-like \
#              operating systems.
#
# processname: supervisord
# pidfile: /var/run/supervisord.pid

# Source function library.
. /etc/rc.d/init.d/functions

RETVAL=0
prog="supervisord"
SUPERVISORD=/opt/py27/bin/supervisord
PID_FILE=/var/run/supervisord.pid
CONFIG_FILE=/etc/supervisord.conf

start()
{
        echo -n $"Starting $prog: "
        $SUPERVISORD -c $CONFIG_FILE --pidfile $PID_FILE && success || failure
        RETVAL=$?
        echo
        return $RETVAL
}

stop()
{
        echo -n $"Stopping $prog: "
        killproc -p $PID_FILE -d 10 $SUPERVISORD
        RETVAL=$?
        echo
}

reload()
{
        echo -n $"Reloading $prog: "
        if [ -n "`pidfileofproc $SUPERVISORD`" ] ; then
            killproc $SUPERVISORD -HUP
        else
            # Fails if the pid file does not exist BEFORE the reload
            failure $"Reloading $prog"
        fi
        sleep 1
        if [ ! -e $PID_FILE ] ; then
            # Fails if the pid file does not exist AFTER the reload
            failure $"Reloading $prog"
        fi
        RETVAL=$?
        echo
}

case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                start
                ;;
        reload)
                reload
                ;;
        status)
                status -p $PID_FILE $SUPERVISORD
                RETVAL=$?
                ;;
        *)
                echo $"Usage: $0 {start|stop|restart|reload|status}"
                RETVAL=1
esac
exit $RETVAL