zoukankan      html  css  js  c++  java
  • supervisord进程管理工具小结

    前言

        昨天临近下班,发现业务队列处理不及时,正好想到不久之前,上了一个新功能:通过队列异步转发微信消息。可能是消息太多了处理不过来,没怎么多想,处理不过来了,多增加处理进程就可以了,后来发现自己so young了 >_<!启动处理进程,必须先安装进程管理工具,比较出名的有supervisord,使用python语言实现。折腾了近半小时,后来发现自己不可能在短时间内搞定这个事情,业务上用户消息没有得到及时回复,需要快速处理,最后还是寻求公司大神帮助安装其它前端机的supervisord。为了学会安装以及使用这个神器,为了以后碰到这样的问题可以自己搞定,在测试机上尝试安装了这个神器,于是有了这篇总结的文章。

    查看依赖python模块是否安装(只安装没有的依赖包)

    1 [root@mtest3 ~]# python -u -c "help('modules')" > a.log
    2 [root@mtest3 ~]# cat a.log | grep element
    3 [root@mtest3 ~]# cat a.log | grep meld
    4 [root@mtest3 ~]# cat a.log | grep setuptool

    先安装依赖包
    1.elementtree-1.2.6-20050316.tar.gz

    1 [root@mtest3 Supervisord]# tar -xvf elementtree-1.2.6-20050316.tar.gz 
    2 [root@mtest3 Supervisord]# cd elementtree-1.2.6-20050316
    3 [root@mtest3 elementtree-1.2.6-20050316]# python setup.py install

    2.meld3-0.6.5.tar.gz

    1 [root@mtest3 Supervisord]# tar -xvf meld3-0.6.5.tar.gz 
    2 [root@mtest3 Supervisord]# cd meld3-0.6.5
    3 [root@mtest3 meld3-0.6.5]# python setup.py install

    3.setuptools-20.2.2.tar.gz

    1 [root@mtest3 Supervisord]# tar -xvf setuptools-20.2.2.tar.gz
    2 [root@mtest3 Supervisord]# cd setuptools-20.2.2
    3 [root@mtest3 setuptools-20.2.2]# python setup.py install

    3.安装supervisord

    1 [root@mtest3 Supervisord]# tar -xvf supervisor-3.2.2.tar.gz 
    2 [root@mtest3 Supervisord]# cd supervisor-3.2.2
    3 [root@mtest3 supervisor-3.2.2]# python setup.py install
    4 
    5 Installing echo_supervisord_conf script to /usr/bin
    6 Installing pidproxy script to /usr/bin
    7 Installing supervisorctl script to /usr/bin
    8 Installing supervisord script to /usr/bin

    生成配置文件

     1 [root@mtest3 ~]# echo_supervisord_conf > /u01/server/supervisord/conf/supervisord.conf 

    设置

     1 ; Sample supervisor config file.
     2 ;
     3 ; For more information on the config file, please see:
     4 ; http://supervisord.org/configuration.html
     5 ;
     6 
     7 [unix_http_server]
     8 file=/u01/server/supervisord/temp/supervisor.sock ; (the path to the socket file)
     9 
    10 [supervisord]
    11 logfile=/u01/server/supervisord/logs/supervisord.log ; (main log file;default $CWD/supervisord.log)
    12 logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
    13 logfile_backups=10 ; (num of main logfile rotation backups;default 10)
    14 loglevel=info ; (log level;default info; others: debug,warn,trace)
    15 pidfile=/u01/server/supervisord/temp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
    16 nodaemon=false ; (start in foreground if true;default false)
    17 minfds=1024 ; (min. avail startup file descriptors;default 1024)
    18 minprocs=200 ; (min. avail process descriptors;default 200)
    19 
    20 ; the below section must remain in the config file for RPC
    21 ; (supervisorctl/web interface) to work, additional interfaces may be
    22 ; added by defining them in separate rpcinterface: sections
    23 [rpcinterface:supervisor]
    24 supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
    25 
    26 [supervisorctl]
    27 serverurl=unix:///u01/server/supervisord/temp/supervisor.sock ; use a unix:// URL for a unix socket
    28 
    29 ; The below sample program section shows all possible program subsection values,
    30 ; create one or more 'real' program: sections to be able to control them under
    31 ; supervisor.
    32 
    33 [program:wx_front]
    34 command=/u01/server/php/bin/php /u01/server/apps/wechat/artisan queue:listen --queue=wxqueue --timeout=60 --delay=3 --memory=128 --sleep=3 --tries=0 --env=test ; the program (relative uses PATH, can take args)
    35 process_name=%(program_name)s ; process_name expr (default %(program_name)s)
    36 numprocs=2 ; number of processes copies to start (def 1)
    37 ;directory=/tmp ; directory to cwd to before exec (def no cwd)
    38 ;umask=022 ; umask for process (default None)
    39 ;priority=999 ; the relative start priority (default 999)
    40 autostart=true ; start at supervisord start (default: true)
    41 startsecs=3 ; # of secs prog must stay up to be running (def. 1)
    42 startretries=3 ; max # of serial start failures when starting (default 3)
    43 ;autorestart=unexpected ; when to restart if exited after running (def: unexpected)
    44 ;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2)
    45 ;stopsignal=QUIT ; signal used to kill process (default TERM)
    46 ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10)
    47 ;stopasgroup=false ; send stop signal to the UNIX process group (default false)
    48 ;killasgroup=false ; SIGKILL the UNIX process group (def false)
    49 user=daemon ; setuid to this UNIX account to run the program
    50 ;redirect_stderr=true ; redirect proc stderr to stdout (default false)
    51 stdout_logfile=/u01/server/supervisord/logs/wx_front_stdout.log ; stdout log path, NONE for none; default AUTO
    52 stdout_logfile_maxbytes=50MB ; max # logfile bytes b4 rotation (default 50MB)
    53 stdout_logfile_backups=5 ; # of stdout logfile backups (default 10)
    54 ;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
    55 ;stdout_events_enabled=false ; emit events on stdout writes (default false)
    56 stderr_logfile=/u01/server/supervisord/logs/wx_front_stderr.log ; stderr log path, NONE for none; default AUTO
    57 stderr_logfile_maxbytes=50MB ; max # logfile bytes b4 rotation (default 50MB)
    58 ;stderr_logfile_backups=10 ; # of stderr logfile backups (default 10)
    59 ;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
    60 ;stderr_events_enabled=false ; emit events on stderr writes (default false)
    61 ;environment=A="1",B="2" ; process environment additions (def no adds)
    62 ;serverurl=AUTO ; override serverurl computation (childutils)
    63 
    64 [program:wx_admin]
    65 command=/u01/server/php/bin/php /u01/server/apps/admin/artisan queue:listen --queue=wx_queue_admin --timeout=60 --delay=3 --memory=128 --sleep=3 --tries=0 --env=test ; the program (relative uses PATH, can take args)
    66 process_name=%(program_name)s ; process_name expr (default %(program_name)s)
    67 numprocs=2 ; number of processes copies to start (def 1)
    68 autostart=true ; start at supervisord start (default: true)
    69 startsecs=3 ; # of secs prog must stay up to be running (def. 1)
    70 startretries=3 ; max # of serial start failures when starting (default 3)
    71 user=daemon ; setuid to this UNIX account to run the program
    72 stdout_logfile=/u01/server/supervisord/logs/wx_admin_stdout.log ; stdout log path, NONE for none; default AUTO
    73 stdout_logfile_maxbytes=50MB ; max # logfile bytes b4 rotation (default 50MB)
    74 stdout_logfile_backups=5 ; # of stdout logfile backups (default 10)
    75 stderr_logfile=/u01/server/supervisord/logs/wx_admin_stderr.log ; stderr log path, NONE for none; default AUTO
    76 stderr_logfile_maxbytes=50MB ; max # logfile bytes b4 rotation (default 50MB)

    开机自启动
    /etc/rc.local
    supervisord -c /u01/server/supervisord/conf/supervisord.conf

    手动启动
    supervisord -c /u01/server/supervisord/conf/supervisord.conf

    进程管理
    1.进入cli终端

    [root@mtest3 logs]# supervisorctl -c /u01/server/supervisord/conf/supervisord.conf
    supervisor> 

    2.查看进程状态

    1 supervisor> status
    2 wx_admin:0 RUNNING pid 26305, uptime 0:07:42
    3 wx_admin:1 RUNNING pid 26304, uptime 0:07:42
    4 wx_front:0 RUNNING pid 26307, uptime 0:07:42
    5 wx_front:1 RUNNING pid 26306, uptime 0:07:42

    3.重启superivsord服务(更改配置之后)

    supervisor> reload
    Really restart the remote supervisord process y/N? y
    Restarted supervisord

    4.关闭进程

    1 supervisor> stop all
    2 wx_admin:1: stopped
    3 wx_admin:0: stopped
    4 wx_front:1: stopped
    5 wx_front:0: stopped

    5.启动进程

    1 supervisor> start all
    2 wx_admin:1: started
    3 wx_admin:0: started
    4 wx_front:1: started
    5 wx_front:0: started

    6.查看命令行帮助(支持的命令,以及用法)

    1 supervisor> help
    2 
    3 default commands (type help <topic>):
    4 =====================================
    5 add exit open reload restart start tail 
    6 avail fg pid remove shutdown status update 
    7 clear maintail quit reread signal stop version

    7.退出

    1 supervisor> exit
    2 
    3 default commands (type help <topic>):
    4 =====================================
    5 add exit open reload restart start tail 
    6 avail fg pid remove shutdown status update 
    7 clear maintail quit reread signal stop version

    备注
    1.配置key value必须至少包含一个空格再跟上 ; 注释符号

    后记

    看起来安装这个很简单,实际操作过之后,还是碰到一些意外的坑,而这些坑只有实际操作过才能发现:)

    参考资料
    [1] supervisord官网
    http://supervisord.org/index.html

    [2] supervisor github

    https://github.com/Supervisor/supervisor/releases

    [3] elementtree-1.2.6-20050316
    http://effbot.org/downloads#elementtree

    [4] meld3-0.6.5
    http://www.plope.com/software/meld3/

    [5] setuptools-20.2.2
    https://pypi.python.org/pypi/setuptools#downloads

    作者:WadeYu
    出处:http://www.cnblogs.com/wadeyu/
    本文版权归本人和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    【BZOJ】1620: [Usaco2008 Nov]Time Management 时间管理(贪心)
    【BZOJ】1651: [Usaco2006 Feb]Stall Reservations 专用牛棚(线段树/前缀和 + 差分)
    【BZOJ】1628 && 1683: [Usaco2007 Demo]City skyline 城市地平线(单调栈)
    【BZOJ】1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路(floyd)
    【BZOJ】1622: [Usaco2008 Open]Word Power 名字的能量(dp/-模拟)
    【BZOJ】1634: [Usaco2007 Jan]Protecting the Flowers 护花(贪心)
    【BZOJ】1690: [Usaco2007 Dec]奶牛的旅行(分数规划+spfa)
    【BZOJ】1660: [Usaco2006 Nov]Bad Hair Day 乱发节(单调栈)
    【BZOJ】1642: [Usaco2007 Nov]Milking Time 挤奶时间(dp)
    【BZOJ】1629: [Usaco2007 Demo]Cow Acrobats(贪心+排序)
  • 原文地址:https://www.cnblogs.com/wadeyu/p/5280450.html
Copyright © 2011-2022 走看看