风岭社区

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 3121|回复: 1

CentOS 6.6安装配置supervisor历程管理工具

[复制链接]
发表于 2016-11-2 10:54:55 | 显示全部楼层 |阅读模式
CentOS 6.6安装配置supervisor进程管理工具
1. Supervisor是一个C/S系统,它可以在类unix操作系统让用户来监视和控制后台服务进程的数量,一个很重要的功能就是监控服务器的主要后台进程,并在出现问题是自动重启。

2. 根据服务器上的python版本下载对应的setuptools
[root@test1 ~]# python -V
Python 2.6.6
  1. wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg
复制代码
直接安装
sh setuptools-0.6c11-py2.6.egg

3. 下载并安装supervisor

  1. wget http://pypi.python.org/packages/source/s/supervisor/supervisor-3.0b1.tar.gz
  2. tar -zxvf supervisor-3.0b1.tar.gz
  3. cd supervisor-3.0b1
  4. python setup.py install
复制代码
安装setuptools后也可以
easy_install supervisor

4. 设定supervisor配置文件
创建默认的配置文件
echo_supervisord_conf  >/etc/supervisord.conf
vi /etc/supervisord.conf
取消以下的注释,并修改IP为0.0.0.0

[inet_http_server]        ; inet (TCP) server disabled by defaultport=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))

增加自定义的后台进程(注意进程名之间用一个:分隔)

[program:hello]command=python /root/hello.pypriority=1numprocs=1autostart=trueautorestart=truestartretries=10stopsignal=KILLstopwaitsecs=10redirect_stderr=truestdout_logfile=/root/hello.log


5. 执行如下命令:
vi /etc/init.d/supervisord

6.输入如下内容:

注意:该文件中的如下几个变量,都需要根据你实际的目录来改写。

PREFIX=/usr/local

SUPERVISORD=$PREFIX/bin/supervisord      ##supervisord   程序的安装路径

SUPERVISORCTL=$PREFIX/bin/supervisorctl  ##supervisorctl 程序的安装路径

PIDFILE=/var/supervisor/supervisord.pid   ##需要先创建/var/supervisor目录

LOCKFILE=/var/supervisor/supervisord.lock

OPTIONS="-c /etc/supervisord.conf"   ##配置文件的路径
  1. #!/bin/bash
  2. #
  3. # supervisord   This scripts turns supervisord on
  4. # chkconfig:        345 83 04
  5. # description:  supervisor is a process control utility.  It has a web based
  6. #          xmlrpc interface as well as a few other nifty features.
  7. #

  8. # source function library
  9. . /etc/rc.d/init.d/functions

  10. set -a

  11. PREFIX=/usr/local

  12. SUPERVISORD=$PREFIX/bin/supervisord
  13. SUPERVISORCTL=$PREFIX/bin/supervisorctl

  14. PIDFILE=/var/supervisor/supervisord.pid
  15. LOCKFILE=/var/supervisor/supervisord.lock

  16. OPTIONS="-c /etc/supervisord.conf"

  17. # unset this variable if you don't care to wait for child processes to shutdown before removing the $LOCKFILE-lock
  18. WAIT_FOR_SUBPROCESSES=yes

  19. # remove this if you manage number of open files in some other fashion
  20. ulimit -n 96000

  21. RETVAL=0


  22. running_pid()
  23. {
  24.   # Check if a given process pid's cmdline matches a given name
  25.   pid=$1
  26.   name=$2
  27.   [ -z "$pid" ] && return 1
  28.   [ ! -d /proc/$pid ] && return 1
  29.   (cat /proc/$pid/cmdline | tr "\000" "\n"|grep -q $name) || return 1
  30.   return 0
  31. }

  32. running()
  33. {
  34. # Check if the process is running looking at /proc
  35. # (works for all users)

  36.   # No pidfile, probably no daemon present
  37.   [ ! -f "$PIDFILE" ] && return 1
  38.   # Obtain the pid and check it against the binary name
  39.   pid=`cat $PIDFILE`
  40.   running_pid $pid $SUPERVISORD || return 1
  41.   return 0
  42. }

  43. start() {
  44.     echo "Starting supervisord: "

  45.     if [ -e $PIDFILE ]; then
  46.     echo "ALREADY STARTED"
  47.     return 1
  48.   fi

  49.   # start supervisord with options from sysconfig (stuff like -c)
  50.     $SUPERVISORD $OPTIONS

  51.   # show initial startup status
  52.   $SUPERVISORCTL $OPTIONS status

  53.   # only create the subsyslock if we created the PIDFILE
  54.     [ -e $PIDFILE ] && touch $LOCKFILE
  55. }

  56. stop() {
  57.     echo -n "Stopping supervisord: "
  58.     $SUPERVISORCTL $OPTIONS shutdown
  59.   if [ -n "$WAIT_FOR_SUBPROCESSES" ]; then
  60.       echo "Waiting roughly 60 seconds for $PIDFILE to be removed after child processes exit"
  61.       for sleep in  2 2 2 2 4 4 4 4 8 8 8 8 last; do
  62.         if [ ! -e $PIDFILE ] ; then
  63.           echo "Supervisord exited as expected in under $total_sleep seconds"
  64.           break
  65.         else
  66.           if [[ $sleep -eq "last" ]] ; then
  67.             echo "Supervisord still working on shutting down. We've waited roughly 60 seconds, we'll let it do its thing from here"
  68.             return 1
  69.           else
  70.             sleep $sleep
  71.             total_sleep=$(( $total_sleep + $sleep ))
  72.           fi

  73.         fi
  74.       done
  75.     fi

  76.     # always remove the subsys. We might have waited a while, but just remove it at this point.
  77.     rm -f $LOCKFILE
  78. }

  79. restart() {
  80.     stop
  81.     start
  82. }

  83. case "$1" in
  84.   start)
  85.     start
  86.     RETVAL=$?
  87.     ;;
  88.   stop)
  89.     stop
  90.     RETVAL=$?
  91.     ;;
  92.   restart|force-reload)
  93.     restart
  94.     RETVAL=$?
  95.     ;;
  96.   reload)
  97.     $SUPERVISORCTL $OPTIONS reload
  98.     RETVAL=$?
  99.     ;;
  100.   condrestart)
  101.     [ -f $LOCKFILE ] && restart
  102.     RETVAL=$?
  103.     ;;
  104.   status)
  105.     $SUPERVISORCTL $OPTIONS status
  106.     if running ; then
  107.       RETVAL=0
  108.     else
  109.       RETVAL=1
  110.     fi
  111.     ;;
  112.   *)
  113.     echo [        DISCUZ_CODE_0        ]quot;Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
  114.     exit 1
  115. esac

  116. exit $RETVAL
复制代码
保存完毕之后,可以执行以下命令修改文件权限:

chmod 777 /etc/init.d/supervisord

/etc/init.d/supervisord  start

这样,supervisor就启动了。

7. 配置开机启动

执行以下命令:

chkconfig supervisord  on

可以以下命令查看是否成功

chkconfig --list | grep  supervisord

回复

使用道具 举报

发表于 2020-8-1 14:06:29 | 显示全部楼层

Котлы варочные

Котлы варочные

Котлы варочные
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|Comsenz Inc.

GMT+8, 2024-4-27 00:55 , Processed in 0.040446 second(s), 8 queries , File On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表