-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
59 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
|
||
生产环境中会额外用到:Nginx、uWSGI、PostgreSQL、Memcached。以下流程在 Debian 12 测试过。 | ||
|
||
1. 安装依赖:`apt install python3-venv nginx uwsgi-plugin-python3 postgresql memcached uwsgi`。 | ||
1. 安装依赖:`apt install python3-dev python3-venv nginx postgresql memcached`。 | ||
1. (建议)本地连接 PostgreSQL 无需鉴权:修改 `/etc/postgresql/15/main/pg_hba.conf`,将 `local all all peer` 一行改为 `local all all trust`,然后执行 `systemctl reload postgresql`。 | ||
1. 创建数据库:`su postgres`,`psql`,`create user hackergame; create database hackergame;`, `\c hackergame`, `grant create on schema public to hackergame;`。 | ||
1. 克隆代码:`cd /opt`,`git clone https://github.com/ustclug/hackergame.git`。 | ||
|
@@ -31,10 +31,16 @@ | |
1. Static 目录初始化:`./manage.py collectstatic`。 | ||
1. Google 与 Microsoft app secret 写入数据库:`./manage.py setup`。 | ||
1. 退出 venv:`deactivate`。 | ||
1. uWSGI 配置文件:`cp conf/uwsgi-apps/hackergame.ini /etc/uwsgi/apps-available/hackergame.ini`,`ln -s /etc/uwsgi/apps-available/hackergame.ini /etc/uwsgi/apps-enabled/hackergame.ini`,`systemctl restart uwsgi`。 | ||
- **注意**:编辑 `/etc/logrotate.d/uwsgi`,修改 `rotate 5` 为 `rotate -1`,否则 logrotate 会丢弃较早的 uwsgi 日志 | ||
1. uWSGI 相关配置文件:`cp conf/systemd/[email protected] /etc/systemd/system/`, `cp conf/logrotate/uwsgi /etc/logrotate.d/`, `systemctl daemon-reload`, `systemctl enable --now [email protected]`。 | ||
1. Nginx 配置文件:`cp conf/nginx-sites/hackergame /etc/nginx/sites-available/hackergame`,`ln -s /etc/nginx/sites-available/hackergame /etc/nginx/sites-enabled/hackergame`,`systemctl reload nginx`。 | ||
|
||
### uWSGI 运行情况检查 | ||
|
||
可以使用 [`uwsgitop`](https://uwsgi-docs.readthedocs.io/en/latest/StatsServer.html#uwsgitop) 来查看 uWSGI 运行情况。 | ||
|
||
1. 安装 `pip install uwsgitop`。 | ||
1. 执行 `uwsgitop /run/uwsgi/app/hackergame/stats.socket` 查看。 | ||
|
||
## 运行 | ||
|
||
注:运行所有以 `./manage.py` 开头的命令都需要先进入 venv 和设置环境变量。 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
"/var/log/uwsgi/app/*.log" { | ||
copytruncate | ||
daily | ||
rotate -1 | ||
compress | ||
delaycompress | ||
missingok | ||
notifempty | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
[Unit] | ||
Description=Hackergame Platform (%i) | ||
After=syslog.target | ||
|
||
[Service] | ||
ExecStart=/opt/hackergame/.venv/bin/uwsgi --ini /opt/hackergame/conf/uwsgi-apps/%i.ini --ini /opt/hackergame/conf/uwsgi.ini --set-placeholder appname=%i --daemonize /var/log/uwsgi/app/%i.log | ||
LogsDirectory=uwsgi/app | ||
RuntimeDirectory=uwsgi/app/%i | ||
Restart=always | ||
KillSignal=SIGQUIT | ||
Type=forking | ||
User=www-data | ||
Group=www-data | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[uwsgi] | ||
master = true | ||
workers = 2 | ||
no-orphans = true | ||
pidfile = /run/uwsgi/app/%(appname)/pid | ||
socket = /run/uwsgi/app/%(appname)/socket | ||
chown-socket = www-data | ||
chmod-socket = 660 | ||
log-date = true | ||
uid = www-data | ||
gid = www-data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters