使用 supervisor 管理 Celery 服务
使用 supervisor 管理 Celery 服务
Celery 后台运行
如果我们想让celery worker运行在后台而不是终端上,在后台以守护进程的方式运行,我们可以使用supervisor进行管理。
celery 的安装
pip install celery
celery的安装很简单,直接通过pip就能够安装,并且本身没有任何的配置,如果需要命令行运行,直接以下命令:
celery -A proj(个人的项目,一般为main文件的相对路径) worker -l info
注意:如果你是win10系统,使用上面命令,可能报错:
Celery ValueError: not enough values to unpack (expected 3, got 0)
请查看这篇文章解决问题
使用通用的 init-script
首先获取 Celery 的 GitHub 仓库 extra/generic-init.d/
文件夹下的文件。
启动 worker
将上面 GitHub 仓库文件夹下的 celeryd
文件复制到本地的 /etc/init.d/celeryd
文件中并赋予可执行的权限: sudo chmod +x /etc/init.d/celeryd
,然后在 /etc/default/
文件夹下创建 celeryd
配置文件:
# Names of nodes to start
# most people will only start one node:
CELERYD_NODES="worker1"
# but you can also start multiple and configure settings
# for each in CELERYD_OPTS
#CELERYD_NODES="worker1 worker2 worker3"
# alternatively, you can specify the number of nodes to start:
#CELERYD_NODES=10 # Absolute or relative path to the 'celery' command:
CELERY_BIN="/usr/local/bin/celery"
#CELERY_BIN="/virtualenvs/def/bin/celery" # App instance to use
# comment out this line if you don't use an app
CELERY_APP="proj"
# or fully qualified:
#CELERY_APP="proj.tasks:app" # Where to chdir at start.
CELERYD_CHDIR="/opt/Myproject/" # Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=300 --concurrency=8"
# Configure node-specific settings by appending node name to arguments:
#CELERYD_OPTS="--time-limit=300 -c 8 -c:worker2 4 -c:worker3 2 -Ofair:worker1" # Set logging level to DEBUG
#CELERYD_LOG_LEVEL="DEBUG" # %n will be replaced with the first part of the nodename.
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid" # Workers should run as an unprivileged user.
# You need to create this user manually (or you can choose
# a user/group combination that already exists (e.g., nobody).
CELERYD_USER="celery"
CELERYD_GROUP="celery" # If enabled pid and log directories will be created if missing,
# and owned by the userid/group configured.
CELERY_CREATE_DIRS=1
这个配置文件中,你可能需要更改 CELERY_BIN
, CELERY_APP
, CELERYD_CHDIR
, CELERYD_USER
, CELERYD_GROUP
。
根据你自身项目配置好上述配置后就可以通过 /etc/init.d/celeryd {start|stop|restart|graceful|kill|dryrun|create-paths}
这些命令来控制 Celery worker 进程。
启动 beat
如果你的项目中还有周期任务,那么还得把 Celery beat 启动起来。
把 GitHub 仓库中的 celerybeat
文件复制到 /etc/init.d/celerybeat
文件中,然后赋予可执行权限: sudo chmod +x /etc/init.d/celerybeat
。
然后同样得有一个 /etc/default/celerybeat
配置文件。不过,如果没有什么特殊配置,可以直接使用 /etc/default/celeryd
配置文件,不必创建 /etc/default/celerybeat
配置文件。
如果你依然要创建的,那么这个文件可能是长这样的:
# Absolute or relative path to the 'celery' command:
CELERY_BIN="/usr/local/bin/celery"
#CELERY_BIN="/virtualenvs/def/bin/celery" # App instance to use
# comment out this line if you don't use an app
CELERY_APP="proj"
# or fully qualified:
#CELERY_APP="proj.tasks:app" # Where to chdir at start.
CELERYBEAT_CHDIR="/opt/Myproject/" # Extra arguments to celerybeat
CELERYBEAT_OPTS="--schedule=/var/run/celery/celerybeat-schedule"
完成配置后,同样通过 /etc/init.d/celerybeat {start|stop|restart|create-paths|status}
这些命令控制 Celery beat 进程。
参考文档:
Celery daemon
How to run celery as a daemon?
使用 supervisor 管理 Celery 服务的更多相关文章
- celery和supervisor配合使用,实现supervisor管理celery进程
在这里我选择redis作为celery异步任务的中间人,系统选择CentOS6.5 64位.redis.celery和supervisor的安装参见官方文档. 安装完毕后: 1, 创建celery的实 ...
- 使用Supervisor管理Celery进程。
讲过一篇celery的,但是celery启动后并不是daemon的,在生产环境中这肯定是不可以的,那怎么办呢? 这就需要使用supervisor进行进程管理了,下面详细介绍. 一. superviso ...
- supervisor 管理 celery
安装supervisor [root@ipv6-api ~]# pip3 install supervisor 生成配置文件 [root@ipv6-api ~]#echo_supervisord_c ...
- supervisor管理superset
参考: https://blog.51cto.com/qiangsh/2153185 安装supervisor: pip install supervisor 停止supervisor管理的服务: [ ...
- 在 OSX 下使用 supervisor 管理服务
我为什么想用 supervisor 来管理服务呢?因为我在系统管理上属于处女座+任性的气质. OSX 下办公用的是普通用户,我不想在 root 权限下做过多设置污染我的系统. OSX 下的服务管理我感 ...
- Linux服务:使用Supervisor管理进程
一.简介 由于基本每个公司都会用到supervisor这个进程管理工具,这里简单阐述一下. Supervisor (http://supervisord.org) 是一个用Python写Linux下的 ...
- supervisor管理进程工具配置
Supervisor(http://supervisord.org/)是用Python开发的一个client/server服务,是Linux/Unix系统下的一个进程管理工具,不支持Windows系统 ...
- 使用 supervisor 管理进程
安装: # yum install python-setuptools # easy_install supervisor 如果已经安装了epel和python-pip, 也可以简单 pip inst ...
- Supervisor 管理后台守护进程
Supervisor 管理后台守护进程 参考原文如下: http://codinn.com/people/brant/notes/110948/ 做了一些注释 +++++++++++引用开始+++++ ...
随机推荐
- 关于 oracle10g、oracle client和plsql devement 三者之间的关系
oracle10g是服务器,如果本机安装了oracle10g,没有必要安装oracle client,只要配置好DNS,就可以使用plsql devement连接 当然你也可以同时安装orac ...
- LeetCode82----删除排序链表中的重复元素 II
给定一个排序链表,删除所有含有重复数字的节点,只保留原始链表中 没有重复出现 的数字. 示例 1: 输入: 1->2->3->3->4->4->5 输出: 1-&g ...
- 20175212童皓桢 《Java程序设计》第十周学习总结
学号 2016-2017-2 <Java程序设计>第X周学习总结 教材学习内容总结 一.Java中的线程的状态 建的线程在它的一个完整的生命周期中通常要经历如下的四种状态: 1.新建: 当 ...
- 十四周学习总结&简易记事本
学习总结: 一.JDBC: 1.JDBC提供里一套与平台无关的标准数据库操作接口和类,只要支持java的数据库厂商,所提供的数据库都可以以使用JDBC操作. 2.JDBC的主要操作类及接口: 3.JD ...
- shell编程常用命令
Linux中常用的命令 #nl filename 使用nl命令打印文件内容并显示行号 #sed '/nw/,$d' filename 使用sed命令删除匹配nw至最后一行的内容 ...
- Difference Between Currency Swap and FX Swap
[z]https://www.differencebetween.com/difference-between-currency-swap-and-vs-fx-swap/ Currency Swap ...
- pureftp安装部署
ftp:文件传输pure-ftpd:ftp软件作用:通过映射登录传送和接收文件.1.先下载pure-ftpd软件,最好指定一个下载软件目录如:/usr/local/src wget https://d ...
- 阶段3 2.Spring_10.Spring中事务控制_2 作业-基于注解的AOP实现事务控制及问题分析_上
创建maven的新项目 先复制坐标的依赖. 再把代码复制进来 先改造ioc的部分 复制上面一行代码.到下面 改成context 这里也是复制的上面两行代码.到下面改成context关键字 配置扫描的包 ...
- 【漏洞汇总】SQL 注入漏洞之 mysql
日期:2019-07-23 19:55:59 更新:2019-08-02 10:40:37 作者:Bay0net 介绍:Mysql 注入笔记 0x01. 基本信息 1.1 基本术语 数据库: 数据库是 ...
- fixture详细介绍-作为参数传入,error和failed区别
前言 fixture是pytest的核心功能,也是亮点功能,熟练掌握fixture的使用方法,pytest用起来才会得心应手! fixture简介 fixture的目的是提供一个固定基线,在该基线上测 ...