【发布时间】:2021-03-15 22:56:31
【问题描述】:
我正在尝试从本地 Redis 容器转换为 Azure 中的托管服务。
我知道我有正确的服务器名称和密钥,因为
redis-cli -h <server-name>.redis.cache.windows.net -p 6379 -a <azure_key>
连接。
我之前在 celery_manager.py 中的本地连接是
app = Celery(broker=redis://redis:6379)
我在启用非 SSL 端口的情况下成功更新了代理。
broker=redis://:<key>@<server-name>.redis.cache.windows.net:6379 per [this question]
我尝试将代理更新为:
broker=redis://:<key>@<server-name>.redis.cache.windows.net:6380
我在 Celery 日志中收到了这个警告:
[2020-12-03 20:54:00,491: WARNING/celery] Secure redis scheme specified (rediss) with no ssl options, defaulting to insecure SSL behaviour.
还有 django-tasks 中的这个异常:
020-12-03 20:54:31,223 - INFO - runworker - Using single-threaded worker.
2020-12-03 20:54:31,224 - INFO - runworker - Running worker against channel layer default (asgi_redis.core.RedisChannelLayer)
2020-12-03 20:54:31,225 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.disconnect, websocket.receive
Traceback (most recent call last):
File "/root/miniconda3/lib/python3.6/site-packages/redis/connection.py", line 185, in _read_from_socket
raise socket.error(SERVER_CLOSED_CONNECTION_ERROR)
OSError: Connection closed by server.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/src/manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/root/miniconda3/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/root/miniconda3/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/root/miniconda3/lib/python3.6/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/root/miniconda3/lib/python3.6/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/root/miniconda3/lib/python3.6/site-packages/channels/management/commands/runworker.py", line 82, in handle
worker.run()
File "/root/miniconda3/lib/python3.6/site-packages/channels/worker.py", line 87, in run
channel, content = self.channel_layer.receive_many(channels, block=True)
File "/root/miniconda3/lib/python3.6/site-packages/asgi_redis/core.py", line 128, in receive_many
result = connection.blpop(list_names, timeout=self.blpop_timeout)
File "/root/miniconda3/lib/python3.6/site-packages/redis/client.py", line 1550, in blpop
return self.execute_command('BLPOP', *keys)
File "/root/miniconda3/lib/python3.6/site-packages/redis/client.py", line 772, in execute_command
connection = pool.get_connection(command_name, **options)
File "/root/miniconda3/lib/python3.6/site-packages/redis/connection.py", line 994, in get_connection
connection.connect()
File "/root/miniconda3/lib/python3.6/site-packages/redis/connection.py", line 502, in connect
self.on_connect()
File "/root/miniconda3/lib/python3.6/site-packages/redis/connection.py", line 570, in on_connect
if nativestr(self.read_response()) != 'OK':
File "/root/miniconda3/lib/python3.6/site-packages/redis/connection.py", line 637, in read_response
response = self._parser.read_response()
File "/root/miniconda3/lib/python3.6/site-packages/redis/connection.py", line 290, in read_response
response = self._buffer.readline()
File "/root/miniconda3/lib/python3.6/site-packages/redis/connection.py", line 224, in readline
self._read_from_socket()
File "/root/miniconda3/lib/python3.6/site-packages/redis/connection.py", line 199, in _read_from_socket
(e.args,))
redis.exceptions.ConnectionError: Error while reading from socket: ('Connection closed by server.',)
我看到this question并添加了broker_use_ssl,但我不确定如何实际使用配置。
这并没有改变任何东西:
app = Celery(broker=redis_url, broker_use_ssl={'cert_reqs':'ssl.CERT_REQUIRED'})
我更正了上面的端口并尝试了@Stanley Gong 的建议,包括从 ssl.CERT_REQUIRED 中删除引号。但结果没有变化。
import ssl
app = Celery(broker=redis_url, broker_use_ssl={'cert_reqs':ssl.CERT_REQUIRED})
【问题讨论】:
-
你试过了吗?
import ssl首先运行:app = Celery(broker=redis_url, broker_use_ssl={'cert_reqs':ssl.CERT_REQUIRED})请注意,如果启用 SSL,则应将端口更改为 6380 -
谢谢@StanleyGong 我尝试了你的建议,但没有成功。