zoukankan      html  css  js  c++  java
  • supervisor安装配置与使用

    supervisor:C/S架构的进程控制系统,可使用户在类UNIX系统中监控、管理进程。常用于管理与某个用户或项目相关的进程。

    组成部分
    supervisord:服务守护进程
    supervisorctl:命令行客户端
    Web Server:提供与supervisorctl功能相当的WEB操作界面
    XML-RPC Interface:XML-RPC接口

    安装
    centos平台下可直接用过YUM源安装
    yum info supervisor
    sudo yum install supervisor
    sudo chkconfig supervisord on

    服务器启停
    sudo /etc/init.d/supervisord {start|stop|status|restart|reload|force-reload|condrestart}

    日志
    /var/log/supervisor/supervisord.log

    配置文件
    sudo vim /etc/supervisord.conf

    需要重点关注的是以部分
    [program:x]中配置要监控的进程


    配置样例

    [plain] view plain copy
     
    1. [supervisord]  
    2. http_port=/var/tmp/supervisor.sock ; (default is to run a UNIX domain socket server)  
    3. ;http_port=127.0.0.1:9001  ; (alternately, ip_address:port specifies AF_INET)  
    4. ;sockchmod=0700              ; AF_UNIX socketmode (AF_INET ignore, default 0700)  
    5. ;sockchown=nobody.nogroup     ; AF_UNIX socket uid.gid owner (AF_INET ignores)  
    6. ;umask=022                   ; (process file creation umask;default 022)  
    7. logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)  
    8. logfile_maxbytes=50MB       ; (max main logfile bytes b4 rotation;default 50MB)  
    9. logfile_backups=10          ; (num of main logfile rotation backups;default 10)  
    10. loglevel=info               ; (logging level;default info; others: debug,warn)  
    11. pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)  
    12. nodaemon=false              ; (start in foreground if true;default false)  
    13. minfds=1024                 ; (min. avail startup file descriptors;default 1024)  
    14. minprocs=200                ; (min. avail process descriptors;default 200)  
    15.   
    16. ;nocleanup=true              ; (don't clean up tempfiles at start;default false)  
    17. ;http_username=user          ; (default is no username (open system))  
    18. ;http_password=123           ; (default is no password (open system))  
    19. ;childlogdir=/tmp            ; ('AUTO' child log dir, default $TEMP)  
    20. ;user=chrism                 ; (default is current user, required if root)  
    21. ;directory=/tmp              ; (default is not to cd during start)  
    22. ;environment=KEY=value       ; (key value pairs to add to environment)  
    23.   
    24. [supervisorctl]  
    25. serverurl=unix:///var/tmp/supervisor.sock ; use a unix:// URL  for a unix socket  
    26. ;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket  
    27. ;username=chris              ; should be same as http_username if set  
    28. ;password=123                ; should be same as http_password if set  
    29. ;prompt=mysupervisor         ; cmd line prompt (default "supervisor")  
    30.   
    31. ; The below sample program section shows all possible program subsection values,  
    32. ; create one or more 'real' program: sections to be able to control them under  
    33. ; supervisor.  
    34.   
    35. ;[program:example]  
    36. ;command=/bin/echo; the program (relative uses PATH, can take args)  
    37. ;priority=999                ; the relative start priority (default 999)  
    38. ;autostart=true              ; start at supervisord start (default: true)  
    39. ;autorestart=true            ; retstart at unexpected quit (default: true)  
    40. ;startsecs=10                ; number of secs prog must stay running (def. 10)  
    41. ;startretries=3              ; max # of serial start failures (default 3)  
    42. ;exitcodes=0,2               ; 'expected' exit codes for process (default 0,2)  
    43. ;stopsignal=QUIT             ; signal used to kill process (default TERM)  
    44. ;stopwaitsecs=10             ; max num secs to wait before SIGKILL (default 10)  
    45. ;user=chrism                 ; setuid to this UNIX account to run the program  
    46. ;log_stdout=true             ; if true, log program stdout (default true)  
    47. ;log_stderr=true             ; if true, log program stderr (def false)  
    48. ;logfile=/var/log/supervisor.log    ; child log path, use NONE for none; default AUTO  
    49. ;logfile_maxbytes=1MB        ; max # logfile bytes b4 rotation (default 50MB)  
    50. ;logfile_backups=10          ; # of logfile backups (default 10)  

    “;”为注释。各参数的含义都很明确。可以根据官方手册结合实验来进一步深入了解。重点说几个[program:example]中的参数

    [plain] view plain copy
     
    1. ;command=/bin/echo;         supervisor启动时将要开启的进程。相对或绝对路径均可。若是相对路径则会从supervisord的$PATH变中查找。命令可带参数。  
    2. ;priority=999                   指明进程启动和关闭的顺序。低优先级表明进程启动时较先启动关闭时较后关闭。高优先级表明进程启动时启动时较后启动关闭时较先关闭。  
    3. ;autostart=true                 是否随supervisord启动而启动  
    4. ;autorestart=true               进程意外退出后是否自动重启  
    5. ;startsecs=10                   进程持续运行多久才认为是启动成功  
    6. ;startretries=3                 重启失败的连续重试次数  
    7. ;exitcodes=0,2                  若autostart设置为unexpected且监控的进程并非因为supervisord停止而退出,那么如果进程的退出码不在exitcode列表中supervisord将重启进程  
    8. ;stopsignal=QUIT                杀进程的信号  
    9. ;stopwaitsecs=10                向进程发出stopsignal后等待OS向supervisord返回SIGCHILD 的时间。若超时则supervisord将使用SIGKILL杀进程  

    一个Rabbitmq项目中生产者和消费者进程使用supervisor监控的配置情况:(配置中的其他部分略)

    [plain] view plain copy
     
    1. </pre><p><pre name="code" class="plain">[program:worker_for_summary]  
    2. command=/home/op1/scripts/rabbitmqclient/worker_for_summary.py  
    3. priority=1  
    4. log_stderr=true             ; if true, log program stderr (def false)  
    5.   
    6. [program:worker_for_detail_all]  
    7. command=/home/op1/scripts/rabbitmqclient/worker_for_detail_all.py  
    8. priority=1  
    9. log_stderr=true             ; if true, log program stderr (def false)  
    10.   
    11. [program:worker_for_detail_recent_list]  
    12. command=/home/op1/scripts/rabbitmqclient/worker_for_detail_recent_list.py  
    13. priority=1  
    14. log_stderr=true             ; if true, log program stderr (def false)  
    15.   
    16. [program:worker_for_detail_recent_sset]  
    17. command=/home/op1/scripts/rabbitmqclient/worker_for_detail_recent_sset.py  
    18. priority=1  
    19. log_stderr=true             ; if true, log program stderr (def false)  
    20.   
    21. [program:publisher_for_summary]  
    22. command=/home/op1/scripts/rabbitmqclient/publisher_for_summary.py  
    23. priority=999  
    24. log_stderr=true             ; if true, log program stderr (def false)  
    25.   
    26. [program:publisher_for_summary_nt]  
    27. command=/home/op1/scripts/rabbitmqclient/publisher_for_summary_nt.py  
    28. priority=999  
    29. log_stderr=true             ; if true, log program stderr (def false)  
    30.   
    31. [program:publisher_for_detail]  
    32. command=/home/op1/scripts/rabbitmqclient/publisher_for_detail.py  
    33. priority=999  
    34. log_stderr=true             ; if true, log program stderr (def false)  
    35.   
    36. [program:publisher_for_detail_nt]  
    37. command=/home/op1/scripts/rabbitmqclient/publisher_for_detail_nt.py  
    38. priority=999  
    39. log_stderr=true             ; if true, log program stderr (def false)  
    40.                                                                       

    配置完成后启动supervisord

    [plain] view plain copy
     
    1. sudo /etc/init.d/supervisord start  

    可以看到配置的各个进程在后台运行了起来。
    停掉某个进程后supervisor会马上重启该进程

    停止supervisor

    [plain] view plain copy
     
    1. sudo /etc/init.d/supervisord stop  

    可以看到配置的各个进程都停止运行了。

    可以通过supervisorctl查看管理监控的进程情况:

    [plain] view plain copy
     
    1. [op1@SVR1631HP360 ~]$ sudo supervisorctl  
    2. publisher_for_detail RUNNING    pid 27557, uptime 0:00:45  
    3. publisher_for_detail_nt RUNNING    pid 27567, uptime 0:00:45  
    4. publisher_for_summary RUNNING    pid 27566, uptime 0:00:45  
    5. publisher_for_summary_nt RUNNING    pid 27568, uptime 0:00:45  
    6. worker_for_detail_all RUNNING    pid 27581, uptime 0:00:45  
    7. worker_for_detail_recent RUNNING    pid 27582, uptime 0:00:45  
    8. worker_for_summary RUNNING    pid 27559, uptime 0:00:45  
    9.   
    10. #可通过help了解命令的更多用法  
    11. supervisor> help  
    12.   
    13. Documented commands (type help <topic>):  
    14. ========================================  
    15. EOF    exit  maintail  quit    restart   start   stop  
    16. clear  help  open      reload  shutdown  status  tail  
    17.   
    18. supervisor> help stop  
    19. stop <processname>            Stop a process.  
    20. stop <processname> <processname>    Stop multiple processes  
    21. stop all                Stop all processes  
    22.   When all processes are stopped, they are stopped in  
    23.   reverse priority order (see config file)  
    24. supervisor> help status  
    25. status          Get all process status info.  
    26. status <name>     Get status on a single process by name.  
    27. status <name> <name>    Get status on multiple named processes.  
    28.   
    29. #停止某个进程  
    30. supervisor> stop publisher_for_summary  
    31. publisher_for_summary: stopped  
    32.   
    33. #查看此时此刻的状态  
    34. supervisor> status  
    35. publisher_for_detail RUNNING    pid 27557, uptime 0:05:41  
    36. publisher_for_detail_nt RUNNING    pid 27567, uptime 0:05:41  
    37. publisher_for_summary STOPPED    Feb 27 02:48 PM  
    38. publisher_for_summary_nt RUNNING    pid 27568, uptime 0:05:41  
    39. worker_for_detail_all RUNNING    pid 27581, uptime 0:05:41  
    40. worker_for_detail_recent RUNNING    pid 27582, uptime 0:05:41  
    41. worker_for_summary RUNNING    pid 27559, uptime 0:05:41  
    42. #发现被supervisorctl停掉的进程不会被自动重启  
    43.   
    44. #开启刚才停掉的进程  
    45. supervisor> start publisher_for_summary  
    46. publisher_for_summary: started  
    47. supervisor> status  
    48. publisher_for_detail RUNNING    pid 27557, uptime 0:08:02  
    49. publisher_for_detail_nt RUNNING    pid 27567, uptime 0:08:02  
    50. publisher_for_summary RUNNING    pid 3035, uptime 0:00:04  
    51. publisher_for_summary_nt RUNNING    pid 27568, uptime 0:08:02  
    52. worker_for_detail_all RUNNING    pid 27581, uptime 0:08:02  
    53. worker_for_detail_recent RUNNING    pid 27582, uptime 0:08:02  
    54. worker_for_summary RUNNING    pid 27559, uptime 0:08:02  
    55.   
    56. #停掉所有进程  
    57. supervisor> stop all  
    58. worker_for_detail_recent: stopped  
    59. worker_for_detail_all: stopped  
    60. publisher_for_summary_nt: stopped  
    61. publisher_for_detail_nt: stopped  
    62. publisher_for_summary: stopped  
    63. worker_for_summary: stopped  
    64. publisher_for_detail: stopped  
    65. supervisor> status  
    66. publisher_for_detail STOPPED    Feb 27 02:51 PM  
    67. publisher_for_detail_nt STOPPED    Feb 27 02:51 PM  
    68. publisher_for_summary STOPPED    Feb 27 02:51 PM  
    69. publisher_for_summary_nt STOPPED    Feb 27 02:51 PM  
    70. worker_for_detail_all STOPPED    Feb 27 02:51 PM  
    71. worker_for_detail_recent STOPPED    Feb 27 02:51 PM  
    72. worker_for_summary STOPPED    Feb 27 02:51 PM  
    73.   
    74. #开启所有进程  
    75. supervisor> start all  
    76. publisher_for_detail: started  
    77. worker_for_summary: started  
    78. publisher_for_summary: started  
    79. publisher_for_detail_nt: started  
    80. publisher_for_summary_nt: started  
    81. worker_for_detail_all: started  
    82. worker_for_detail_recent: started  
    83. supervisor> status  
    84. publisher_for_detail RUNNING    pid 5111, uptime 0:00:15  
    85. publisher_for_detail_nt RUNNING    pid 5141, uptime 0:00:15  
    86. publisher_for_summary RUNNING    pid 5135, uptime 0:00:15  
    87. publisher_for_summary_nt RUNNING    pid 5147, uptime 0:00:15  
    88. worker_for_detail_all RUNNING    pid 5153, uptime 0:00:15  
    89. worker_for_detail_recent RUNNING    pid 5159, uptime 0:00:14  
    90. worker_for_summary RUNNING    pid 5112, uptime 0:00:15  

    更多内容请参考官方手册
    http://supervisord.org/

  • 相关阅读:
    JMeter学习-图形化 HTML 报表概要说明
    转《Python爬虫学习系列教程》学习笔记
    PYTHON __main__
    python property
    loadrunner脚本,如何获取lr的变量以及lr变量和其他程序语言的变量的转换
    参考链接
    彻底抛弃脚本录制,LR脚本之使用web_custom_request函数自定义http请求
    如何看Analysis分析图
    Ubuntu16.04安装QQ2015
    Ubuntu16.04运行LSD-SLAM踩坑笔记
  • 原文地址:https://www.cnblogs.com/antflow/p/8005018.html
Copyright © 2011-2022 走看看