Files
deploy-test/README.md
2026-04-13 01:27:34 +07:00

281 lines
8.3 KiB
Markdown
Raw Permalink 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.

# deploy-test — 测试服务器部署脚本集
> **适用场景**:部署在**有公网 IP 的测试服务器**上。所有服务后端、前端、Docker 基础设施、LiveKit均在本机运行。
>
> 如果你在本机 Mac 开发,请使用 `deploy-local/` 目录。
---
## 两套环境对比
| 项目 | deploy-test本目录| deploy-local/ |
|------|---------------------|----------------|
| 适用机器 | 测试服务器(有公网 IP | 本机 Mac无公网 IP |
| 配置文件 | `.env.deploy-test` | `.env.deploy-local` |
| 运行时目录 | `.deploy-test/` | `.deploy-local/` |
| LiveKit | 本机 Docker 启动,使用公网 IP | 指向本目录服务器的 LiveKit |
| Redis/Kafka/Etcd | 本机 Docker | 本机 Docker |
| 后端服务 | 本机进程 | 本机进程 |
| 前端服务 | 本机进程(可选) | 本机进程 |
---
## 目录结构
```
deploy-test/
├── common.sh # 公共函数库(路径、日志函数)
├── 01-init-env.sh # 步骤1生成 .env.deploy-test 配置模板
├── 02-patch-config.sh # 步骤2将 .env.deploy-test 写入各服务 YAML
├── 03-start-infra.sh # 步骤3启动 Docker 容器Redis/Kafka/Etcd/LiveKit
├── 04-build.sh # 步骤4编译所有后端 Go 服务
├── 05-start.sh # 步骤5启动所有后端服务
├── 06-install-frontend.sh # 步骤6安装前端依赖可选
├── 07-start-frontend.sh # 步骤7启动前端开发服务器可选
├── stop.sh # 停止后端服务
├── stop-infra.sh # 停止 Docker 容器(含 LiveKit
├── stop-frontend.sh # 停止前端服务
├── remove-infra.sh # 删除 Docker 容器及数据(危险!)
├── restart.sh # 重启指定服务(支持 --build
├── status.sh # 查看所有服务状态
├── logs.sh # 查看日志(统一入口)
├── check-conn.sh # 验证 MongoDB / S3 连接
└── setup.sh # 一键完整部署(首次使用)
```
运行时目录(`.deploy-test/`,已加入 `.gitignore`
```
.deploy-test/
├── bin/ # Go 编译产物
├── pids/ # PID 文件
├── logs/ # 后端/前端服务日志
├── docker-data/ # Docker 数据卷
├── docker-logs/ # Docker 容器日志(按日期滚动)
└── script-logs/ # 脚本执行日志(带时间戳)
```
---
## 快速开始
### 首次使用
```bash
# 一键执行(推荐)
./deploy-test/setup.sh
```
### 分步执行
```bash
# 1. 生成配置模板
./deploy-test/01-init-env.sh
# 2. 修改配置(重要:确认 DEPLOY_TEST_IP 等信息正确)
vim .env.deploy-test
# 3. 将配置写入各服务 YAML包括 livekit/livekit.yaml
./deploy-test/02-patch-config.sh
# 4. 启动 Docker 基础设施Redis / Kafka / Etcd / LiveKit
./deploy-test/03-start-infra.sh
# 5. 编译后端服务
./deploy-test/04-build.sh
# 6. 启动后端服务
./deploy-test/05-start.sh
# 7. 安装前端依赖(可选)
./deploy-test/06-install-frontend.sh
# 8. 启动前端开发服务器(可选)
./deploy-test/07-start-frontend.sh
```
---
## 配置文件(`.env.deploy-test`
```bash
# ══ 测试服务器公网 IP ═══════════════════════════════════════════
DEPLOY_TEST_IP=54.116.29.247 # 本机公网 IPLiveKit WebRTC 必需)
# ══ MongoDB ════════════════════════════════════════════════════
MONGO_HOST=47.237.103.4
MONGO_PORT=27017
MONGO_USERNAME=minio_pC5wMB
MONGO_PASSWORD=rI57PJsJhnz_qlRkfnTa0RPT
MONGO_AUTHSOURCE=openim_v3
MONGO_DATABASE=openim_v3
BUILD_MONGO_DATABASE=build
# ══ Amazon S3 ══════════════════════════════════════════════════
OPENIM_AWS_REGION=ap-southeast-1
OPENIM_AWS_BUCKET=im1688
OPENIM_AWS_ACCESS_KEY_ID=xxx
OPENIM_AWS_SECRET_ACCESS_KEY=xxx
BUILD_AWS_REGION=ap-east-1
BUILD_AWS_BUCKET=im-hk-apk
BUILD_AWS_ACCESS_KEY=xxx
BUILD_AWS_SECRET_KEY=xxx
# ══ Docker Redis / Kafka / Etcd ════════════════════════════════
REDIS_PORT=6379
REDIS_PASSWORD=openIM123
KAFKA_PORT=9092
ETCD_PORT=2379
# ══ LiveKit本机 Docker使用公网 IP════════════════════════
LIVEKIT_NODE_IP=54.116.29.247 # 与 DEPLOY_TEST_IP 保持一致
LIVEKIT_URL=ws://127.0.0.1:7880
LIVEKIT_API_KEY=API8462dba2
LIVEKIT_API_SECRET=xxx
# ══ Cloudflare Stream / 腾讯云 RTC ════════════════════════════
CF_ACCOUNT_ID=
CF_API_TOKEN=
TENCENT_SDK_APP_ID=xxx
TENCENT_SDK_SECRET_KEY=xxx
```
---
## 服务地址
### 后端服务
| 服务 | 端口 |
|------|------|
| openim-server | :10002 (HTTP) / :10001 (WS) |
| chat-api | :10008 |
| admin-api | :10009 |
| meetingmsg | :8000 (WS) |
| livecloud | :8080 |
| livestream | :8081 |
| build-server | :8281 |
### 前端开发服务器(可选)
| 项目 | 端口 | 说明 |
|------|------|------|
| pc (Electron) | :7777 | Electron 桌面客户端 |
| meetingh5 | :5188 | 直播观看 H5弹幕+视频) |
| h5 | :3003 | 移动端 H5 |
| cms | :8001 | 后台管理 |
| build-cms | :8002 | 构建管理后台 |
| build-down | :8003 | 下载页 |
> **meetingh5 访问方式**
>
> `02-patch-config.sh` 会自动生成 `meetingh5/.env.local`,设置默认后端地址:
>
> ```
> # 直接访问(使用 .env.local 中的默认后端)
> http://<DEPLOY_TEST_IP>:5188
>
> # 或显式传入 URL 参数(优先级最高)
> http://<DEPLOY_TEST_IP>:5188?ws=ws://<DEPLOY_TEST_IP>:8000&liveApi=http://<DEPLOY_TEST_IP>:8081
> ```
>
> - `ws` → meetingmsg 弹幕 WebSocket `:8000`
> - `liveApi` → livestream 直播间 API `:8081`
### Docker 基础设施
| 服务 | 端口 |
|------|------|
| Redis | :6379 |
| Kafka | :9092 |
| Etcd | :2379 |
| LiveKit | :7880 (API) / :7882 (TCP) / :50000-51000/udp (WebRTC) |
---
## LiveKit 说明
本测试服务器运行本地 LiveKit 容器WebRTC 媒体流通过公网 IP 对外暴露。
```
测试服务器DEPLOY_TEST_IP: 54.116.29.247
├── dev-redis :6379 ←── dev-livekit 通过 host.docker.internal 访问
└── dev-livekit
:7880 → HTTP API后端连接
:7882/tcp+udp → WebRTC fallback
:50000-51000/udp → WebRTC 媒体流(客户端直连公网 IP
```
**防火墙必须开放**7880/tcp、7882/tcp+udp、50000-51000/udp
本机 Macdeploy-local的 LiveKit 连接地址为 `ws://54.116.29.247:7880`,与此保持一致。
---
## 日志体系
```
.deploy-test/
├── script-logs/ ← 每次脚本执行的完整输出(带时间戳,自动去除颜色码)
├── logs/ ← 后端/前端服务进程 stdout+stderr
└── docker-logs/ ← Docker 容器日志(每日一文件)
├── redis/
├── kafka/
├── etcd/
└── livekit/
```
```bash
# 查看所有日志概览
./deploy-test/logs.sh
# 实时跟踪某个服务
./deploy-test/logs.sh openim-server
./deploy-test/logs.sh livekit
./deploy-test/logs.sh cms
# 查看脚本执行历史
./deploy-test/logs.sh scripts
./deploy-test/logs.sh scripts --last # 最新一次完整输出
```
---
## 日常操作
```bash
# 早上开机
./deploy-test/03-start-infra.sh # Docker 容器(含 LiveKit
./deploy-test/05-start.sh # 后端服务
# 查看状态
./deploy-test/status.sh
# 重启单个后端服务
./deploy-test/restart.sh chat-api
./deploy-test/restart.sh chat-api --build # 重编译 + 重启
# 下班关机
./deploy-test/stop.sh # 后端进程
./deploy-test/stop-infra.sh # Docker 容器(含 LiveKit数据保留
```
---
## 故障排查
```bash
# 验证 MongoDB / S3 连接
./deploy-test/check-conn.sh
# 查看 LiveKit 日志WebRTC 不通时)
./deploy-test/logs.sh livekit --last
# 重置 Docker 环境(删除所有数据)
./deploy-test/remove-infra.sh
./deploy-test/02-patch-config.sh
./deploy-test/03-start-infra.sh
```