一、nginx相关配置
yum安装
yum install nginx
修改配置代理
vim /etc/nginx/nginx.conf #修改server配置
server{
listen 9123; # nginx监听的端口
server_name archery;
client_max_body_size 20M; # 处理Request Entity Too Large
proxy_read_timeout 600s; # 超时时间与Gunicorn超时时间设置一致,主要用于在线查询
location / {
proxy_pass http://127.0.0.1:8000;#程序绑定的地址
proxy_set_header Host $host:9123; # 解决重定向404的问题,和listen端口保持一致,如果是docker则和宿主机映射端口保持一致
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /static {
alias /application/Archery-1.8.0/static; # 此处指向settings.py配置项STATIC_ROOT目录的绝对路径,用于nginx收集静态资源
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
启动
nginx -t
systemctl start nginx.service
systemctl status nginx.service
二、启动MySQL
此处为settings.py文件里的数据库
ps -ef|grep mysql
三、启动inception,goinception,redis
nohup /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf &
nohup ./Inception --defaults-file=inc.cnf &
nohup ./goInception -config=conf.toml &
四、修改supervisord配置
supervisord是一个进程管理工具,通过它来管理gunicorn,它可以很方便的监听、启动、停止、重启一个或多个进程。用Supervisor管理的进程,当一个进程意外被杀死,supervisort监听到进程死后,会自动将它重新拉起,很方便的做到进程自动恢复的功能,不再需要自己写shell脚本来控制。gunicorn是一个高性能的Python WSGI UNIX HTTP Server,通过它来启动我们的python程序。
vim supervisord.conf
1 [unix_http_server]
2 file=supervisor.sock
3
4 [supervisord]
5 logfile=logs/supervisord.log
6 nodaemon=false
7
8 [supervisorctl]
9 serverurl=unix://supervisor.sock
10
11 [rpcinterface:supervisor]
12 supervisor.rpcinterface_factory=supervisor.rpcinterface:make_main_rpcinterface
13
14 [program:archery]
15 command=gunicorn -w 4 -k uvicorn.workers.UvicornWorker -b 127.0.0.1:8000 --timeout 600 archery.asgi:application
16 autorestart=true
17 stopasgroup=true
18 killasgroup=true
19 redirect_stderr=true
20
21 [program:qcluster]
22 command=python manage.py qcluster
23 autorestart=true
24 stopasgroup=true
25 killasgroup=true
26 redirect_stderr=true
运行startup脚本启动
cat startup.sh
#!/bin/bash
# 收集所有的静态文件到STATIC_ROOT
python3 manage.py collectstatic -v0 --noinput
# 启动服务
supervisord -c supervisord.conf
bash startup.sh
查看端口
netstat -tnl
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:9123 0.0.0.0:* LISTEN
tcp6 0 0 :::6669 :::* LISTEN
tcp6 0 0 :::22 :::* LISTEN
tcp6 0 0 :::3356 :::* LISTEN
tcp6 0 0 :::3357 :::* LISTEN
tcp6 0 0 :::4000 :::* LISTEN
五、登陆
访问10。0.0.51:9123
,
生产环境使用该方式进行配置。