芹菜无法连接到远程 Redis 服务器



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

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

  1. redis.conf中删除绑定并重新启动服务器
  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 连接到我的 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:根据要求,这是我的芹菜设置(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'语句的默认设置。

如果您在使用本地主机时遇到此问题,请尝试通过

sudo apt install redis-server

然后再次尝试连接

相关内容

  • 没有找到相关文章

最新更新