背景
項目投產前准備步驟
1.新建虛擬環境
2.安裝nginx 配置wsgi
3.啟動應用服務器(建議80/443)端口
4.配置web服務器
5.配置域名
django took too long to shut down and was killed 報錯
症狀:
項目可以正常啟動,每次只能處理一個請求,啟動的服務很容易卡死
attributeerror 'inmemorychannelayer' object has no attribute 'get' 報錯
症狀:
向數據庫新增數據的時候提示 attributeerror 'inmemorychannelayer' object has no attribute 'get'
解決方案
運行環境
python3.7
pip==19.0.3 必須使用這個版本
django==3.1.3
channels==2.2.0 如果pip版本大於20的時候,安裝channels會導致django 自動降級到2.1版本
channels-redis==2.3.3
settings.py 配置
redis 集群配置
其它配置請參照官網:https://channels.readthedocs.io/en/stable/topics/channel_layers.html
CACHES = { 'default': { 'BACKEND': 'django_redis.cache.RedisCache', 'LOCATION': [ "redis://127.0.0.1:6379/0", "redis://127.0.0.1:6380/0", "redis://127.0.0.1:6381/0", ], 'OPTIONS': { 'REDIS_CLIENT_CLASS': 'rediscluster.RedisCluster', 'CONNECTION_POOL_CLASS': 'rediscluster.connection.ClusterConnectionPool', # 'CONNECTION_POOL_KWARGS': { # 'skip_full_coverage_check': True # } } } } CHANNEL_LAYERS = { "default": { "BACKEND": "channels.layers.InMemoryChannelLayer" } }