讲过一篇celery的,但是celery启动后并不是daemon的,在生产环境中这肯定是不可以的,那怎么办呢? 这就需要使用supervisor进行进程管理了,下面详细介绍。

一、 supervisor是干什么的。

supervisor是有Python语言编写的,基于linux操作系统的一款服务器管理工具,用以监控服务器进程的运行。
supervisor要求管理的程序是非daemon程序,supervisord会帮你把他转换成daemon程序。
因此如果使用supervisor来管理nginx进程的话,必须在nginx的配置文件里添加一行设置deamon off让nginx以非daemon方式启动,
我们这里是用supervisor是用它来管理celery进程。

二、supervisor安装

1. 安装好python环境,这个Linux系统都默认已经安装好了,但是建议安装2.7.0以上版本。
2. 使用pip或者easy_install安装
sudo pip install supervisor 或者
sudo easy_install supervisor
安装完以后,进入python交互式环境,输入:
import supervisor
如果没有错误提示则表示安装成功。

三、 supervisor配置

1. superisor配置生成
$ echo_supervidord_conf > /etc/supervisord.conf 2. 配置文件说明
$ sudo cp /etc/supervisord.conf /etc/suprtvidord.conf.bak # 首先备份一下配置文件
废话不多说,直接贴配置文件(配置文件中以;开头的行表示注释): ; Sample supervisor config file.
;
; For more information on the config file, please see:
; http://supervisord.org/configuration.html
;
; Notes:
; - Shell expansion ("~" or "$HOME") is not supported. Environment
; variables can be expanded using this syntax: "%(ENV_HOME)s".
; - Comments must have a leading space: "a=b ;comment" not "a=b;comment". # [unix_http_server] 这个模块主要是配置sock文件的路径及权限
[unix_http_server]
file=/var/run/supervisor.sock ; (the path to the socket file)
chmod=0700 ; socket file mode (default 0700)
chown=root:root ; socket file uid:gid owner
;username=admin ; (default is no username (open server))
;password=admin ; (default is no password (open server))
# [inet_http_server] 这个模块只要是配置Web管理界面
[inet_http_server] ; inet (TCP) server disabled by default
port=127.0.0.1:9001 ; (ip_address:port specifier, *:port for all iface)
username=admin ; (default is no username (open server))
password=admin ; (default is no password (open server))
# [supervisord] 这个模块是supervisord服务的配置模块,比如日志文件位置,日志等级等等
[supervisord]
logfile=/home/liuyadong/log/supervisor/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=/var/run/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)
;umask=022 ; (process file creation umask;default 022)
;user=chrism ; (default is current user, required if root)
;identifier=supervisor ; (supervisord identifier, default is 'supervisor')
;directory=/tmp ; (default is not to cd during start)
;nocleanup=true ; (don't clean up tempfiles at start;default false)
;childlogdir=/tmp ; ('AUTO' child log dir, default $TEMP)
;environment=KEY="value" ; (key value pairs to add to environment)
;strip_ansi=false ; (strip ansi escape codes in logs; def. false) ; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface # [supervisorctl] 这个模块的值必须和"unix_http_server"里面设定的匹配
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
;serverurl=http://127.0.0.1:9001 ; use an http:// url to specify an inet socket
;username=admin ; should be same as http_username if set
;password=admin ; should be same as http_password if set
;prompt=mysupervisor ; cmd line prompt (default "supervisor")
;history_file=~/.sc_history ; use readline history if available ; The below sample program section shows all possible program subsection values,
; create one or more 'real' program: sections to be able to control them under
; supervisor.
# [program:xxx] 这个模块就是需要管理的进程模块, 字段属性也很简单,后面有注释就不详细介绍了。
# 这个模块可以是多个
[program:celery]
command=celery worker -A monitorAuto.celery --loglevel=info ; the program (relative uses PATH, can take args)
;process_name=%(program_name)s ; process_name expr (default %(program_name)s)
numprocs=1 ; number of processes copies to start (def 1)
directory=/home/liuyadong/git/monitor_auto/ ; directory to cwd to before exec (def no cwd)
autostart=true ; start at supervisord start (default: true)
startsecs=10 ; # of secs prog must stay up to be running (def. 1)
startretries=3 ; max # of serial start failures when starting (default 3)
;autorestart=ture ; when to restart if exited after running (def: unexpected)
;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2)
;stopsignal=QUIT ; signal used to kill process (default TERM)
stopwaitsecs=600 ; max num secs to wait b4 SIGKILL (default 10)
;stopasgroup=false ; send stop signal to the UNIX process group (default false)
killasgroup=true ; SIGKILL the UNIX process group (def false)
user=liuyadong ; setuid to this UNIX account to run the program
redirect_stderr=true ; redirect proc stderr to stdout (default false)
stdout_logfile=/home/liuyadong/log/supervisor/supercelery.log ; stdout log path, NONE for none; default AUTO
;stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stdout_logfile_backups=10 ; # of stdout logfile backups (default 10)
;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
;stdout_events_enabled=false ; emit events on stdout writes (default false)
stderr_logfile=/home/liuyadong/log/supervisor/supercelery.error.log ; stderr log path, NONE for none; default AUTO
;stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB)
;stderr_logfile_backups=10 ; # of stderr logfile backups (default 10)
;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0)
;stderr_events_enabled=false ; emit events on stderr writes (default false)
;environment=A="1",B="2" ; process environment additions (def no adds)
;serverurl=AUTO ; override serverurl computation (childutils) ; The below sample eventlistener section shows all possible
; eventlistener subsection values, create one or more 'real'
; eventlistener: sections to be able to handle event notifications
; sent by supervisor.
;[group:thegroupname]
;programs=progname1,progname2 ; each refers to 'x' in [program:x] definitions
;priority=999 ; the relative start priority (default 999) ; The [include] section can just contain the "files" setting. This
; setting can list multiple files (separated by whitespace or
; newlines). It can also contain wildcards. The filenames are
; interpreted as relative to this file. Included files *cannot*
; include files themselves. ;[include]
;files = relative/directory/*.ini

四、 Supervisord管理 Supervidord安装完成以后有两个可用的命令行supervisor和supervisorctl

 ? supervisord,                     初始启动Supervisord,启动、管理配置中设置的进程。
? supervisorctl stop programxxx 停止某一个进程(programxxx),programxxx为[program:chatdemon]里配置的值,这个示例就是chatdemon。
? supervisorctl start programxxx 启动某个进程
? supervisorctl restart programxxx 重启某个进程
? supervisorctl stop groupworker 重启所有属于名为groupworker这个分组的进程(start,restart同理)
? supervisorctl stop all 停止全部进程,注:start、restart、stop都不会载入最新的配置文件。
? supervisorctl reload 载入最新的配置文件,停止原有进程并按新的配置启动、管理所有进程。
? supervisorctl update 根据最新的配置文件,启动新配置或有改动的进程,配置没有改动的进程不会受影响而重启。 注意:显示用stop停止掉的进程,用reload或者update都不会自动重启。 可以使用--help查看命令更多的用法,我启动时遇到配置文件没有放到默认路径使用-c 参数执行

使用Supervisor管理Celery进程。的更多相关文章

  1. celery和supervisor配合使用,实现supervisor管理celery进程

    在这里我选择redis作为celery异步任务的中间人,系统选择CentOS6.5 64位.redis.celery和supervisor的安装参见官方文档. 安装完毕后: 1, 创建celery的实 ...

  2. 使用 supervisor 管理 Celery 服务

    使用 supervisor 管理 Celery 服务 Celery 后台运行 如果我们想让celery worker运行在后台而不是终端上,在后台以守护进程的方式运行,我们可以使用supervisor ...

  3. 使用Supervisor管理Linux进程

    使用Supervisor管理Linux进程 简介 Supervisor是一个C/S系统,它可以在类UNIX系统上控制系统进程,由python编写,提供了大量的功能来实现对进程的管理. 安装 sudo ...

  4. supervisor 管理 celery

    安装supervisor [root@ipv6-api ~]# pip3 install  supervisor 生成配置文件 [root@ipv6-api ~]#echo_supervisord_c ...

  5. supervisor 管理uwsgi 进程

    Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动 重启.它是通过fork/exec的方式把这些被管理的进 ...

  6. supervisor管理ELK进程

    1.配置supervisor #更新epel yum install epel-release yum install python-pip pip install supervisor -p /et ...

  7. supervisor管理进程工具配置

    Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统 ...

  8. Supervisor 管理进程,Cloud Insight 监控进程,完美!

    Supervisor 是由 Python 语言编写.基于 linux 操作系统的一款服务器管理工具,用于监控服务器的运行,发现问题能立即自动预警及自动重启等. Cloud Insight 是一款次世代 ...

  9. supervisor管理进程 superlance对进程状态报警

    supervisor介绍 首先,介绍一下supervisor.Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linu ...

随机推荐

  1. JS 信息提示弹框封装

    // 功能提示弹框 function tipsBox ( option ) { var html = ''; if ( option.type == 'success' ) { html += '&l ...

  2. github使用心的

    Git是一个分布式的版本控制系统,最初由LinusTorvalds编写,用作Linux内核代码的管理.在推出后,Git在其它项目中也取得了很大成功,尤其是在Ruby社区中.包括Rubinius和Mer ...

  3. GCD的其他方法

    1.栅栏函数 作用:控制线程的执行顺序 注:栅栏函数不能使用全局并发队列 -(void)barrier { //1.创建队列(并发队列) dispatch_queue_t queue = dispat ...

  4. linux命令基础学习

    谨慎使用 rm -rf /* 命令 谨慎在SSH执行“rm -rf /*”,若不了解这个命令,可能导致整个Linux系统文件全部被删除. 这个删除命令只有 “root” 权限的帐号才可以执行,其它未取 ...

  5. Python 基礎 - 數據類型

    標準數據類型 Python3 中有六個標準的數據類型 1 Number(數字) 2 String(字符串) 3 List (列表) 4 Tuple (元組) 5 Sets (集合) 6 Diction ...

  6. LintCode Search a 2D Matrix II

    排好序的二维数组, 从上到下从左到右增大, 给出一个数找出此数组里有多少个这个数. 不用两个循环做, 着手于条件(从左下角开始,若相等往右上跳一个,若小于target往右边跳一个,若大于target往 ...

  7. UDP信息接收与发送

    转载:http://www.cnblogs.com/sunev/archive/2012/08/08/2627247.html 一.摘要 总结基于C#的UDP协议的同步通信. 二.实验平台 Visua ...

  8. 修改MySQL用户的密码

    =====知道当前用户密码时===== P.S.:此文只针对windows下的用户密码更改. 1.使用进入MySQL的bin文件夹下: cd path\to\bin\mysqladmin.exe 2. ...

  9. MyEclipse定位class文件

    upolfind.bat :: 读取参数 例子 E:\workspaces\common-ws\xm_upol\WebRoot\WEB-INF\classes\${java_type_name} se ...

  10. [BZOJ 3503][Cqoi 2014]和谐矩阵

    我觉得这一题的样例输出一点都不和谐,大家千万别像我一样被坑了…… 题目不算难,果然是进错省系列555,不过搞出 O(n*m*2m) 的还是不要挣扎的比较好 我们暴力地推出第 n 行 第 m 列中每个数 ...