Files
aiot-platform-cloud/docs/technical-overview/09-部署与运维.md

63 lines
2.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.

# Part 9: 部署与运维
> **文档定位**:详细描述系统的自动化构建流程、容器化部署架构及生产环境的运维监控策略。
## 9.1 CI/CD 流水线 (Jenkins Pipeline)
平台采用声明式 Jenkins Pipeline 实现全自动化的持续集成与部署,支持**自动回滚**与**智能并发构建**。
### 9.1.1 流水线阶段概览
1. **Detect Changes**: 智能检测代码变更仅构建受影响的微服务模块Optimization 2
2. **Build Services**:
* **动态并行**:根据构建机 CPU/内存动态计算并行度 (`MAX_PARALLEL_BUILDS`)。
* **Maven 缓存**:挂载 `jenkins-maven-cache` 卷加速依赖下载。
3. **Deploy**:
* **备份**:记录当前运行的镜像 TAG 到 `deployment-state-xxx.txt`
* **部署**:更新镜像并重启服务,支持 `StrictHostKeyChecking=no` 免交互 SSH。
4. **Health Check**: 循环检测 `/actuator/health` 端点,超时或失败则自动触发回滚。
### 9.1.2 自动回滚机制
* **触发条件**:部署失败或健康检查未通过。
* **执行逻辑**
1. 读取 `PREV_IMAGE_TAG`(上一次成功部署的版本)。
2. 执行 `rollbackDeployment`,强制拉取旧镜像并重启。
3. 保留最近 5 个版本的镜像 Tag避免 `dangling` 清理误删。
---
## 9.2 容器化部署架构
基于 **Docker Compose** 的微服务编排方案,适用于私有化交付场景。
### 9.2.1 核心服务清单
| 服务名称 | 端口 | 内存限制 | 依赖关系 |
| :--- | :--- | :--- | :--- |
| `viewsh-gateway` | 48080 | 1536m | Nacos, Redis |
| `viewsh-module-system` | 48081 | 1536m | Gateway, MySQL |
| `viewsh-module-iot` | 48091 | 2560m | RocketMQ, TDengine |
| `viewsh-module-iot-gateway` | 8091/1883 | 2560m | IoT-Server |
### 9.2.2 网络与存储
* **网络**:使用外部网络 `1panel-network` (External),便于与 1Panel 面板管理的 MySQL/Redis 互通。
* **日志挂载**:所有服务日志统一映射至 `app-logs` 卷 (`/app/logs`),便于 Filebeat 采集。
* **环境变量**:通过 `.env` 文件或 Jenkins 注入 `REGISTRY_HOST``IMAGE_TAG`,实现版本控制。
---
## 9.3 监控与运维
### 9.3.1 应用监控 (SkyWalking)
* **探针注入**:在 `Dockerfile` 中集成 SkyWalking Agent。
```dockerfile
JAVA_OPTS="-javaagent:/agent/skywalking-agent.jar -Dskywalking.agent.service_name=aiot-gateway"
```
* **全链路追踪**:通过 `TraceId` 串联 HTTP 请求 -> 网关 ->微服务 -> 数据库/MQ 的完整调用链。
### 9.3.2 日志管理
* **规范**JSON 格式输出,包含 `traceId`、`spanId`。
* **采集**Filebeat -> Logstash -> Elasticsearch -> Kibana (ELK 栈)。
### 9.3.3 告警策略
* **系统级**CPU > 80%, 内存 > 90%, 磁盘 > 85%。
* **业务级**IoT 设备离线率 > 10%, 工单处理超时 > 30min (通过 XXL-JOB 检测)。