【问题标题】:Celery not running in production芹菜没有在生产中运行
【发布时间】:2015-07-05 08:04:01
【问题描述】:

我正在尝试在生产中运行 celery 和 celerybeat。在我当前的 django 应用程序中,我可以使用命令“celery -A Gorgon worker”和“celery -A Gorgon beat -l debug --max-interval=10”进行测试和运行。另外,我正在通过 virtualenv 运行它。另外,我使用 redis 作为任务代理。

整个应用程序在 gunicorn 服务器上运行。但是,当我尝试守护进程时,它会因 111 连接错误而失败。

我已将 https://github.com/celery/celery/tree/3.0/extra/generic-init.d 中的所需脚本添加到目录 /etc/init.d 中

至于 /etc/defaults 中的脚本,它们看起来像这样:

我的celeryd脚本如下

# Names of nodes to start
#   most will only start one node:

CELERYD_NODES="worker1"

#   but you can also start multiple and configure settings
#   for each in CELERYD_OPTS (see `celery multi --help` for examples).
#CELERYD_NODES="worker1 worker2 worker3"
# Absolute or relative path to the 'celery' command:
#CELERY_BIN="/usr/local/bin/celery"

CELERY_BIN="/home/ubuntu/sites/virtualenv/bin/celery"

# App instance to use
# comment out this line if you don't use an app

CELERY_APP="Gorgon"

# or fully qualified:
#CELERY_APP="proj.tasks:app"
# Where to chdir at start.

CELERYD_CHDIR="/home/ubuntu/sites/source"

# Extra command-line arguments to the worker

CELERYD_OPTS="--time-limit=300 --concurrency=8"

# %N will be replaced with the first part of the nodename.

CELERYD_LOG_FILE="/var/log/celery/%N.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

我的 celerybeat 脚本是

# Absolute or relative path to the 'celery' command:

CELERY_BIN="/home/ubuntu/sites/virtualenv/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="Gorgon"

# or fully qualified:
#CELERY_APP="proj.tasks:app"
# Where to chdir at start.

CELERYBEAT_CHDIR="/home/ubuntu/sites/source"

# Extra arguments to celerybeat
#CELERYBEAT_OPTS="--schedule=/var/run/celery/celerybeat-schedule"

如何使用 /home/ubuntu/sites/virtualenv 中的当前虚拟环境让我的 celery 设置作为守护进程运行

【问题讨论】:

  • 你为什么不用supervisor
  • CELERYBEAT_CHDIR= /path/to/project/ ?
  • "/home/ubuntu/sites/source" 是项目所在的目录。即 manage.py 在源文件夹中。

标签: django celery django-celery celerybeat celeryd


【解决方案1】:

要在守护进程中运行 celery,你可以使用 supervisor。 此链接可能会帮助您了解如何在守护程序模式下运行 celery。 http://www.hiddentao.com/archives/2012/01/27/processing-long-running-django-tasks-using-celery-rabbitmq-supervisord-monit/

【讨论】:

    猜你喜欢
    • 2015-10-09
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    • 2013-11-10
    • 1970-01-01
    • 1970-01-01
    • 2019-12-07
    • 2020-05-06
    相关资源
    最近更新 更多