Celery 提示[ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: [Errno 61

本文详细解析了在使用Celery进行任务调度时,如何正确配置Celery与Redis的集成,包括解决默认连接地址问题及调整相关参数以适应不同需求。

 

这个原因是你在celery.py中的设置问题导致的

import os
from celery import Celery, platforms
from .settings import base


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "pro.settings.development")



# app = Celery('pro')
app = Celery('pro', backend='redis://localhost:6379/1', broker='redis://localhost:6379/0')
app.config_from_object('django.conf:settings')
app.conf.broker_url = 'redis://localhost:6379'
app.conf.broker_transport_options = {'visibility_timeout': 43200}
app.conf.timezone = 'Asia/Shanghai'

app.autodiscover_tasks(lambda: base.INSTALLED_APPS)

platforms.C_FORCE_ROOT = True
app = Celery('ManagementSystem')

 

当这样设置 app时,它默认的连接地址就是  amqp://guest:**@127.0.0.1:5672//

所以我们需要修改一下

app = Celery('pro', backend='redis://localhost:6379/1', broker='redis://localhost:6379/0')

这样就ok了

[2025-08-20 19:43:04,809: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: timed out. Trying again in 2.00 seconds... (1/100) [2025-08-20 19:43:08,252: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672// [2025-08-20 19:43:12,258: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: timed out. Trying again in 2.00 seconds... (1/100) [2025-08-20 19:43:16,268: INFO/MainProcess] mingle: searching for neighbors /usr/local/lib/python3.11/site-packages/click/core.py:1193: UserWarning: The parameter --uid is used more than once. Remove its duplicate as parameters should be unique. parser = self.make_parser(ctx) /usr/local/lib/python3.11/site-packages/click/core.py:1186: UserWarning: The parameter --uid is used more than once. Remove its duplicate as parameters should be unique. self.parse_args(ctx, args) /usr/local/lib/python3.11/site-packages/celery/platforms.py:840: SecurityWarning: You're running the worker with superuser privileges: this is absolutely not recommended! Please specify a different user using the --uid option. User information: uid=0 euid=0 gid=0 egid=0 warnings.warn(SecurityWarning(ROOT_DISCOURAGED.format( -------------- celery@common_worker v5.2.7 (dawn-chorus) --- ***** ----- -- ******* ---- Linux-6.1.0-37-cloud-amd64-x86_64-with-glibc2.36 2025-08-20 19:43:24 - *** --- * --- - ** ---------- [config] - ** ---------- .> app: common:0x7fc58a87d990 - ** ---------- .> transport: amqp://guest:**@localhost:5672// - ** ---------- .> results: disabled:// - *** --- * --- .> concurrency: 2 (prefork) -- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker) --- ***** ----- -------------- [queues] .> common exchange=common(direct) key=common [tasks] . tasks.common.common_tasks.process [2025-08-20 19:43:28,604: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: timed out. Trying again in 2.00 seconds... (1/100) [2025-08-20 19:43:32,253: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672// [2025-08-20 19:43:36,262: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: timed out. Trying again in 2.00 seconds... (1/100) [2025-08-20 19:43:40,260: INFO/MainProcess] mingle: searching for neighbors /usr/local/lib/python3.11/site-packages/click/core.py:1193: UserWarning: The parameter --uid is used more than once. Remove its duplicate as parameters should be unique. parser = self.make_parser(ctx) /usr/local/lib/python3.11/site-packages/click/core.py:1186: UserWarning: The parameter --uid is used more than once. Remove its duplicate as parameters should be unique. self.parse_args(ctx, args) /usr/local/lib/python3.11/site-packages/celery/platforms.py:840: SecurityWarning: You're running the worker with superuser privileges: this is absolutely not recommended! Please specify a different user using the --uid option. User information: uid=0 euid=0 gid=0 egid=0 warnings.warn(SecurityWarning(ROOT_DISCOURAGED.format( -------------- celery@common_worker v5.2.7 (dawn-chorus) --- ***** ----- -- ******* ---- Linux-6.1.0-37-cloud-amd64-x86_64-with-glibc2.36 2025-08-20 19:43:48 - *** --- * --- - ** ---------- [config] - ** ---------- .> app: common:0x7f17a9df4b10 - ** ---------- .> transport: amqp://guest:**@localhost:5672// - ** ---------- .> results: disabled:// - *** --- * --- .> concurrency: 2 (prefork) -- ******* ---- .> task events: OFF (enable -E to monitor tasks in this worker) --- ***** ----- -------------- [queues] .> common exchange=common(direct) key=common [tasks] . tasks.common.common_tasks.process [2025-08-20 19:43:52,581: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: timed out. Trying again in 2.00 seconds... (1/100) [2025-08-20 19:43:56,254: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672// [2025-08-20 19:44:00,265: ERROR/MainProcess] consumer: Cannot connect to amqp://guest:**@127.0.0.1:5672//: timed out. Trying again in 2.00 seconds... (1/100)
08-21
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值