Files
iotlcm/docs/deploy/optional.md
T
Dai0814 e43640d0fe docs: 部署手册改为平台部署,替换原文档站自身部署说明
原 /deploy/ 内容是文档站自身(VitePress/Node/nginx)的部署说明,
与用户所需的「IotLCM 平台部署手册」不符。

改为基于 iotlcm-public/iotlcm-deploy 部署仓的平台部署手册:
- 部署概览:部署构成、三步流程、端口规划、关键约束
- 环境准备:硬件分档、系统与 Docker 版本、镜像仓库、防火墙、可选外部依赖
- 配置说明:.env 必填 8 项与可选 4 项、10 份应用配置逐项说明
- 启动与验证:首次初始化流程、7 步验证清单、首次登录必做项
- 可选服务:运营商挡板 onelink-mock、飞书 bot、反向代理(含 HTTPS)
- 升级与备份:版本固定、升级回滚、备份与恢复、日志清理、监控指标
- 故障排查:启动/功能/性能/网络四类共 20 个问题

删除原 6 页(docker-nginx / path-prefix / static-hosting / local-dev /
offline / faq),侧边栏同步改为「部署手册 + 运维」两组。
2026-10-28 14:00:58 +08:00

172 lines
3.9 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.
---
title: 可选服务
description: 运营商接口挡板、飞书通知与反向代理
outline: deep
---
# 可选服务
以下服务默认不启动,按需通过 profile 开启。
## 运营商接口挡板
### 用途
模拟中国移动 OneLink 接口。**没有真实运营商环境时,靠它跑通完整链路**:
```text
admin-svr → worker-svr → upstream-chan → onelink-mock
```
不开挡板时,`upstream-chan` 会尝试连接真实运营商接口。没有凭据则批次执行、状态同步、流量查询全部失败。
### 启动
```bash
docker compose --profile with-mock up -d
```
验证:
```bash
curl -s -o /dev/null -w '%{http_code}\n' http://127.0.0.1:8080/api.json
```
预期 `200`。接口文档在 `http://127.0.0.1:8080/swagger`。
### 配置
挡板自身无需配置,数据存在容器内 SQLite(`./data/mock/onelink_mock.db`)。
`upstream-chan` 配置中已预置指向:
```yaml
dependencies:
sim_yd_mock_v5:
url: "http://onelink-mock:8080/v5/"
```
数据库种子脚本 `schema/08-seed-mock-channel.sql` 已插入 Mock 通道(`channel_yd_mock`)并指向该地址。
`app-server` 若使用挡板,把 `upstream.onelinkMock.enabled` 改为 `true`,`baseUrl` 填 `http://onelink-mock:8080/v5`。
### 造测试卡
挡板支持生成模拟卡片,用于验证查询、开停复机、续费流程。接口见挡板 Swagger 页面。
### 切换到真实运营商
1. 删除或注释 `upstream-chan` 配置中的 `sim_yd_mock_v5` 段
2. 在平台「通道管理」录入真实运营商通道(AppKey、AppSecret、接口地址)
3. 停用 Mock 通道,避免卡片误挂
```bash
docker compose --profile with-mock stop onelink-mock
```
## 飞书通知
### 用途
把全量同步完成、失败告警等运维事件推送到飞书群。
### 准备
在飞书开放平台创建自建应用,获取 `appId`、`appSecret` 与目标群的 `chatId`,填入 `.env`:
```bash
FEISHU_APP_ID=cli_xxxxxxxx
FEISHU_APP_SECRET=xxxxxxxx
FEISHU_CHAT_ID=oc_xxxxxxxx
```
### 启动
```bash
docker compose --profile with-bot up -d
```
bot 读取 `worker-svr` 生成的全量同步归档(`./data/logs/worker-svr/full-sync`),该目录有数据后才会产生通知。
## 反向代理
### 用途
把分散在各端口的服务统一到域名下按路径分流。宿主机已有 nginx 或面板时不需要。
### 域名与分流
编辑 `config/nginx/iotlcm.conf`:
| 域名 | 分流到 |
| --- | --- |
| `api.your-domain.example.com` | openapi(`/openapi/v3/`、`/route/open/`) |
| `admin.your-domain.example.com` | 管理端前端 + `/docs/` 文档站 |
| `app.your-domain.example.com` | 小程序前端 + `/app/api/v1/` 后端 |
### 启动
```bash
docker compose --profile with-nginx up -d
```
默认监听 80,改 `.env` 的 `NGINX_HTTP_PORT` 可调整。
### 使用宿主机 nginx
不启动容器时,把 `config/nginx/iotlcm.conf` 中的 `upstream` 与 `location` 段落复制到宿主机 nginx 配置。
::: warning 宿主机 nginx 无法解析容器名
需要把 `upstream` 里的服务名换成宿主机地址:
```nginx
# 容器内写法
server admin-svr:8008;
# 宿主机写法
server 127.0.0.1:8008;
```
:::
### 启用 HTTPS
自带配置未包含证书,启用需三步:
1. 准备证书,放入 `data/certs/`
2. 在 server 块加入 SSL 配置:
```nginx
listen 443 ssl;
ssl_certificate /etc/nginx/certs/fullchain.pem;
ssl_certificate_key /etc/nginx/certs/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
```
3. 给 nginx 服务增加证书目录挂载,并加 80 → 443 跳转:
```yaml
volumes:
- ./data/certs:/etc/nginx/certs:ro
```
```nginx
server {
listen 80;
server_name admin.your-domain.example.com;
return 301 https://$host$request_uri;
}
```
## 组合启动
多个 profile 可同时启用:
```bash
docker compose --profile with-mock --profile with-nginx up -d
```
查看指定 profile 下的服务清单:
```bash
docker compose --profile with-mock config --services
```