Files
Django/deploy/systemd/README.md

48 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Gunicorn systemd生产环境
修复 sync×9 + 访问日志灌 journal 导致的卡顿。
## 服务器安装(一次性)
```bash
cd /opt/1panel/apps/openresty/nginx/www/sites/43.142.166.152.443/django
git pull origin main
# 备份旧 service若有
cp /etc/systemd/system/gunicorn-dianjing.service /etc/systemd/system/gunicorn-dianjing.service.bak 2>/dev/null || true
cp deploy/systemd/gunicorn-dianjing.service /etc/systemd/system/gunicorn-dianjing.service
pkill -f 'gunicorn.*a_long_dianjing' 2>/dev/null || true
sleep 2
systemctl daemon-reload
systemctl enable gunicorn-dianjing.service
systemctl restart gunicorn-dianjing.service
systemctl status gunicorn-dianjing.service --no-pager | head -12
pgrep -af gthread | head -2
curl -s -o /dev/null -w '8001: HTTP:%{http_code} %{time_total}s\n' http://127.0.0.1:8001/
```
## 1Panel
关闭该站点 **Python 运行环境自动管理**,避免与 systemd 冲突。
## 日常
```bash
systemctl restart gunicorn-dianjing.service
tail -f /tmp/gunicorn-error.log
```
## journal 限制(可选,建议)
```bash
grep -q '^SystemMaxUse=' /etc/systemd/journald.conf \
&& sed -i 's/^SystemMaxUse=.*/SystemMaxUse=200M/' /etc/systemd/journald.conf \
|| echo 'SystemMaxUse=200M' >> /etc/systemd/journald.conf
journalctl --vacuum-size=200M
systemctl restart systemd-journald
```