centos利用supervisord实现守护进程,保证后台常驻进程服务的高可用
安装supervisor
#第一种 yum install python-setuptools easy_install pip pip install supervisor #第二种 yum install python-setuptools easy_install supervisor #第三种 wget https://pypi.python.org/packages/source/s/supervisor/supervisor-3.1.3.tar.gz tar zxvf supervisor-3.1.3.tar.gz cd supervisor python setup.py install #第四种 yum install -y epel-release yum install -y supervisor
配置
cd /etc/ mkdir supervisord.d echo_supervisord_conf > supervisord.conf vim /etc/supervisord.conf #加入以下配置信息 [include] files = /etc/supervisord.d/*.conf
开机启动服务文件
#!/bin/sh # # /etc/init.d/supervisord # # Supervisor is a client/server system that # allows its users to monitor and control a # number of processes on UNIX-like operating # systems. # # chkconfig: - 64 36 # description: Supervisor Server # processname: supervisord # Source init functions . /etc/rc.d/init.d/functions prog="supervisord" prog_bin="/usr/bin/supervisord" PIDFILE="/var/run/$prog.pid" start() { echo -n $"Starting $prog: " ###注意下面这一行一定得有-c /etc/supervisord.conf 不然修改了配置文件根本不生效! daemon $prog_bin -c /etc/supervisord.conf --pidfile $PIDFILE [ -f $PIDFILE ] && success $"$prog startup" || failure $"$prog startup" echo } stop() { echo -n $"Shutting down $prog: " [ -f $PIDFILE ] && killproc $prog || success $"$prog shutdown" echo } case "$1" in start) start ;; stop) stop ;; status) status $prog ;; restart) stop start ;; *) echo "Usage: $0 {start|stop|restart|status}" ;; esac
chmod +x /etc/init.d/supervisord chkconfig --add supervisord chkconfig supervisord on service supervisord start
开启web查看
# 如果想通过web查看管理的进程,加入以下代码,监听9001,用户user,密码123 [inet_http_server] port=9001 username=user password=123
创建一个任务
#在重启之前随便创建一个挂在后台的命令 vim /etc/supervisord.d/tail.conf [program:task1] command=tail -f /etc/supervisord.conf ;常驻后台的命令 autostart=true ;是否随supervisor启动 autorestart=true ;是否在挂了之后重启,意外关闭后会重启,比如kill掉! startretries=3 ;启动尝试次数 stderr_logfile=/tmp/task1.err.log ;标准输出的位置 stdout_logfile=/tmp/task1.out.log ;标准错误输出的位置
查看服务是否启动
##查看一下是否监听 lsof -i:9001 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME superviso 7782 root 4u IPv4 74522612 0t0 TCP *:etlservicemgr (LISTEN)
web方式查看
http://ip:9001 #输入你上面设置的账号密码,管理台上可以启动和停止服务
相关推荐
liwf 2020-06-10
ooouuuooouuu 2020-05-09
wintelx 2020-04-30
iamplane 2020-01-16
CoderBoom 2015-07-07
liusarazhang 2019-11-03
ningningmingming 2019-07-10
88991030 2019-06-02
86133550 2019-09-05
七夕小子 2019-09-05
fhxyxzw 2019-08-19
热爱技术热爱生活 2015-09-24
projectharbor 2019-07-01
sevenpolaris 2015-07-14
vitavae 2019-06-30
周小董 2015-07-07