需要帮助使用Systemd和启动脚本在Azure应用程序服务上部署芹菜Beat和芹菜Worker for Django,以及Azure缓存for Redis吗
我正在尝试将django webapp部署到azure,并在后台运行芹菜beat和worker实例。我尝试使用配置文件、启动脚本和systemd部署芹菜实例。但是我在运行.services文件时遇到了问题。这是我的系统服务文件 芹菜需要帮助使用Systemd和启动脚本在Azure应用程序服务上部署芹菜Beat和芹菜Worker for Django,以及Azure缓存for Redis吗,django,azure,celery,systemd,Django,Azure,Celery,Systemd,我正在尝试将django webapp部署到azure,并在后台运行芹菜beat和worker实例。我尝试使用配置文件、启动脚本和systemd部署芹菜实例。但是我在运行.services文件时遇到了问题。这是我的系统服务文件 芹菜 [Unit] Description=Celery Beat Service After=network.target [Service] Type=simple User=celery Group=celery EnvironmentFile=/e
[Unit]
Description=Celery Beat Service
After=network.target
[Service]
Type=simple
User=celery
Group=celery
EnvironmentFile=/etc/conf.d/celery_config
WorkingDirectory=/home/site/wwwroot/celery
ExecStart= /bin/sh -c '${CELERY_BIN} -A ${CELERY_APP} beat \
--pidfile=${CELERYBEAT_PID_FILE} \
--logfile=${CELERYBEAT_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL}'
Restart=always
[Install]
WantedBy=multi-user.target
2021-05-13T04:07:54.654058469Z Created symlink /etc/systemd/system/getty.target.wants/getty@tty1.service → /lib/systemd/system/getty@.service.
2021-05-13T04:07:54.659312989Z Created symlink /etc/systemd/system/multi-user.target.wants/remote-fs.target → /lib/systemd/system/remote-fs.target.
2021-05-13T04:07:54.668816506Z Created symlink /etc/systemd/system/sysinit.target.wants/systemd-timesyncd.service → /lib/systemd/system/systemd-timesyncd.service.
2021-05-13T04:07:54.727944856Z Adding group `systemd-journal' (GID 103) ...
2021-05-13T04:07:54.742460987Z Done.
2021-05-13T04:07:55.287951738Z Setting up libpam-systemd:amd64 (232-25+deb9u12) ...
2021-05-13T04:07:55.387856718Z debconf: unable to initialize frontend: Dialog
2021-05-13T04:07:55.388996844Z debconf: (TERM is not set, so the dialog frontend is not usable.)
2021-05-13T04:07:55.389631459Z debconf: falling back to frontend: Readline
2021-05-13T04:07:55.390632182Z debconf: unable to initialize frontend: Readline
2021-05-13T04:07:55.391113593Z debconf: (Can't locate Term/ReadLine.pm in @INC (you may need to install the Term::ReadLine module) (@INC contains: /etc/perl /usr/local/lib/x86_64-linux-gnu/perl/5.24.1 /usr/local/share/perl/5.24.1 /usr/lib/x86_64-linux-gnu/perl5/5.24 /usr/share/perl5 /usr/lib/x86_64-linux-gnu/perl/5.24 /usr/share/perl/5.24 /usr/local/lib/site_perl /usr/lib/x86_64-linux-gnu/perl-base .) at /usr/share/perl5/Debconf/FrontEnd/Readline.pm line 7.)
2021-05-13T04:07:55.392316820Z debconf: falling back to frontend: Teletype
2021-05-13T04:07:55.509303290Z Processing triggers for libc-bin (2.24-11+deb9u4) ...
2021-05-13T04:07:55.525179753Z Processing triggers for dbus (1.10.32-0+deb9u1) ...
2021-05-13T04:07:55.604052853Z Starting system message bus: dbus.
2021-05-13T04:07:55.635939281Z Failed to start celerybeat.service: Unknown unit: celerybeat.service
2021-05-13T04:07:55.636724399Z See system logs and 'systemctl status celerybeat.service' for details.
2021-05-13T04:07:55.641978419Z Failed to start celeryworker.service: Unknown unit: celeryworker.service
2021-05-13T04:07:55.642636034Z See system logs and 'systemctl status celeryworker.service' for details.
2021-05-13T04:07:56.094144240Z [2021-05-13 04:07:56 +0000] [785] [INFO] Starting gunicorn 20.0.4
2021-05-13T04:07:56.095453669Z [2021-05-13 04:07:56 +0000] [785] [INFO] Listening at: http://0.0.0.0:8000 (785)
2021-05-13T04:07:56.096002982Z [2021-05-13 04:07:56 +0000] [785] [INFO] Using worker: sync
2021-05-13T04:07:56.099059052Z [2021-05-13 04:07:56 +0000] [788] [INFO] Booting worker with pid: 788
芹菜工人服务
[Unit]
Description=Celery Worker Service
After=network.target
[Service]
Type=simple
User=celery
Group=celery
EnvironmentFile=/etc/conf.d/celery_config
WorkingDirectory=/home/site/wwwroot/celery
ExecStart= /bin/sh -c '${CELERY_BIN} -A ${CELERY_APP} worker \
--pidfile=${CELERYD_PID_FILE} \
--logfile=${CELERYD_LOG_FILE} --loglevel=${CELERYD_LOG_LEVEL}'
Restart=always
[Install]
WantedBy=multi-user.target
芹菜配置文件如下,芹菜配置
# Name of nodes to start
# here we have a single node
CELERYD_NODES="w1"
# or we could have three nodes:
#CELERYD_NODES="w1 w2 w3"
# Absolute or relative path to the 'celery' command:
CELERY_BIN="/home/site/wwwroot/celery"
#CELERY_BIN="/virtualenvs/def/bin/celery"
# App instance to use
# comment out this line if you don't use an app
CELERY_APP="kinduwa"
# or fully qualified:
#CELERY_APP="proj.tasks:app"
# How to call manage.py
CELERYD_MULTI="multi"
# 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.
# - %I will be replaced with the current child process index
# and is important when using the prefork pool to avoid race conditions.
CELERYD_PID_FILE="/var/run/celery/%n.pid"
CELERYD_LOG_FILE="/home/LogFiles/%n%I.log"
CELERYD_LOG_LEVEL="INFO"
# you may wish to add these options for Celery Beat
CELERYBEAT_PID_FILE="/var/run/celery/beat.pid"
CELERYBEAT_LOG_FILE="/home/LogFiles/celery/beat.log"
接下来是我的django应用程序中的my芹菜.py文件
import os
from celery import Celery
from django.conf import settings
# settings.configure()
# if settings.DEBUG:
# setting_file = 'kinduwa.settings'
# else:
setting_file = 'kinduwa.production'
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', setting_file)
app = Celery('kinduwa')
app.config_from_object('kinduwa')
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django app configs.
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print(f'Request: {self.request!r}')
# To start the worker process for development, you must run the following commands in separate terminals
# celery -A kinduwa beat -l INFO
# celery -A kinduwa worker -l INFO
# make sure your local redis server is also running
# type 'celery --help' for more info
最后,这里是我的启动脚本,它在启动我的应用程序服务时实际运行
apt-get update
apt-get install -y systemd
mkdir /var/run/celery/
mkdir /etc/conf.d/
cp celery_config /etc/conf.d/
cp celerybeat.service /etc/systemd/system/
cp celeryworker.service /etc/systemd/system/
chmod 644 /etc/systemd/system/celerybeat.service
chmod 644 /etc/systemd/system/celeryworker.service
/etc/init.d/dbus start
systemctl daemon-reload
systemctl start celerybeat
systemctl start celeryworker
gunicorn --bind=0.0.0.0 --timeout 600 kinduwa.wsgi
我一直想解决的当前错误是“无法启动celerybeat.service:未知单元:celerybeat.service”
我正试图让这个芹菜服务运行,但我遇到了很多麻烦,让他们工作,也导航这个系统一般。我想知道是否有人对我当前的设置有直接的问题,或者知道我可能遗漏了什么或没有做什么。我想我已经看完了所有与此主题相关的堆栈溢出文章。再次感谢您,如果我需要在本文中添加更多信息,请告诉我
此外,如果您有更简单的解决方案或方法来进行此部署,请让我知道