1.安装
bash
pip install gunicorn
which gunicorn #获取到path /usr/local/python3.10/bin/gunicorn
bash
vim /etc/systemd/system/文件名.service
bash
[Unit]
Description=Gunicorn Flask Service
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/opt/fmzhang/python/akamai
ExecStart=/usr/local/python3.10/bin/gunicorn 文件名:app \
-b 0.0.0.0:7901 \
-w 3 \
-k gthread \
--threads 10 \
--timeout 15
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
启动 & 设置开机自启
bash
systemctl daemon-reload
systemctl start 文件名
systemctl enable 文件名
journalctl -u 文件名 -f 看日志
改了.py,重启服务
bash
systemctl restart 文件名
systemctl status 文件名
常见命令
bash
#不中断请求
systemctl reload
# 启动
systemctl start
# 停止
systemctl stop
# 重启(代码更新最常用)
systemctl restart
# 看状态
systemctl status
# 实时看日志(排错神器)
journalctl -u 文件名 -f