docs: record baota server deployment notes

This commit is contained in:
Codex
2026-07-01 21:49:28 +08:00
parent 084456536f
commit 5004f0d98e
2 changed files with 103 additions and 0 deletions

View File

@@ -435,6 +435,8 @@ npm run test:rls
当前 `tjszsb.com` 已建议按 6 个生产入口使用:`api.tjszsb.com` 反代业务 API`app.tjszsb.com` 承载学生 H5`admin.tjszsb.com` 承载租户后台,`console.tjszsb.com` 承载平台后台,`supabase.tjszsb.com` 反代 Supabase gateway/Auth/Storage/PostgREST`studio.tjszsb.com` 仅限固定 IP/VPN 访问 Supabase Studio。可提交到仓库的部署模板在 `scripts/deploy/`;真实服务器文件建议放在 `/opt/tiku-saas/repo``/srv/tiku-saas/www/*``/etc/tiku-saas/*.env`。Gitea token、数据库密码、支付私钥、短信密钥、对象存储密钥都只允许放服务器本地不允许写入 Git、前端运行时配置或部署脚本。
当前云服务器是 Alibaba Cloud Linux 3 + 宝塔面板环境,宝塔 Nginx 配置在 `/www/server/nginx``/www/server/panel/vhost/nginx`,不是 `/etc/nginx`。H5 静态产物仍发布到 `/srv/tiku-saas/www/*`,宝塔站点根目录通过 `/www/wwwroot/tiku-saas/*` 软链接接入。完整服务器落地记录见 `scripts/deploy/README.md`
1. 准备服务器基础环境:安装 Docker、Node.js 20+、Supabase CLI、Nginx/Caddy、进程管理或容器编排工具拉取本仓库 `main`,以 Gitea 最新提交为准。
2. 启动 Supabase/PostgreSQL执行全部 migrations 和最小 seed确认 `DATABASE_URL` 指向云端数据库。
3.`docs/refactor/postgresql-4c16g-tuning.md` 应用 4 核 16G `shared-host` 起步参数,启用 `pg_stat_statements`,重启 PostgreSQL 后跑 `PG_TUNING_PROFILE=shared-host npm run perf:postgres:evidence -- --strict --json`

View File

@@ -44,6 +44,107 @@ sudo chown -R deploy:deploy /opt/tiku-saas /srv/tiku-saas
sudo chmod 750 /etc/tiku-saas
```
## 宝塔服务器实际落地记录
2026-07-01 首次上云使用的是 Alibaba Cloud Linux 3 + 宝塔面板环境。该服务器的 80/443 已由宝塔 Nginx 接管,主配置不在 `/etc/nginx`,而在:
```text
/www/server/nginx/conf/nginx.conf
/www/server/panel/vhost/nginx/*.conf
```
因此在这类服务器上不要执行 `systemctl start nginx`、不要写 `/etc/nginx/sites-available`,也不要覆盖宝塔生成的站点配置。宝塔 Nginx 的测试和重载命令是:
```bash
/www/server/nginx/sbin/nginx -t -c /www/server/nginx/conf/nginx.conf
/www/server/nginx/sbin/nginx -s reload
```
本次保留企业目录隔离方案:
```text
/opt/tiku-saas/repo Gitea 工作副本
/opt/tiku-saas/bin 服务器部署脚本
/srv/tiku-saas/www H5 发布产物
/srv/tiku-saas/data 运行数据
/srv/tiku-saas/backups 备份
/etc/tiku-saas 真实 env、Gitea token、运行时配置
```
宝塔新增站点时会拦截 `/srv` 作为网站根目录。不要因此把密钥、仓库或运行数据搬进 `/www`。只为 H5 静态站点创建 `/www/wwwroot` 下的软链接:
```bash
mkdir -p /www/wwwroot/tiku-saas
ln -sfn /srv/tiku-saas/www/student /www/wwwroot/tiku-saas/student
ln -sfn /srv/tiku-saas/www/tenant-admin /www/wwwroot/tiku-saas/tenant-admin
ln -sfn /srv/tiku-saas/www/platform-admin /www/wwwroot/tiku-saas/platform-admin
chown -h deploy:deploy /www/wwwroot/tiku-saas/student
chown -h deploy:deploy /www/wwwroot/tiku-saas/tenant-admin
chown -h deploy:deploy /www/wwwroot/tiku-saas/platform-admin
```
宝塔面板中新增三个纯静态站点:
| 域名 | 宝塔根目录 |
| --- | --- |
| `app.tjszsb.com` | `/www/wwwroot/tiku-saas/student` |
| `admin.tjszsb.com` | `/www/wwwroot/tiku-saas/tenant-admin` |
| `console.tjszsb.com` | `/www/wwwroot/tiku-saas/platform-admin` |
每个站点需要保留 H5 history fallback并禁止缓存公开运行时配置
```nginx
location / {
try_files $uri $uri/ /index.html;
}
location = /runtime-config.json {
add_header Cache-Control "no-store" always;
try_files $uri =404;
}
```
当前服务器已经验证过的基础环境:
```text
Node.js: v20.20.2,系统级安装在 /usr/bin/nodedeploy 用户可用
npm: 10.8.2deploy 用户可用
Docker: 26.1.3
Docker Compose: v2.27.0
Nginx: 宝塔 /www/server/nginx/sbin/nginx1.30.1
```
不要使用 root 的 nvm Node 路径作为生产运行时。若 `deploy` 用户看不到 Node/NPM应安装系统级 NodeSource Node.js 20
```bash
curl -fsSL https://rpm.nodesource.com/setup_20.x | bash -
dnf install -y nodejs
sudo -u deploy bash -lc 'command -v node; command -v npm; node -v; npm -v'
```
大陆服务器 `npm ci` 可能访问 npm 官方源超时。本次部署在 `/etc/tiku-saas/deploy.env` 中使用可配置 npm registry 和重试参数:
```bash
NPM_REGISTRY=https://registry.npmmirror.com
NPM_FETCH_RETRIES=5
NPM_FETCH_RETRY_MINTIMEOUT=20000
NPM_FETCH_RETRY_MAXTIMEOUT=120000
NPM_FETCH_TIMEOUT=300000
```
截至 2026-07-01 21:39`sudo -u deploy /opt/tiku-saas/bin/deploy.sh` 已完成:
- Gitea `main` 拉取到 `/opt/tiku-saas/repo`
- `npm ci` 安装依赖。
- `npm run security:repo`,结果 0 finding。
- `node scripts/production-launch-gate-test.js`,通过。
- API 和 worker 构建通过。
- 学生端、租户后台、平台后台三套 Taro H5 构建通过。
- H5 发布到 `/srv/tiku-saas/www/student``/srv/tiku-saas/www/tenant-admin``/srv/tiku-saas/www/platform-admin`
- 三个 `runtime-config.json` 已安装到各自 H5 根目录。
Taro H5 构建存在 webpack asset size warning这是前端包体优化事项不影响当前部署继续进行。后续可做拆包、按需加载和 KaTeX 字体裁剪。
## 首次安装
1. 安装基础组件Docker、Docker Compose、Node.js 20+、Nginx、Certbot、Git、rsync、flock。