supervise程序进行程序管理监控

来源:互联网 发布:大疆 知乎 编辑:程序博客网 时间:2024/06/07 20:06

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

1.安装,很简单

[root@test log]# yum search supervisorLoaded plugins: fastestmirrorLoading 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 programspython-simplevisor.noarch : Python simple daemons supervisorsupervisor.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  supervisesupervise                 - Tools for communicating with runit / daemontools supervisors.Usurper                   - An unsupervised dependency parser.sparse_filtering          - Unsupervised feature learning based on sparse-filteringgpalign                   - Unsupervised grapheme-phoneme aligner for JapaneseLittle-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 defaultport=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 socketserverurl=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 programredirect_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 0