uwsgi deploys django and uwsgi restart and reset

Prerequisite: build the django framework

Introduction:
Build a full stack of managed service development,
apply to the communication between front-end server (nginx) and back-end server (uWSGI), formulate specifications, etc., so that front-end and back-end servers can smoothly understand what both parties are talking about

1. Install uwsgi
pip install uwsgi #It is best that the pip operating environment is a set of django, otherwise the module will be reported when the service is enabled

2. Deploy uwsgi
a. Create a new directory under the same level directory of the django project, here is the new Uwsgi directory
b.cd Uwsgi
c. Under the newly created Uwsgi directory, create a new uwsgi configuration file vim uwsgi.ini
d. The content of the configuration file is as follows:

# uwsig使用配置文件启动
[uwsgi]
# 项目目录,全路径
chdir=/www/djangoProject_name/
# 指定项目的application
module=djangoProject_name.wsgi:application
# 指定sock的文件路径
socket=/www/djangoProject_name/uwsgi.sock
# 进程个数
workers=5
pidfile=/www/djangoProject_name/Uwsgi/uwsgi.pid
# 指定IP端口
http=0.0.0.0:8000
# 指定静态文
#static-map=/static=/vipkid/airflowTasks/static
# 启动uwsgi的用户名和用户组
uid=root
gid=root
# 启用主进程
master=true
# 自动移除unix Socket和pid文件当服务停止的时候
vacuum=true
# 序列化接受的内容,如果可能的话
thunder-lock=true
# 启用线程
enable-threads=true
# 设置自中断时间
harakiri=30
# 设置缓冲
post-buffering=4096
# 设置日志目录
daemonize=/www/djangoProject_name/Uwsgi/uwsgi.log

Path description:
static-map: if there is no static file, you can comment it out (generally, there is no static file for front-end separation)
module: project file.wsgi.application
In the project file generated by django, there is a directory with the same name as the project. In the wsgi.py file below, you can see that the application
Insert picture description here
log, sock, and pid files are all newly created in the Uwsgi directory at the beginning. Uid
and gid are the users logged in from the command line.

e. After configuring the configuration file uwsgi.ini, save and exit

d. Start uwsgi

uwsgi --ini uwsgi.ini

Successful startup, you can see
[uWSGI] getting INI configuration from uwsgi.ini

3. Restart uwsgi (usually after modifying the files of the django project, uwsgi needs to be restarted)
a. First find the configuration file .ini file of uwsgi, and check the path of .pid in the configuration file.
Insert picture description here
Open the view pid to
Insert picture description here
view the uwsgi process:
Insert picture description here

You can see that the pids of the two are the same

b. Stop uwsgi service:

uwsgi --stop /www/Uwsgi/uwsgi.pid 

c. Start uwsgi service:

uwsgi --ini /www/Uwsgi/uwsgi.cfg

d. Restarting successfully can be seen:
[uWSGI] getting INI configuration from uwsgi.ini

Note: reset uwsgi service

uwsgi --reload uwsgi.pid

e. After the restart is successful, you can follow the above method to go to the pid file and ps to see if the process number is consistent

Guess you like

Origin blog.csdn.net/weixin_43202081/article/details/107785335