From 4b3032996dcf4c9909abe2ebaed19f4af376b492 Mon Sep 17 00:00:00 2001 From: XingQue Date: Tue, 16 Jun 2026 11:25:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BF=BD=E7=95=A5=E5=AF=86=E9=92=A5=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=B9=B6=E6=B7=BB=E5=8A=A0=20Celery=20=E5=B9=BF?= =?UTF-8?q?=E6=92=AD=20Supervisor=20=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + deploy/supervisor/README.md | 36 +++++++++++++++++++++++++ deploy/supervisor/celery-broadcast.conf | 22 +++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 deploy/supervisor/README.md create mode 100644 deploy/supervisor/celery-broadcast.conf diff --git a/.gitignore b/.gitignore index af3e880..8afb961 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ media/ *.log .DS_Store migrations/00*.py +_secrets.py diff --git a/deploy/supervisor/README.md b/deploy/supervisor/README.md new file mode 100644 index 0000000..b4a35c7 --- /dev/null +++ b/deploy/supervisor/README.md @@ -0,0 +1,36 @@ +# Celery 广播 Worker(Supervisor) + +## 服务器安装(一次性) + +```bash +apt install -y supervisor +systemctl enable supervisor && systemctl start supervisor + +cd /opt/1panel/apps/openresty/nginx/www/sites/43.142.166.152.443/django +git pull + +cp deploy/supervisor/celery-broadcast.conf /etc/supervisor/conf.d/celery-broadcast.conf +supervisorctl reread +supervisorctl update +supervisorctl start celery-broadcast +supervisorctl status celery-broadcast +``` + +## 验证 + +```bash +celery -A a_long_dianjing inspect registered | grep dingdan_guangbo +tail -f /var/log/celery-broadcast.log +``` + +## 日常 + +```bash +supervisorctl restart celery-broadcast +``` + +## 注意 + +- 不要用 `nohup` 再起第二个 celery worker,避免抢任务。 +- 仅 `-Q default`,不会跑订单自动结算(order_tasks)。 +- 密钥文件 `app_secrets.py` 只放服务器,不要提交 Git。 diff --git a/deploy/supervisor/celery-broadcast.conf b/deploy/supervisor/celery-broadcast.conf new file mode 100644 index 0000000..3ed379c --- /dev/null +++ b/deploy/supervisor/celery-broadcast.conf @@ -0,0 +1,22 @@ +; Celery 广播 Worker(仅消费 default 队列,跑 dingdan_guangbo) +; 安装:复制到 /etc/supervisor/conf.d/ 后执行 supervisorctl reread && supervisorctl update +; +; cp deploy/supervisor/celery-broadcast.conf /etc/supervisor/conf.d/celery-broadcast.conf +; supervisorctl reread && supervisorctl update && supervisorctl start celery-broadcast + +[program:celery-broadcast] +directory=/opt/1panel/apps/openresty/nginx/www/sites/43.142.166.152.443/django +command=/opt/1panel/apps/openresty/nginx/www/sites/43.142.166.152.443/django/venv/bin/celery -A a_long_dianjing worker -l info -Q default --concurrency=4 --hostname=broadcast@%%h +user=root +autostart=true +autorestart=true +startsecs=10 +startretries=999 +stopwaitsecs=600 +killasgroup=true +stopasgroup=true +stdout_logfile=/var/log/celery-broadcast.log +stderr_logfile=/var/log/celery-broadcast.err.log +stdout_logfile_maxbytes=50MB +stderr_logfile_maxbytes=50MB +environment=DJANGO_SETTINGS_MODULE="a_long_dianjing.settings"