使用Supervisor管理Celery进程。
讲过一篇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进程。的更多相关文章
- celery和supervisor配合使用,实现supervisor管理celery进程
在这里我选择redis作为celery异步任务的中间人,系统选择CentOS6.5 64位.redis.celery和supervisor的安装参见官方文档. 安装完毕后: 1, 创建celery的实 ...
- 使用 supervisor 管理 Celery 服务
使用 supervisor 管理 Celery 服务 Celery 后台运行 如果我们想让celery worker运行在后台而不是终端上,在后台以守护进程的方式运行,我们可以使用supervisor ...
- 使用Supervisor管理Linux进程
使用Supervisor管理Linux进程 简介 Supervisor是一个C/S系统,它可以在类UNIX系统上控制系统进程,由python编写,提供了大量的功能来实现对进程的管理. 安装 sudo ...
- supervisor 管理 celery
安装supervisor [root@ipv6-api ~]# pip3 install supervisor 生成配置文件 [root@ipv6-api ~]#echo_supervisord_c ...
- supervisor 管理uwsgi 进程
Supervisor是用Python开发的一套通用的进程管理程序,能将一个普通的命令行进程变为后台daemon,并监控进程状态,异常退出时能自动 重启.它是通过fork/exec的方式把这些被管理的进 ...
- supervisor管理ELK进程
1.配置supervisor #更新epel yum install epel-release yum install python-pip pip install supervisor -p /et ...
- supervisor管理进程工具配置
Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统 ...
- Supervisor 管理进程,Cloud Insight 监控进程,完美!
Supervisor 是由 Python 语言编写.基于 linux 操作系统的一款服务器管理工具,用于监控服务器的运行,发现问题能立即自动预警及自动重启等. Cloud Insight 是一款次世代 ...
- supervisor管理进程 superlance对进程状态报警
supervisor介绍 首先,介绍一下supervisor.Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linu ...
随机推荐
- Python学习路程day9
本节内容 Gevent协程 Select\Poll\Epoll异步IO与事件驱动 Python连接Mysql数据库操作 RabbitMQ队列 Redis\Memcached缓存 Paramiko SS ...
- jquery操作select(增加,删除,清空)
jQuery获取Select选择的Text和Value: $("#select_id").change(function(){//code...}); //为Select添加事件, ...
- Lua协程
协作例程 1.同一时刻仅一个例程在运行 2.执行权让渡和恢复[栈]
- zTree简单使用和代码结构
1.页面使用元素代码 <input type="text" id="key" class="Side_Toput2" name=&qu ...
- 解决R速度太慢问题
R的速度慢一直被人诟病,最近做一个比较大的dataset的分析,跑得实在太慢,发现症结是R的data frame的index太慢: 以下为测试: gene_list = 1:100000 eQTL_m ...
- 这些 Git 技能够你用一年了
这些 Git 技能够你用一年了 原文出处: Pyper 用git有一年了,下面是我这一年来的git使用总结,覆盖了日常使用中绝大多数的场景.嗯,至少是够用一年了,整理出来分享给大家,不明白的地方可以回 ...
- 二叉排序树(BST)的建立
给一个非递归的吧. /* 已知,二叉树存储结构定义见bstree.h,请编写一个算法函数bstree creatBstree(int a[],int n), 以数组a中的数据作为输入建立一棵二叉排序树 ...
- ✡ leetcode 157. Read N Characters Given Read4 利用read4实现read --------- java
The API: int read4(char *buf) reads 4 characters at a time from a file. The return value is the actu ...
- 论文笔记之:Conditional Generative Adversarial Nets
Conditional Generative Adversarial Nets arXiv 2014 本文是 GANs 的拓展,在产生 和 判别时,考虑到额外的条件 y,以进行更加"激烈 ...
- post 与 get 在转码的区别
前端输入中文的时候,后端post通过 String text = getRequest().getParameter("text");可以正常拿到中文, 但是通过get的时候就会出 ...