feat: 三种部署方式 — embed单容器 + 二进制部署 + K8s

新增三种部署方式(原有 docker-compose 不受影响):

1. Docker embed 单容器 (docker-compose.embed.yml):
   - go:embed 前端嵌入后端二进制
   - 不需要 nginx 容器,3容器→2容器
   - 镜像仅 54.8MB (vs 原来 1.16GB)
   - 用法: make docker-embed

2. 二进制部署 (deploy/binary/):
   - make build-binary 生成单二进制
   - install.sh 自动创建 systemd 服务
   - 适合无 Docker 环境
   - 用法: scp aiops + install.sh, bash install.sh install

3. Kubernetes 部署 (deploy/k8s/):
   - devops 命名空间全套 yaml
   - MySQL StatefulSet + Redis StatefulSet + Backend Deployment
   - ConfigMap + Secret + Ingress
   - 用法: kubectl apply -f deploy/k8s/

核心改动:
- backend/cmd/embed.go: go:embed 前端 + SPA fallback 路由
- backend/Dockerfile.embed: 四阶段构建 (前端→后端embed→agent→runtime)
- Makefile: build-binary + docker-embed 目标
- deploy/README.md: 四种部署方式对比文档
This commit is contained in:
Logan authored and attacker committed 2026-06-21 14:20:29 +08:00
1 parent 24f955832e
commit 4631b02f13
15 files changed
+1218 -3

No files matched your search

+107
View File
@@ -0,0 +1,107 @@
# AIOps 三种部署方式
## 部署方式对比
| 方式 | 适用场景 | 优点 | 缺点 |
|------|---------|------|------|
| **Docker Compose(双容器)** | 生产环境 | 前后端分离,nginx 高性能 | 需要 4 个容器 |
| **Docker Compose(embed 单容器)** | 快速部署 | 1 个容器搞定,无需 nginx | 静态文件性能稍弱 |
| **二进制部署** | 无 Docker 环境 | 一个文件 + systemd | 需要自行管理 MySQL/Redis |
| **Kubernetes** | K8s 集群 | 标准化编排,弹性伸缩 | 需要 K8s 集群 |
---
## 方式一:Docker Compose(双容器,当前默认)
```bash
# 开发机(75)
cd /srv/aiops
make docker-up # 构建并启动
# 生产机(150)
cd /srv/aiops && git pull
make docker-up
```
架构:nginx(:80) → backend(:8080) + MySQL + Redis
---
## 方式二:Docker Compose embed 单容器
前端通过 Go `//go:embed` 嵌入后端二进制,不需要 nginx 容器。
```bash
cd /srv/aiops
docker-compose -f docker-compose.embed.yml up -d --build
# 或
make docker-embed
```
架构:aiops-app(:80→:8080) + MySQL + Redis(3 个容器)
---
## 方式三:二进制部署(无 Docker)
### 在开发机构建
```bash
cd /srv/aiops
make build-binary
# 生成 ./aiops 单二进制(~30MB,前端已嵌入)
```
### 在目标服务器部署
```bash
# 传两个文件到目标服务器
scp aiops deploy/binary/install.sh root@<target>:/tmp/
# 安装(自动创建 systemd 服务 + 默认配置)
ssh root@<target>
cd /tmp && bash install.sh install
# 修改数据库配置
vim /opt/aiops/config.yaml
# 启动
systemctl start aiops
```
### 管理
```bash
systemctl start aiops # 启动
systemctl stop aiops # 停止
systemctl restart aiops # 重启
systemctl status aiops # 状态
journalctl -u aiops -f # 日志
```
架构:aiops 二进制 + systemd(端口 8080 同时服务 API 和前端)
> 前提:目标服务器需已安装 MySQL 8.0 + Redis 7
---
## 方式四:Kubernetes 部署
```bash
cd /srv/aiops
kubectl apply -f deploy/k8s/
```
详见 [deploy/k8s/README.md](../k8s/README.md)
---
## 快速选择
| 环境 | 推荐方式 |
|------|---------|
| 开发测试(75) | 方式一 docker-compose |
| 生产环境(150) | 方式一 docker-compose |
| 客户现场快速演示 | 方式二 embed 单容器 |
| 内网无 Docker 服务器 | 方式三 二进制部署 |
| K8s 集群 | 方式四 Kubernetes |