django
# 刚写的就不复制粘贴了
http: //blog.csdn .net /xiaobuding007/article/details/79130397
# 列一下目录结构
root@tianshl:~# cd server/
root@tianshl:~/server# tree server
server
├── db.sqlite 3
├── manage.py
└── server
├── __init__.py
├── settings.py
├── urls.py
└── wsgi.py
gunicorn
安装
pip install gunicorn
配置
# 修改django项目的settings.py
INSTALLED_APPS = [
......
'gunicorn' ,
]
运行
root@tianshl :~
root@tianshl :~/server/server
supervisor
安装
pip install supervisor
配置
root@tianshl:~
root@tianshl:~
root@tianshl:~
root@tianshl:~
root@tianshl:~
[unix_http_server]
file =/tmp/supervisor.sock ; the path to the socket file
[supervisord]
logfile =/tmp/supervisord.log ; main log file; default $CWD/supervisord.log
logfile_maxbytes =10MB ; max main logfile bytes b4 rotation; default 50MB
logfile_backups =1 ; # of main logfile backups; 0 means none, default 10
loglevel =info ; log level; default info; others: debug,warn,trace
pidfile =/tmp/supervisord.pid ; supervisord pidfile; default supervisord.pid
nodaemon =false ; start in foreground if true; default false
minfds =1024 ; min. avail startup file descriptors; default 1024
minprocs =200 ; min. avail process descriptors;default 200
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl =unix:///tmp/supervisor.sock ; use a unix:// URL for a unix socket
[include]
files = /etc/supervisor/conf.d/*.conf
root@tianshl:~
内容如下:
[program:server]
directory = /root/server/server/
command = gunicorn --pythonpath /root/server/venv/bin/python3 -w 3 -b 0.0.0.0:80 server.wsgi
autostart = true
startsecs = 5
autorestart = true
startretries = 3
user = root
redirect_stderr = true
stdout_logfile_maxbytes = 10MB
stdout_logfile_backups = 1
stdout_logfile = /root/logs/server.log
启动
supervisord -c /etc/supervisor/supervisor.conf
常用指令
root@tianshl :~
root@tianshl :~
root@tianshl :~
root@tianshl :~
root@tianshl :~