supervise程序进行程序管理监控

Supervise是daemontools的一个工具,可以用来监控管理unix下的应用程序运行情况,在应用程序出现异常时,supervise可以重新启动指定程序。

1.安装,很简单

[root@test log]# yum search supervisor
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.hustunique.com
 * epel: mirrors.hustunique.com
 * extras: mirrors.hustunique.com
 * updates: mirrors.hustunique.com
 * webtatic: us-east.repo.webtatic.com
====================================================== N/S Matched: supervisor =======================================================
nodejs-supervisor.noarch : A supervisor program for running nodejs programs
python-simplevisor.noarch : Python simple daemons supervisor
supervisor.noarch : A System for Allowing the Control of Process State on UNIX

  Name and summary matches only, use "search all" for everything.
[root@test log]# 

亦或者

[root@test log]# pip2.6 search  supervise
supervise                 - Tools for communicating with runit / daemontools supervisors.
Usurper                   - An unsupervised dependency parser.
sparse_filtering          - Unsupervised feature learning based on sparse-filtering
gpalign                   - Unsupervised grapheme-phoneme aligner for Japanese
Little-Snob               - A simple library for unsupervised classification of data.
[root@test log]# 
2.配置相关

yum安装的会自动生成/etc/init.d/supervisord 和 /etc/supervisord.conf

如果是pip 安装的话,则麻烦点需要手动生成以上两者,好处是版本较薪

生成配置文件:echo_supervisord_conf >/etc/supervisord.conf

关于/etc/init.d/下面的脚本可以参考:

https://github.com/Supervisor/initscripts/blob/master/redhat-init-mingalevme

3. 一个小demo,测试服务是httpd 服务

极其简单的配置文件如下:

[root@test supervisor]# cat /etc/supervisord.conf |grep -v '^;'


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


[inet_http_server]         ; inet (TCP) server disabled by default
port=0.0.0.0:9001        ; (ip_address:port specifier, *:port for all iface)


[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           ; (num of main logfile rotation backups;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
serverurl=http://10.210.71.143:9001 ; use an http:// url to specify an inet socket








[program:apache]
command=/usr/sbin/httpd -c "ErrorLog /dev/stdout" -DFOREGROUND             ; the program (relative uses PATH, can take args)
user=root                   ; setuid to this UNIX account to run the program
redirect_stderr=true          ; redirect proc stderr to stdout (default false)
测试方式:

killall -9 'httpd' 

-9 很重要,意思是意外的退出,如果不加 -9  那么在终端下是 -15 

过一会,很小的一会,httpd 服务会自动重启起来的。

注:httpd前台运行


4.web界面查看和控制

http://10.210.71.143:9001/

显示:


可以灵活的控制

就不用专门的去为每个需要检测的服务写一个脚本去检测进程是否存在了

 



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值