-
通过docker创建容器
docker run -i -t -d --name=‘test’ -p 80:80 -p 81:81 -v /www:/www 8000/test /bin/bash (此处把已经写好的django项目放进www目录中。如若拖进失败则执行文件夹权限命令,如:chmod 777 /www)
docker attach test
pip3 install -i https://pypi.douban.com/simple django==2.0.7 -
pip3 install -i https://pypi.douban.com/simple gunicorn
-
pip3 install -i https://pypi.douban.com/simple greenlet
-
pip3 install -i https://pypi.douban.com/simple eventlet
-
pip3 install -i https://pypi.douban.com/simple gevent
8.apt-get install -y apache2-utils -
apt-get install -y nginx
-
cd www/MyServer/ 测试gunicorn
gunicorn -w 3 -b 0.0.0.0:80 MyServer.wsgi:application
11 vi MyServer/gunicorn.conf.py
import os
from multiprocessing import cpu_count
bind = “127.0.0.1:8888”
daemon = True
workers = 2cpu_count() + 1
threads = 2
worker_class = “gevent”
forworded_allow_ips = '’
keepalive = 6
timeout = 65
graceful_timeout = 10
worker_connections = 65535
pidfile = ‘/www/MyServer/gunicorn.pid’
errorlog = ‘/www/MyServer/gunicorn.error.log’
accesslog = ‘/www/MyServer/gunicorn.access.log’
loglevel = ‘info’
proc_name = ‘MyServer’ -
vi /etc/nginx/nginx.conf
worker_connections 65535 -
vi /etc/nginx/conf.d/myserver.conf
upstream app_server {
server 127.0.0.1:8888;
}
server {
listen 80;
server_name 0.0.0.0;
access_log /www/MyServer/logs/host.access.log;
location = /favicon.ico {
empty_gif;
access_log off;
}
location /static/ {
root /www/MyServer/;
expires 30d;
access_log off;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
14.nginx -t 测试语法错误
15.mkdir -p /www/MyServer/logs
16.service nginx start
17. 打开浏览器验证 192.168.99.100/index
welcome to Nginx
18. vi /etc/nginx/sites-enabled/default
server {
listen 81 default_server;
listen [::]:81 default_server;
}
19.service nginx restart
20. apt-get install -y supervisor
21. rm /etc/supervisor/supervisord.conf
22. echo_supervisord_conf > /etc/supervisor/supervisord.conf
23. vi /etc/supervisor/supervisord.conf
/tmp/supervisor.sock --> /var/run/supervisor.sock
/tmp/supervisord.log --> /var/log/supervisord.log
/tmp/supervisord.pid --> /var/run/supervisord.pid
unix:///tmp/supervisor.sock --> unix:///var/run/supervisor.sock
[include] 去掉前面的分号
files = relative/directory/.ini
去掉前面的分号并修改为
files = /etc/supervisor/conf.d/.conf
24. chmod -R 777 /var/run
25. chmod -R 777 /var/log
26. vi /etc/supervisor/conf.d/myserver.conf
[program:myserver]
command = gunicorn -c /www/MyServer/MyServer/gunicorn.conf.py MyServer.wsgi:application
user = root
autostart=true ;
autorestart=true ;
startretries=10 ;
redirect_stderr = true
stdout_logfile = /www/MyServer/logs/robot.log
stderr_logfile=/www/MyServer/logs/err.log
27.supervisorctl shutdown
28. cd /www/MyServer
29. supervisord -c /etc/supervisor/supervisord.conf
30.验证
ps -ax
kill -9 某一个gunicorn进程id
ps -ax
即便强制杀死gunicorn,supervisor依然会自动重启