Gunicorn來源於Ruby的unicorn項目,是一個Python WSGI HTTP Server,經過pre-fork worker
模型來管理和維護worker。html
簡而言之就是經過多進程管理應用服務器,實現了對WSGI的功能拓展,好比IO處理模型是同步仍是異步、輪詢機制、請求限制等等。shell
參數配置服務器
咱們知道Gunicorn是一個wsgi服務器,它經過一個主進程控制、管理請求,可是若是這個主進程掛了怎麼辦?這就比如咱們使用nohup
在後臺運行一個應用服務器,可是若是主機重啓或其餘異常致使後臺進程掛了,咱們是不可能及時重啓服務器的。異步
這時Supervisor就頗有用了,Supervisor是一個進程管理軟件,它能夠根據你的要求執行命令行命令,設置log日誌,自動重啓掛掉的進程。命令行
一般是Supervisor與Gunicorn一塊兒使用。rest
# program.conf [program:<program name>] command=/usr/local/bin/gunicorn wsgi --bind <ip:port> --workers <2 * cpucores + 1> --worker-class gevent directory=<program directory> autostart=true autorestart=true stdout_logfile=<stdoutlog directory> stderr_logfile=<stderrlog directory> # supervisor 中文 bug environment=LANG="en_US.utf8", LC_ALL="en_US.UTF-8", LC_LANG="en_US.UTF-8"
# 創建一個軟連接 ln -s -f program.conf /etc/supervisor/conf.d/program.conf # 重啓supervisor以開啓服務 service supervisor restart