Supervisord进程管家
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)监控页面(如需要安全性,也可以设置账号):
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
Supervisord进程管家的更多相关文章
- supervisord 进程管家
s supervisor supervisor管理进程,是通过fork/exec的方式将这些被管理的进程当作supervisor的子进程来启动,所以我们只需要将要管理进程的可执行文件的路径添加到sup ...
- Supervisord进程管理工具
进程管理工具Supervisord Posted on 2014/06/17 by admin Supervisord 上面已经介绍了Go目前是有两种方案来实现他的daemon,但是官方本身还不支持这 ...
- supervisord进程管理工具小结
前言 昨天临近下班,发现业务队列处理不及时,正好想到不久之前,上了一个新功能:通过队列异步转发微信消息.可能是消息太多了处理不过来,没怎么多想,处理不过来了,多增加处理进程就可以了,后来发现自己so ...
- supervisord进程管理
一:简介 supervisord是一个进程管理工具,提供web页面管理,能对进程进行自动重启等操作. 优点: - 可以将非后台运行程序后台运行 - 自动监控,重启进程 缺点: - 不能管理后台运行程序 ...
- Supervisord管理进程实践
今天凑空研究了下Supervisord,这是一款linux进程管理工具,使用python开发,主要用于在后台维护进程(类似master守护进程),可以实现监控进程的状态.自动重启进程等操作,便于一些服 ...
- supervisord 小记
此篇仅用作supervisord的用法,不涉及理论说明和基础介绍 supervisor(一)基础篇 使用supervisord来管理process 进程的守护神 - Supervisor superv ...
- 进程管理工具Supervisor(一)简介与使用
Supervisor是用Python开发的一套client/server架构的进程管理程序,能做到开机启动,以daemon进程的方式运行程序,并可以监控进程状态等等. linux进程管理方式有传统的r ...
- Supervisor 安装及配置管理uwsgi进程
Supervisor介绍 Supervisor 允许其用户在UNIX类操作系统上控制多个进程. 块如下: 方便 需要为每个进程实例编写rc.d脚本通常是不方便的. rc.d脚本是进程初始化/自动启动/ ...
- supervisor进程管理的使用
介绍 Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动重启.它是通过fork/exec的方式把这些被管理 ...
随机推荐
- LeetCode初级算法之数组:283 移动零
移动零 题目地址:https://leetcode-cn.com/problems/move-zeroes/ 给定一个数组 nums,编写一个函数将所有 0 移动到数组的末尾,同时保持非零元素的相对顺 ...
- go学习的第7天
不容易啊,坚持7天了呢,今天开始看视频学习 https://www.bilibili.com/video/BV1pt41127FZ?from=search&seid=4441824587572 ...
- CSP-S2020初赛游记
前一星期 感觉没怎么复习初赛啊,经常旷初赛练习赛--整天刷复赛题被老师怒斥了. zhoukangyang 天天做初赛(但是一天还是稳定做 \(2\) 道黑题),是不是要 AK 了啊(慌... 前一天 ...
- 第一章、Docker 简介
笔记内容来自:第一本Docker书 [澳] James Turnbull 著 李兆海 刘斌 巨震 Docker 是一个能够把开发的应用程序自动部署到容器的开源引擎.(由Docker 公司,前dot ...
- Excel优雅导出
流程 原来写过一篇文章,是介绍EasyExcel的,但是现在有些业务需要解决,流程如下 1.需要把导出条件转换成中文并存入数据库 2.需要分页导出 3.需要上传FTP或者以后上传OSS 解决方案 大体 ...
- 04-flask-模版基础
Jinja2 概念 Jinja2:是 Python 下一个被广泛应用的模板引擎,是由Python实现的模板语言,他的设计思想来源于 Django 的模板引擎,并扩展了其语法和一系列强大的功能,其是Fl ...
- 使用BulkLoad恢复hbase数据
问题: hbase 集群启动不了,maste一直在初始化,数据面临丢失风险. 解决: 把hbfs上 /hbase 目录移走 改名为/hbase-bak 删除zk上的数据,重新建立一个新的hbase集群 ...
- vulstudy靶机搭建(kali)
安装 安装docker apt-get install docker.io //# 安装docker pip install docker-compose //# 安装docker-compose g ...
- RabbitMq基本概念理解
RabbitMQ的基本概念 RabbitMQ github项目地址 RabbitMQ 2007年发布,是一个在AMQP(高级消息队列协议)基础上完成的,可复用的企业消息系统,是当前最主流的 消息中间件 ...
- 这个 bug 让我更加理解 Spring 单例了
我是风筝,公众号「古时的风筝」,一个兼具深度与广度的程序员鼓励师,一个本打算写诗却写起了代码的田园码农! 文章会收录在 JavaNewBee 中,更有 Java 后端知识图谱,从小白到大牛要走的路都在 ...