Django 使用gunicorn 和 supervisord部署

安装依赖

pip3 install gunicorn supervisor

项目部署目录为/code,有2个服务 一个为web服务,一个为任务服务

生成配置文件

echo_supervisord_conf > /code/supervisord.conf

/code/supervisord.conf配置

[program:ccu]
command=/code/py/bin/gunicorn --chdir /code/project --pythonpath /code/py/ -k gthread --thread 40 --max-requests 4096 --max-requests-jitter 512 -w 4 -b0.0.0.0:8000 project.wsgi
directory=/code/project
startsecs=0
stopwaitsecs=0
autostart=true
autorestart=true

[program:ccu_cron]
command=/code/py/bin/python3 /code/project/run.py
directory=/code/project
startsecs=0
stopwaitsecs=0
autostart=true
autorestart=true

gunicorn 参数说明

name Value
chdir 加载应用程序之前将chdir目录指定到指定目录
pythonpath 路径加到python path
max-requests 工作将处理的最大请求数(静态数值)
max-requests-jitter 工作将处理的最大请求数(动态数值)randint(0, max_requests_jitter)
-w 表示开启多少个worker
project.wsgi project/wsgi.py 文件

supervisorctl 基本命令

supervisord -c /etc/supervisord.conf 启动服务
supervisorctl -c /code/supervisord.conf status              查看状态
supervisorctl -c /code/supervisord.conf reload              重新载入配置文件
supervisorctl -c /code/supervisord.conf start [all]|[x]     启动所有/指定的程序进程
supervisorctl -c /code/supervisord.conf stop [all]|[x]      停止所有/指定的程序进程
posted @ 2019-08-14 11:38  紫系流月  阅读(940)  评论(0编辑  收藏  举报