1.安裝
pip3 install uwsgi
2.新建配置文件
mkdir /etc/uwsgi
vim /etc/uwsgi/uwsgi.ini
3.往配置文件中寫入內容
[uwsgi]
uid = root
gid = root
socket = 127.0.0.1:8111 # 項目啟動的ip:端口
master = true //啟動主進程
vhost = true //多站模式
no-site = true //多站模式時不設置⼊⼝模塊和⽂件
workers = 2 // 進程數
reload-mercy = 10 //平滑的重啟
vacuum = true //退出、重啟時清理⽂件
max-requests = 1000 //開啟10000個進程后, ⾃動respawn下
limit-as = 512 // 將進程的總內存量控制在512M
buffer-size = 30000
pidfile = /var/run/uwsgi8111.pid //pid⽂件,⽤於下⾯的腳本啟動、停⽌該進程
daemonize = /var/log/uwsgi8111.log
pythonpath = /root/jiangsqobj/lib/python3.6/site-packages // 有虛擬環境就添加虛擬環境 沒有就添加python安裝路徑
4.啟動
方法一
1.啟動
uwsgi --ini /etc/uwsgi/uwsgi.ini
2.測試是否啟動
netstat -ntpl
3.查看進程號
cat /var/run/uwsgi8111.pid
4.殺死進程
kill -9 81392
killall -9 uwsgi
方法二
1.新建配置文件
vim /etc/init.d/uwsgi
2.寫入啟動腳本
#!/bin/sh
DESC="uwsgi daemon"
NAME=uwsgi
DAEMON=/usr/local/bin/uwsgi
CONFIGFILE=/etc/uwsgi/${NAME}.ini
PIDFILE=/var/run/$NAME9090.pid
SCRIPTNAME=/etc/init.d/$NAME
FIFOFILE=/tmp/uwsgififo
set -e
[ -x "$DAEMON" ] || exit 0
do_start() {
if [ ! -f $PIDFILE ];then
$DAEMON $CONFIGFILE || echo -n "uwsgi running"
else
echo "The PID is exist..."
fi
}
do_stop() {
if [ -f $PIDFILE ];then
$DAEMON --stop $PIDFILE || echo -n "uwsgi not running"
rm -f $PIDFILE
echo "$DAEMON STOPED."
else
echo "The $PIDFILE doesn't found"
fi
}
do_reload() {
if [ -p $FIFOFILE ];then
echo w > $FIFOFILE
else
$DAEMON --touch-workers-reload $PIDFILE || echo -n "uwsgi
can't reload"
fi
}
do_status() {
ps aux|grep $DAEMON
}
case "$1" in
status)
echo -en "Status $NAME: \n"
do_status
;;
start)
echo -en "Starting $NAME: \n"
do_start
;;
stop)
echo -en "Stopping $NAME: \n"
do_stop
;;
reload|graceful)
echo -en "Reloading $NAME: \n"
do_reload
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|reload}" >&2
exit 3
;;
esac
exit 0
3.啟動
/etc/init.d/uwsgi start
4.查看
netstat -ntpl
/etc/init.d/uwsgi status
5.關閉
/etc/init.d/uwsgi stop