gpt4 book ai didi

python - celery 无法连接到远程redis服务器

转载 作者:IT王子 更新时间:2023-10-29 06:00:17 29 4
gpt4 key购买 nike

我在使用 Celery 和 Redis 时遇到问题。出于某种原因,Celery 无法连接到远程 Redis 服务器。我已经阅读了这里的 celery +redis帖子,但还没有找到解决方案。

到目前为止,我已经尝试了以下方法:

  1. redis.conf 中删除绑定(bind)并重新启动服务器
  2. 仔细检查 Celery 是否具有我在 celeryconfig.py 文件中指定的正确设置。
  3. 已验证 BROKER_TRANSPORT 已设置为 'redis'
  4. 使用 celery.broker_connection().as_uri() 方法验证我的配置文件正在加载
  5. 已验证我可以使用 redis-cli -h w2214.area1.company.com:6379 连接到我的 redis 服务器并且 redis ping 命令返回 +PONG
  6. 已验证我可以使用 telnet w2214.area1.company.com 6379
  7. 连接到我的 redis 服务器

但是当我运行我的工作脚本时我仍然遇到连接失败 111 并且我很困惑。这是回溯。我已经替换了下面显示的 URL 中的公司名称,以保护我工作的公司的隐私。

initializing celery
celery.broker_connection() = redis://w2214.area1.company.com:6379/0
BROKER_URL: redis://w2214.area1.company.com:6379/0
CELERY_RESULT_BACKEND: redis://w2214.area1.company.com:6379/0

Traceback (most recent call last):
File "test_worker_standalone.py", line 66, in <module>
result = tasks.get_schema.apply_async((), queue=options.queue)
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/celery/app/task.py", line 474, in apply_async
**options)
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/celery/app/amqp.py", line 250, in publish_task
**kwargs
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/kombu/messaging.py", line 164, in publish
routing_key, mandatory, immediate, exchange, declare)
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/kombu/connection.py", line 470, in _ensured
interval_max)
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/kombu/connection.py", line 396, in ensure_connection
interval_start, interval_step, interval_max, callback)
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/kombu/utils/__init__.py", line 217, in retry_over_time
return fun(*args, **kwargs)
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/kombu/connection.py", line 246, in connect
return self.connection
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/kombu/connection.py", line 761, in connection
self._connection = self._establish_connection()
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/kombu/connection.py", line 720, in _establish_connection
conn = self.transport.establish_connection()
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/kombu/transport/virtual/__init__.py", line 742, in establish_connection
self._avail_channels.append(self.create_channel(self))
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/kombu/transport/virtual/__init__.py", line 725, in create_channel
channel = self.Channel(connection)
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/kombu/transport/redis.py", line 365, in __init__
self.client.info()
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/redis/client.py", line 480, in info
return self.execute_command('INFO')
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/redis/client.py", line 397, in execute_command
connection.send_command(*args)
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/redis/connection.py", line 306, in send_command
self.send_packed_command(self.pack_command(*args))
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/redis/connection.py", line 288, in send_packed_command
self.connect()
File "/nfs/site/home/rodney/projects/mos-env/lib/python2.7/site-packages/redis/connection.py", line 235, in connect
raise ConnectionError(self._error_message(e))

redis.exceptions.ConnectionError: Error 111 connecting localhost:6379. Connection refused.

最后,我使用了以下软件版本:

amqp (1.0.13)
anyjson (0.3.3)
autoenv (1.0.0)
billiard (2.7.3.34)
celery (3.0.24)
celery-with-redis (3.0)
Cython (0.19.1)
distribute (0.7.3)
Django (1.5.1)
kombu (2.5.16)
pbr (0.5.21)
pip (1.4.1)
python-dateutil (2.2)
redis (2.8.0)
setuptools (0.9.8)
six (1.4.1)
stevedore (0.12)
virtualenv (1.10.1)
virtualenv-clone (0.2.4)
virtualenvwrapper (4.1.1)
wsgiref (0.1.2)

而我的redis版本是:Redis server v=2.6.16

我注意到一件有趣的事情,我不确定它是否相关,但回溯显示以下错误,即使我指定了要使用的远程服务器:

Error 111 connecting localhost:6379. Connection refused.

感谢您抽出宝贵时间以及您能给我的任何帮助。

更新:我修改了 redis 库 Connection 对象的 __init__() (redis/connecton.py:211) 并硬编码了我的 redis 服务器的主机名和一切正常。因此,我将继续尝试确定为什么 Connection 对象没有收到我在 Celery 中指定的主机名。

更新 #2:这里是我的 Celery 设置 (celeryconfig.py):

    BROKER_TRANSPORT = 'redis'
CELERY_BROKER_URL = 'redis://w2214.area1.company.com:6379/0'
CELERY_RESULT_BACKEND = 'redis://w2214.area1.company.com:6379/0'

CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'America/Chicago'
CELERY_ENABLE_UTC = True
CELERYD_LOG_COLOR = False
CELERY_IMPORTS = ("tasks", )
CELERY_TASK_RESULT_EXPIRES = 300

我的 redis.conf 设置是默认设置,删除了 'bind' 语句。

最佳答案

如果您在本地主机上遇到此问题,请尝试通过以下方式安装 redis-server

sudo apt install redis-server

然后再尝试连接

关于python - celery 无法连接到远程redis服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19804058/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com