Supervisord进程管家

Supervisord是一个守护进程的工具,当进程意外终止或服务器掉电起来后,希望进程能够自动运行,supervisord可以很好的为我们做这件事情。同时supervisord也自带监控界面,可以通过浏览器灵活的查看、操作。

以安徽storm快数据系统为例,20台服务器总计268个进程(不包括CDH hadoop集群进程),全部由supervisord接管。

1)  首先安装meld3和supervisor:

下载地址

https://pypi.python.org/pypi/meld3

https://pypi.python.org/pypi/supervisor

tar xfz meld3-1.0.2.tar.gz

cd meld3-1.0.2

python setup.py install

python setup.py install安装报错

[root@localhost meld3-1.0.2]# python setup.py install

Traceback (most recent call last):

File "setup.py", line 1, in ?

from setuptools import setup

ImportError: No module named setuptools

解决办法

http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
tar zxvf setuptools-0.6c11.tar.gz
cd setuptools-0.6c11
python setup.py build
python setup.py install

tar xfz supervisor-3.2.3.tar.gz

cd supervisor-3.2.3

python setup.py install

2)生成配置文件:

echo_supervisord_conf > /etc/supervisord.conf

3)修改配置文件,并在末尾添加app守护:

vi /etc/supervisord.conf

末尾添加app信息:

[program:storm_nimbus]

user=inas

autorestart=true

directory=/home/inas/storm/bin

command=/home/inas/storm/bin/storm nimbus

[program:storm_ui]

user=inas

autorestart=true

directory=/home/inas/storm/bin

command=/home/inas/storm/bin/storm ui

[program:storm_supervisor]

user=inas

autorestart=true

directory=/home/inas/storm/bin

command=/home/inas/storm/bin/storm supervisor

附录/etc/supervisord.conf  (安徽样例)

4)添加自启动服务脚本:

vi /etc/init.d/supervisord

详见附录/etc/init.d/supervisord

5)生成日志目录并添加到服务里:

mkdir -p /var/log/supervisor

chmod +x /etc/init.d/supervisord

chkconfig --add supervisord

chkconfig --list supervisord

6)相关命令:

service supervisord start|stop|status|reload|restart

supervisorctl status

supervisorctl start xxx

supervisorctl stop xxx

supervisorctl update

7)监控页面(如需要安全性,也可以设置账号):

http://x.x.x.x:9001

8)FAQ:

Q)由supervisord守护的进程条件?

A)启动命令中不能包含daemon或&后台符来运行即可。

Q)如果/etc/supervisord.conf里新增加了app,需要重启supervisord?

A)可以通过service supervisord restart来重启所有app;

也可以通过supervisorctl update命令来运行新增的app,而原有未改动的app不受影响。

附录1:

/etc/supervisord.conf文件样例:

; Sample supervisor config file.

;

; For more information on the config file, please see:

; http://supervisord.org/configuration.html

;

; Notes:

;  - Shell expansion ("~" or "$HOME") is not supported.  Environment

;    variables can be expanded using this syntax: "%(ENV_HOME)s".

;  - Comments must have a leading space: "a=b ;comment" not "a=b;comment".

[unix_http_server]

file=/tmp/supervisor.sock       ; (the path to the socket file)

;chmod=0700                 ; socket file mode (default 0700)

;chown=nobody:nogroup       ; socket file uid:gid owner

;username=user              ; (default is no username (open server))

;password=123               ; (default is no password (open server))

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

[supervisord]

logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)

logfile_maxbytes=50MB        ; (max main logfile bytes b4 rotation;default 50MB)

logfile_backups=10           ; (num of main logfile rotation backups;default 10)

loglevel=info                ; (log level;default info; others: debug,warn,trace)

pidfile=/var/run/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)

;umask=022                   ; (process file creation umask;default 022)

;user=chrism                 ; (default is current user, required if root)

;identifier=supervisor       ; (supervisord identifier, default is 'supervisor')

;directory=/tmp              ; (default is not to cd during start)

;nocleanup=true              ; (don't clean up tempfiles at start;default false)

;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)

;environment=KEY="value"     ; (key value pairs to add to environment)

;strip_ansi=false            ; (strip ansi escape codes in logs; def. false)

; the below section must remain in the config file for RPC

; (supervisorctl/web interface) to work, additional interfaces may be

; added by defining them in separate rpcinterface: sections

[rpcinterface:supervisor]

supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]

serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket

;username=chris              ; should be same as http_username if set

;password=123                ; should be same as http_password if set

;prompt=mysupervisor         ; cmd line prompt (default "supervisor")

;history_file=~/.sc_history  ; use readline history if available

; The below sample program section shows all possible program subsection values,

; create one or more 'real' program: sections to be able to control them under

; supervisor.

;[program:theprogramname]

;command=/bin/cat              ; the program (relative uses PATH, can take args)

;process_name=%(program_name)s ; process_name expr (default %(program_name)s)

;numprocs=1                    ; number of processes copies to start (def 1)

;directory=/tmp                ; directory to cwd to before exec (def no cwd)

;umask=022                     ; umask for process (default None)

;priority=999                  ; the relative start priority (default 999)

;autostart=true                ; start at supervisord start (default: true)

;startsecs=1                   ; # of secs prog must stay up to be running (def. 1)

;startretries=3                ; max # of serial start failures when starting (default 3)

;autorestart=unexpected        ; when to restart if exited after running (def: unexpected)

;exitcodes=0,2                 ; 'expected' exit codes used with autorestart (default 0,2)

;stopsignal=QUIT               ; signal used to kill process (default TERM)

;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)

;stopasgroup=false             ; send stop signal to the UNIX process group (default false)

;killasgroup=false             ; SIGKILL the UNIX process group (def false)

;user=chrism                   ; setuid to this UNIX account to run the program

;redirect_stderr=true          ; redirect proc stderr to stdout (default false)

;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 (default 10)

;stdout_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)

;stdout_events_enabled=false   ; emit events on stdout writes (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 (default 10)

;stderr_capture_maxbytes=1MB   ; number of bytes in 'capturemode' (default 0)

;stderr_events_enabled=false   ; emit events on stderr writes (default false)

;environment=A="1",B="2"       ; process environment additions (def no adds)

;serverurl=AUTO                ; override serverurl computation (childutils)

; The below sample eventlistener section shows all possible

; eventlistener subsection values, create one or more 'real'

; eventlistener: sections to be able to handle event notifications

; sent by supervisor.

;[eventlistener:theeventlistenername]

;command=/bin/eventlistener    ; the program (relative uses PATH, can take args)

;process_name=%(program_name)s ; process_name expr (default %(program_name)s)

;numprocs=1                    ; number of processes copies to start (def 1)

;events=EVENT                  ; event notif. types to subscribe to (req'd)

;buffer_size=10                ; event buffer queue size (default 10)

;directory=/tmp                ; directory to cwd to before exec (def no cwd)

;umask=022                     ; umask for process (default None)

;priority=-1                   ; the relative start priority (default -1)

;autostart=true                ; start at supervisord start (default: true)

;startsecs=1                   ; # of secs prog must stay up to be running (def. 1)

;startretries=3                ; max # of serial start failures when starting (default 3)

;autorestart=unexpected        ; autorestart if exited after running (def: unexpected)

;exitcodes=0,2                 ; 'expected' exit codes used with autorestart (default 0,2)

;stopsignal=QUIT               ; signal used to kill process (default TERM)

;stopwaitsecs=10               ; max num secs to wait b4 SIGKILL (default 10)

;stopasgroup=false             ; send stop signal to the UNIX process group (default false)

;killasgroup=false             ; SIGKILL the UNIX process group (def false)

;user=chrism                   ; setuid to this UNIX account to run the program

;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 (default 10)

;stdout_events_enabled=false   ; emit events on stdout writes (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 (default 10)

;stderr_events_enabled=false   ; emit events on stderr writes (default false)

;environment=A="1",B="2"       ; process environment additions

;serverurl=AUTO                ; override serverurl computation (childutils)

; The below sample group section 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 = relative/directory/*.ini

[program:zookeeper]

user=inas

autorestart=true

command=/usr/java/default/bin/java -Dzookeeper.log.dir=/home/inas/zookeeper-3.4.8/bin -Dzookeeper.root.logger=INFO,CONSOLE -cp /home/inas/zookeeper-3.4.8/build/classes:/home/inas/zookeeper-3.4.8/build/lib/*.jar:/home/inas/zookeeper-3.4.8/lib/slf4j-log4j12-1.6.1.jar:/home/inas/zookeeper-3.4.8/lib/slf4j-api-1.6.1.jar:/home/inas/zookeeper-3.4.8/lib/netty-3.7.0.Final.jar:/home/inas/zookeeper-3.4.8/lib/log4j-1.2.16.jar:/home/inas/zookeeper-3.4.8/lib/jline-0.9.94.jar:/home/inas/zookeeper-3.4.8/zookeeper-3.4.8.jar:/home/inas/zookeeper-3.4.8/src/java/lib/*.jar:/home/inas/zookeeper-3.4.8/conf:.:/usr/java/default/lib/dt.jar:/usr/java/default/lib/tools.jar: -Xms4096m -Xmx4096m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.local.only=false org.apache.zookeeper.server.quorum.QuorumPeerMain /home/inas/zookeeper-3.4.8/conf/zoo.cfg

[program:storm_nimbus]

user=inas

autorestart=true

command=/home/inas/storm/bin/storm nimbus

[program:storm_ui]

user=inas

autorestart=true

command=/home/inas/storm/bin/storm ui

[program:storm_supervisor]

user=inas

autorestart=true

command=/home/inas/storm/bin/storm supervisor

[program:haproxy]

user=inas

autorestart=true

directory=/home/inas/haproxy

command=/home/inas/haproxy/haproxy -f haproxy_supervisord.cfg

[program:tomcat1]

user=inas

autorestart=true

directory=/home/inas/tomcat1/bin

command=/home/inas/tomcat1/bin/catalina.sh run

[program:tomcat2]

user=inas

autorestart=true

directory=/home/inas/tomcat2/bin

command=/home/inas/tomcat2/bin/catalina.sh run

附录2

/etc/init.d/supervisord 文件样例:

#!/bin/bash

#

# supervisord   Startup script for the Supervisor process control system

#

# Author:       Mike McGrath <mmcgrath@redhat.com> (based off yumupdatesd)

#               Jason Koppe <jkoppe@indeed.com> adjusted to read sysconfig,

#                   use supervisord tools to start/stop, conditionally wait

#                   for child processes to shutdown, and startup later

#               Erwan Queffelec <erwan.queffelec@gmail.com>

#                   make script LSB-compliant

#

# chkconfig:    345 83 04

# 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

# config: /etc/supervisord.conf

# config: /etc/sysconfig/supervisord

# pidfile: /var/run/supervisord.pid

#

### BEGIN INIT INFO

# Provides: supervisord

# Required-Start: $all

# Required-Stop: $all

# Short-Description: start and stop Supervisor process control system

# Description: Supervisor is a client/server system that allows

#   its users to monitor and control a number of processes on

#   UNIX-like operating systems.

### END INIT INFO

# Source function library

. /etc/rc.d/init.d/functions

# Source system settings

if [ -f /etc/sysconfig/supervisord ]; then

. /etc/sysconfig/supervisord

fi

# Path to the supervisorctl script, server binary,

# and short-form for messages.

supervisorctl=/usr/bin/supervisorctl

supervisord=${SUPERVISORD-/usr/bin/supervisord}

prog=supervisord

pidfile=${PIDFILE-/var/run/supervisord.pid}

lockfile=${LOCKFILE-/var/lock/subsys/supervisord}

STOP_TIMEOUT=${STOP_TIMEOUT-60}

OPTIONS="${OPTIONS--c /etc/supervisord.conf}"

RETVAL=0

start() {

echo -n $"Starting $prog: "

daemon --pidfile=${pidfile} $supervisord $OPTIONS

RETVAL=$?

echo

if [ $RETVAL -eq 0 ]; then

touch ${lockfile}

$supervisorctl $OPTIONS status

fi

return $RETVAL

}

stop() {

echo -n $"Stopping $prog: "

killproc -p ${pidfile} -d ${STOP_TIMEOUT} $supervisord

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && rm -rf ${lockfile} ${pidfile}

}

reload() {

echo -n $"Reloading $prog: "

LSB=1 killproc -p $pidfile $supervisord -HUP

RETVAL=$?

echo

if [ $RETVAL -eq 7 ]; then

failure $"$prog reload"

else

$supervisorctl $OPTIONS status

fi

}

restart() {

stop

start

}

case "$1" in

start)

start

;;

stop)

stop

;;

status)

status -p ${pidfile} $supervisord

RETVAL=$?

[ $RETVAL -eq 0 ] && $supervisorctl $OPTIONS status

;;

restart)

restart

;;

condrestart|try-restart)

if status -p ${pidfile} $supervisord >&/dev/null; then

stop

start

fi

;;

force-reload|reload)

reload

;;

*)

echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload}"

RETVAL=2

esac

exit $RETVAL

转载于:https://www.cnblogs.com/chenjunjie/p/7793924.html

Supervisord进程管家相关推荐

  1. 2018-05-18 docker supervisord进程管家

    目录: 一.mysupervisord文件夹准备 二.mysupervisord容器的生成 三.附件 3.1.supervisord文件内容 3.2.backup.sh文件内容 3.3.Dockerf ...

  2. supervisor 进程管家的安装及测试

    supervisor  tail 项目名称 sdout        输出错误提示 # 注意 supervidor 依赖python2.4-2.7  python3下 使用pip无法安装 使用pyth ...

  3. Docker 入门教程-----supervisor(进程管家)配置与Docker使用

    supervisord的官网:http://supervisord.org supervisor管理进程,是通过fork/exec的方式将这些被管理的进程当作supervisor的子进程来启动,所以我 ...

  4. supervisord 进程管理利器

    Supervisor概述 ​ supervisor是一个 Client/Server模式的系统,允许用户在类unix操作系统上监视和控制多个进程,或者可以说是多个程序.supervisor与launc ...

  5. supervisord进程管理

    Supervisord Supervisord是一款基于Python的进程管理工具,当主机上存在多个的进程需要管理时,通过supervisor可以简化进程的管理. 再通过supervisor提供的rp ...

  6. Python Supervisord 进程管理工具

    Supervisord,用Python实现的一款非常实用的进程管理工具,在批量服务化管理时特别有效. 环境 centos python2.6.6 安装  wget http://pypi.python ...

  7. linux服务与进程管理sup,linux下进程管理工具-supervisord

    一 简介 supervisord是linux下的一个优秀的进程管理工具,通过supervisord可以方便管理和应用linux系统下服务进程过多的问题,其支持服务异常退出自动重启,通过浏览器管理控制相 ...

  8. linux下进程管理工具-supervisord

    一 简介 supervisord是linux下的一个优秀的进程管理工具,通过supervisord可以方便管理和应用linux系统下服务进程过多的问题,其支持服务异常退出自动重启,通过浏览器管理控制相 ...

  9. supervisor 守护多个进程_supervisor守护进程管理实操笔记

    2020年年后工作中需开发一支持多数据源自动上报业务数据的程序,程序开发完部署上线时需要对其进程进行自动管理,不然哪天程序down了还不知,可就麻烦了,所以这里选用了强大的supervisor,以下文 ...

最新文章

  1. uploadify 上传
  2. liun5实现DHCP地址分配笔记
  3. python高维向量的可视化_Tensorboard教程:高维向量可视化
  4. boost::container实现devector选项程序
  5. mysql varchar 2000能存_mysql 数据库 varchar 到底可以存多少数据呢,长文慎入
  6. 容器化之路:谁偷走了我的构建时间
  7. Hadoop1.0.4伪分布式安装
  8. 个人网站建设教程|本地网站环境搭建|网站制作教程
  9. V831——PWM驱动舵机
  10. python迅雷下载任务出错_迅雷下载任务出错的原因和解决方法 来研究下吧
  11. Excel画横坐标不均分的图表
  12. win7如何隐藏所有微软服务器,如何隐藏Win7登录界面的administrator用户名
  13. Python OpenCV开发MR智能人脸识别打卡系统(四、服务模块设计)
  14. 计算机 查找 功能的使用,详解电脑搜索快捷键是什么?
  15. BMS专题之动力电池组
  16. Python 图像文字识别提取的两种简单方案(Windows)
  17. 好的代码结构是什么样的?
  18. 【存储器了解 RAM flash和eeprom存储器的区别和作用】
  19. MATLAB实验报告之五
  20. Python beautifulsoup库实践

热门文章

  1. java--xml文件读取(SAX)
  2. Android 如何调用系统默认浏览器访问
  3. iOS开发Swift篇—(七)函数(1)
  4. 关于JS的传递方式的小理解
  5. mysql.zip免安装版配置
  6. C#Word转Html的类
  7. RUNOOB python练习题19 找出1000以内的所有完数
  8. 阿里一年,聊聊我成长了什么,入职阿里的职业生涯感悟
  9. JavaScript-基础入门.0014.JavaScript内置对象
  10. linux中fcntl()、lockf、flock的区别