Django 频道 2 和 EC2 / Elasticbeanstalk
Posted
技术标签:
【中文标题】Django 频道 2 和 EC2 / Elasticbeanstalk【英文标题】:Django channels 2 and EC2 / Elasticbeanstalk 【发布时间】:2018-08-20 06:12:43 【问题描述】:我的简短问题,如何在 AWS Elasticbeanstalk 上设置 Django-channels v2?下面是冗长且不那么吸引人的问题。 提前谢谢!
我正在尝试使用 Django Channels 2.02 设置一个 elasticbeanstalk 实例。我遵循了这个https://hackernoon.com/setting-up-django-channels-on-aws-elastic-beanstalk-716fd5a49c4a 教程。为频道 1 制作的教程。
Elasticbeanstalk 实例是使用应用程序负载均衡器创建的。 Redis 4.0 实例正在运行 0.0.0.0:6379,由 netstat 确认。自定义 TCP,端口范围:6379,来源:redis 实例上的 0.0.0.0/0。
.ebekstension 中的 alb_listener.config:
option_settings: aws:elbv2:listener:80:
DefaultProcess: http
ListenerEnabled: 'true'
Protocol: HTTP aws:elasticbeanstalk:environment:process:http:
Port: '8000'
Protocol: HTTP
使用命令“Daphne .asgi:application”启动 Daphne 服务器。监听 TCP 地址 0.0.0.0:8000。它返回:
2018-03-12 08:59:30,778 ERROR Exception inside application: [Errno -2] Name or service not known
File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels/consumer.py", line 54, in __call__
await await_many_dispatch([receive, self.channel_receive], self.dispatch)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels/utils.py", line 47, in await_many_dispatch
result = task.result()
File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels_redis/core.py", line 167, in receive
task.result()
File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels_redis/core.py", line 187, in receive_loop
real_channel, message = await self.receive_single(general_channel)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels_redis/core.py", line 224, in receive_single
async with self.connection(index) as connection:
File "/opt/python/run/venv/local/lib/python3.6/site-packages/channels_redis/core.py", line 403, in __aenter__
self.conn = await aioredis.create_redis(**self.kwargs)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/aioredis/commands/__init__.py", line 174, in create_redis
loop=loop)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/aioredis/connection.py", line 107, in create_connection
timeout, loop=loop)
File "/usr/lib64/python3.6/asyncio/tasks.py", line 339, in wait_for
return (yield from fut)
File "/opt/python/run/venv/local/lib/python3.6/site-packages/aioredis/stream.py", line 19, in open_connection
lambda: protocol, host, port, **kwds)
File "/usr/lib64/python3.6/asyncio/base_events.py", line 733, in create_connection
infos = f1.result()
File "/usr/lib64/python3.6/concurrent/futures/thread.py", line 55, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/lib64/python3.6/socket.py", line 743, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
[Errno -2] Name or service not known
Websocket 在浏览器控制台中没有返回错误。
它适用于我的本地运行服务器设置。问题是什么?你能帮我写一个配置脚本,这样我就不需要手动启动 Daphne 了吗?
【问题讨论】:
嘿,您找到解决方案了吗?我经常在 EC2 上遇到这个问题。谢谢 你好@BoCode,对不起,我没有找到答案。 我正在尝试同样的事情!如果你成功了请告诉我 到目前为止,这对我来说还是个谜。找到解决方案后会通知您。 频道 2 不使用 daphne...我正在尝试让频道 2 也在弹性豆茎上工作...但我的错误不同 【参考方案1】:这里回复很晚。
问题在于教程中的config:hosts
URL。从 URL 中删除 redis:// 部分。
例如,
REDIS_PUBLIC_DNS = "YOUR-REDIS-DNS.amazonaws.com"
CHANNEL_LAYERS =
"default":
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG":
"hosts": [(REDIS_PUBLIC_DNS, 6379)],
你可以使用redis-cli检查连接,
redis-cli -h REDIS-PUBLIC-DNS-url ping ;you should expect PONG in response.
【讨论】:
以上是关于Django 频道 2 和 EC2 / Elasticbeanstalk的主要内容,如果未能解决你的问题,请参考以下文章
AWS RDS / EC2:TimeoutError:Knex:获取连接超时。游泳池可能已满
如何在 AWS Elastic Beanstalk 上部署 django 频道 2.x?