WIP-CHECKPOINT[auth-refactor]: 固化工程师崩溃前部分成果 + 同树其他未提交WIP(仅源码,不含密钥/二进制)-- 待重激活工程师续作

This commit is contained in:
Simon
2026-07-07 21:52:11 +08:00
parent 242c1967ff
commit fab75760e0
203 changed files with 21504 additions and 3345 deletions
+136
View File
@@ -0,0 +1,136 @@
# 蓝绿部署指南
## 概述
蓝绿部署是一种零停机部署策略,通过维护两套完全相同的运行环境(Blue 和 Green),实现快速切换和回滚。
## 架构
```
┌─────────────────┐
│ Nginx │
│ (流量入口) │
└────────┬────────┘
┌──────────────┴──────────────┐
│ │
▼ ▼
┌────────────────┐ ┌────────────────┐
│ Blue 环境 │ │ Green 环境 │
│ (当前活动) │ │ (待验证) │
│ backend:8000 │ │ backend_green: │
│ │ │ 5002 │
└────────────────┘ └────────────────┘
│ │
└──────────────┬──────────────┘
┌──────────────┴──────────────┐
│ │
▼ ▼
┌────────────────┐ ┌────────────────┐
│ PostgreSQL │ ←──→ │ Redis │
│ (共享) │ │ (共享) │
└────────────────┘ └────────────────┘
```
## 文件说明
| 文件 | 位置 | 说明 |
|------|------|------|
| docker-compose-green.yml | /opt/wecom-it-desk/ | Green 环境配置 |
| switch-blue-green.sh | /opt/wecom-it-desk/ | 切换脚本 |
| nginx.conf | /opt/wecom-it-desk/nginx/ | Nginx 配置(包含 upstream |
## 部署步骤
### 1. 部署 Green 环境
```bash
cd /opt/wecom-it-desk
# 构建并启动 Green 环境
docker-compose -f docker-compose-green.yml up -d
# 验证 Green 环境健康
curl http://localhost:5002/health
```
### 2. 测试 Green 环境
通过端口 5080 访问 Green 环境进行测试:
- H5: http://服务器IP:5080/itdesk/
- 坐席: http://服务器IP:5080/itagent/
- 管理后台: http://服务器IP:5080/itadmin/
### 3. 切换流量到 Green
```bash
# 方法一:使用切换脚本
./switch-blue-green.sh to-green
# 方法二:手动修改 Nginx 配置
sed -i 's/wecom_it_backend:8000/wecom_it_backend_green:8000/' /opt/wecom-it-desk/nginx/nginx.conf
docker restart wecom_it_nginx
```
### 4. 验证切换
```bash
# 检查 Nginx upstream 配置
grep -A1 'upstream backend_api' /opt/wecom-it-desk/nginx/nginx.conf
# 测试 API
curl https://itsupport.servyou.com.cn/api/v1/system/health
```
### 5. 回滚(如有问题)
```bash
# 方法一:使用切换脚本
./switch-blue-green.sh to-blue
# 方法二:手动修改
sed -i 's/wecom_it_backend_green:8000/wecom_it_backend:8000/' /opt/wecom-it-desk/nginx/nginx.conf
docker restart wecom_it_nginx
```
## 端口说明
| 端口 | 服务 | 说明 |
|------|------|------|
| 80/443 | Nginx (Blue) | 生产入口 |
| 5002 | Backend (Green) | Green 后端 API |
| 5080 | Nginx (Green) | Green 测试入口 |
| 5443 | Nginx (Green) | Green HTTPS |
## 注意事项
1. **数据库共享**Blue 和 Green 共用同一个 PostgreSQL 和 Redis
2. **文件上传**:上传的文件保存在挂载目录,不受切换影响
3. **会话影响**:切换后用户可能需要重新登录
4. **WebSocket**:切换后现有 WebSocket 连接会断开
## 快速命令汇总
```bash
# 查看状态
docker ps
# 查看 Green 日志
docker logs wecom_it_backend_green
# 切换到 Green
sed -i 's/wecom_it_backend:8000/wecom_it_backend_green:8000/' /opt/wecom-it-desk/nginx/nginx.conf
docker restart wecom_it_nginx
# 切换回 Blue
sed -i 's/wecom_it_backend_green:8000/wecom_it_backend:8000/' /opt/wecom-it-desk/nginx/nginx.conf
docker restart wecom_it_nginx
# 停止 Green 环境
docker-compose -f docker-compose-green.yml down
```
## 更新日志
- 2026-07-05: 初始版本