简体   繁体   English

错误 111 连接被拒绝(Python、celery、redis)

[英]Error 111 connection refused (Python, celery, redis)

I tried to get all the active/scheduled/reserved tasks in redis:我试图在 redis 中获取所有活动/计划/保留的任务:

from celery.task.control import inspect
inspect_obj = inspect()
inspect_obj.active()
inspect_obj.scheduled()
inspect_obj.reserved()

But was greeted with a list of errors as follows: My virtual environment ==> HubblerAPI.但是遇到了如下错误列表:我的虚拟环境 ==> HubblerAPI。 Iam using this from the ec2 console我从 ec2 控制台使用这个

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ec2-user/HubblerAPI/local/lib/python3.4/site-
packages/celery/app/control.py", line 81, in active
return self._request('dump_active', safe=safe)
File "/home/ec2-user/HubblerAPI/local/lib/python3.4/site-
packages/celery/app/control.py", line 71, in _request
timeout=self.timeout, reply=True,
File "/home/ec2-user/HubblerAPI/local/lib/python3.4/site-
packages/celery/app/control.py", line 316, in broadcast
limit, callback, channel=channel,
File "/home/ec2-user/HubblerAPI/local/lib/python3.4/site-
packages/kombu/pidbox.py", line 283, in _broadcast
chan = channel or self.connection.default_channel
File "/home/ec2-user/HubblerAPI/local/lib/python3.4/site-
packages/kombu/connection.py", line 771, in default_channel
self.connection
File "/home/ec2-user/HubblerAPI/local/lib/python3.4/site-
packages/kombu/connection.py", line 756, in connection
self._connection = self._establish_connection()
File "/home/ec2-user/HubblerAPI/local/lib/python3.4/site-
packages/kombu/connection.py", line 711, in _establish_connection
conn = self.transport.establish_connection()
File "/home/ec2-user/HubblerAPI/local/lib/python3.4/site-
packages/kombu/transport/pyamqp.py", line 116, in establish_connection
conn = self.Connection(**opts)
File "/home/ec2-user/HubblerAPI/local/lib/python3.4/site-
packages/amqp/connection.py", line 165, in __init__
self.transport = self.Transport(host, connect_timeout, ssl)
File "/home/ec2-user/HubblerAPI/local/lib/python3.4/site-
packages/amqp/connection.py", line 186, in Transport
return create_transport(host, connect_timeout, ssl)
File "/home/ec2-user/HubblerAPI/local/lib/python3.4/site-
packages/amqp/transport.py", line 299, in create_transport
return TCPTransport(host, connect_timeout)
File "/home/ec2-user/HubblerAPI/local/lib/python3.4/site-
packages/amqp/transport.py", line 95, in __init__
raise socket.error(last_err)
**OSError: [Errno 111] Connection refused**

My celery config file is as follows:我的芹菜配置文件如下:

BROKER_TRANSPORT = 'redis'
BROKER_TRANSPORT_OPTIONS = {
    'queue_name_prefix': 'dev-',
    'wait_time_seconds': 10,
    'polling_interval': 30,
    # The polling interval decides the number of seconds to sleep 
      between unsuccessful polls
    'visibility_timeout': 3600 * 5,
    # If a task is not acknowledged within the visibility_timeout, the 
      task will be redelivered to another worker and executed.
}
CELERY_MESSAGES_DB = 6
BROKER_URL = "redis://%s:%s/%s" % (AWS_REDIS_ENDPOINT, AWS_REDIS_PORT, 
              CELERY_MESSAGES_DB)

What am i doing wrong here as the error log suggests that its not using the redis broker.我在这里做错了什么,因为错误日志表明它没有使用 redis 代理。

Looks like your python code doesn't recognize your configs since it is attempting to use RabbitMQ's ampq protocol instead of the configured broker.看起来您的 python 代码无法识别您的配置,因为它试图使用 RabbitMQ 的 ampq 协议而不是配置的代理。

I suggest the following我建议以下

http://docs.celeryproject.org/en/latest/getting-started/brokers/redis.html http://docs.celeryproject.org/en/latest/getting-started/brokers/redis.html

Your configs look similar to Django configs for Celery yet it doesn't seem you are using Celery with Django.您的配置看起来类似于 Celery 的 Django 配置,但您似乎并未将 Celery 与 Django 一起使用。

http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html#using-celery-with-django http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html#using-celery-with-django

The issue is using "BROKER_URL" instead of "CELERY_BROKER_URL" in settings.py.问题是在 settings.py 中使用“BROKER_URL”而不是“CELERY_BROKER_URL”。 Celery wasn't finding the URL and was defaulting to the rabbitmq port instead of the redis port. Celery 没有找到 URL,并且默认使用 rabbitmq 端口而不是 redis 端口。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM