chore(deploy): 删除废弃 nginx 配置并更新部署文档
- 移除 deploy/nginx/(旧前后端分离方案已无引用) - 重写 deploy/README.md 对齐 embed 三种部署方式 - 更新 deploy/kubernetes/README.md(lghost/aiops 镜像与 release 命令)
This commit is contained in:
1 parent
9215cd9b8c
commit
aac15122e5
3 files changed
+92
-139
No files matched your search
+75
-68
@@ -1,107 +1,114 @@
|
|||||||
# AIOps 三种部署方式
|
# AIOps 部署资源
|
||||||
|
|
||||||
|
本目录存放**运维部署清单**(与 `frontend/src/components/deploy/` 应用发布模块无关)。
|
||||||
|
|
||||||
|
## 目录结构
|
||||||
|
|
||||||
|
```
|
||||||
|
deploy/
|
||||||
|
├── kubernetes/ # K8s 清单(./run.sh kubernetes 使用)
|
||||||
|
│ ├── namespace.yaml
|
||||||
|
│ ├── secret.yaml
|
||||||
|
│ ├── configmap.yaml
|
||||||
|
│ ├── mysql.yaml / redis.yaml
|
||||||
|
│ ├── deployment.yaml # embed 单容器,镜像 lghost/aiops:<tag>
|
||||||
|
│ ├── ingress.yaml
|
||||||
|
│ └── README.md
|
||||||
|
└── binary/
|
||||||
|
└── install.sh # 裸机 systemd 安装脚本(可选)
|
||||||
|
```
|
||||||
|
|
||||||
|
> 已移除 `deploy/nginx/`:旧版前后端分离 Nginx 容器方案已废弃,统一 embed 单端口 8080。
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## 部署方式对比
|
## 部署方式对比
|
||||||
|
|
||||||
| 方式 | 适用场景 | 优点 | 缺点 |
|
| 方式 | 命令 | 架构 |
|
||||||
|------|---------|------|------|
|
|------|------|------|
|
||||||
| **Docker Compose(双容器)** | 生产环境 | 前后端分离,nginx 高性能 | 需要 4 个容器 |
|
| **Docker Compose** | `./run.sh docker up` | MySQL + Redis + AIOps embed(3 容器,:8080) |
|
||||||
| **Docker Compose(embed 单容器)** | 快速部署 | 1 个容器搞定,无需 nginx | 静态文件性能稍弱 |
|
| **独立二进制** | `./run.sh build` → `./aiops` | 单文件 embed,项目根目录 |
|
||||||
| **二进制部署** | 无 Docker 环境 | 一个文件 + systemd | 需要自行管理 MySQL/Redis |
|
| **Kubernetes** | `./run.sh kubernetes deploy` | embed 单 Pod + MySQL/Redis StatefulSet |
|
||||||
| **Kubernetes** | K8s 集群 | 标准化编排,弹性伸缩 | 需要 K8s 集群 |
|
| **发版推送** | `./run.sh release v1.5.0` | 二进制 + `lghost/aiops:v1.5.0` 镜像 |
|
||||||
|
|
||||||
|
详见 [docs/deployment.md](../docs/deployment.md)。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 方式一:Docker Compose(双容器,当前默认)
|
## 一、Docker Compose(推荐单机)
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 开发机(75)
|
./run.sh docker up
|
||||||
cd /srv/aiops
|
./run.sh docker up v1.5.0 # 指定版本
|
||||||
make docker-up # 构建并启动
|
|
||||||
|
|
||||||
# 生产机(150)
|
# 访问
|
||||||
cd /srv/aiops && git pull
|
http://localhost:8080
|
||||||
make docker-up
|
http://localhost:8080/version
|
||||||
```
|
```
|
||||||
|
|
||||||
架构:nginx(:80) → backend(:8080) + MySQL + Redis
|
连接外部 MySQL/Redis 时使用根目录 `docker-compose.k8s.yml`。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 方式二:Docker Compose embed 单容器
|
## 二、独立二进制(无 Docker)
|
||||||
|
|
||||||
前端通过 Go `//go:embed` 嵌入后端二进制,不需要 nginx 容器。
|
### 本机构建
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /srv/aiops
|
./run.sh build tag v1.5.0
|
||||||
docker-compose -f docker-compose.embed.yml up -d --build
|
./aiops version
|
||||||
# 或
|
./run.sh binary upgrade # 本机后台启动
|
||||||
make docker-embed
|
|
||||||
```
|
```
|
||||||
|
|
||||||
架构:aiops-app(:80→:8080) + MySQL + Redis(3 个容器)
|
### 远程 Linux 服务器(systemd)
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## 方式三:二进制部署(无 Docker)
|
|
||||||
|
|
||||||
### 在开发机构建
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /srv/aiops
|
# 1. 在 Linux 上构建,或从 CI 拷贝 linux/amd64 二进制
|
||||||
make build-binary
|
scp ./aiops deploy/binary/install.sh root@<server>:/tmp/
|
||||||
# 生成 ./aiops 单二进制(~30MB,前端已嵌入)
|
|
||||||
```
|
|
||||||
|
|
||||||
### 在目标服务器部署
|
# 2. 安装
|
||||||
|
ssh root@<server> 'cd /tmp && bash install.sh install'
|
||||||
|
|
||||||
```bash
|
# 3. 配置并启动
|
||||||
# 传两个文件到目标服务器
|
|
||||||
scp aiops deploy/binary/install.sh root@<target>:/tmp/
|
|
||||||
|
|
||||||
# 安装(自动创建 systemd 服务 + 默认配置)
|
|
||||||
ssh root@<target>
|
|
||||||
cd /tmp && bash install.sh install
|
|
||||||
|
|
||||||
# 修改数据库配置
|
|
||||||
vim /opt/aiops/config.yaml
|
vim /opt/aiops/config.yaml
|
||||||
|
|
||||||
# 启动
|
|
||||||
systemctl start aiops
|
systemctl start aiops
|
||||||
|
systemctl status aiops
|
||||||
```
|
```
|
||||||
|
|
||||||
### 管理
|
> Mac 上 `./run.sh build` 产出 darwin 二进制,不能直接在 Linux 运行。Linux 部署请用 Docker 镜像或在 Linux 上编译。
|
||||||
|
|
||||||
```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 部署
|
## 三、Kubernetes
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd /srv/aiops
|
# 一键部署(构建镜像 + apply 全部清单)
|
||||||
kubectl apply -f deploy/kubernetes/
|
./run.sh kubernetes deploy
|
||||||
|
./run.sh kubernetes deploy v1.5.0
|
||||||
|
|
||||||
|
# 滚动更新 + 推送 Docker Hub
|
||||||
|
./run.sh release v1.5.0
|
||||||
|
./run.sh kubernetes upgrade v1.5.0
|
||||||
|
|
||||||
|
# 运维
|
||||||
|
./run.sh kubernetes status
|
||||||
|
./run.sh kubernetes logs
|
||||||
|
./run.sh kubernetes delete
|
||||||
```
|
```
|
||||||
|
|
||||||
详见 [deploy/kubernetes/README.md](../kubernetes/README.md)
|
清单目录:`deploy/kubernetes/`
|
||||||
|
默认镜像:`lghost/aiops:<tag>`,NodePort `30080`。
|
||||||
|
|
||||||
|
详见 [kubernetes/README.md](./kubernetes/README.md)。
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## 快速选择
|
## 快速选择
|
||||||
|
|
||||||
| 环境 | 推荐方式 |
|
| 环境 | 推荐 |
|
||||||
|------|---------|
|
|------|------|
|
||||||
| 开发测试(75) | 方式一 docker-compose |
|
| 本地开发 | `./run.sh dev` |
|
||||||
| 生产环境(150) | 方式一 docker-compose |
|
| 单机演示/测试 | `./run.sh docker up` |
|
||||||
| 客户现场快速演示 | 方式二 embed 单容器 |
|
| 无 Docker 的 Linux | `./aiops` + `deploy/binary/install.sh` |
|
||||||
| 内网无 Docker 服务器 | 方式三 二进制部署 |
|
| K8s 集群 | `./run.sh kubernetes deploy` |
|
||||||
| K8s 集群 | 方式四 Kubernetes |
|
| 版本发布 | `./run.sh release v1.x` |
|
||||||
+17
-14
@@ -54,46 +54,48 @@ AIOps 平台在 Kubernetes 上的部署清单(Go/Gin 后端 + go:embed 前端
|
|||||||
# 查看日志
|
# 查看日志
|
||||||
./run.sh kubernetes logs
|
./run.sh kubernetes logs
|
||||||
|
|
||||||
# 更新(重新构建镜像 + 滚动更新)
|
# 指定版本滚动更新
|
||||||
./run.sh kubernetes upgrade
|
./run.sh kubernetes upgrade v1.5.0
|
||||||
|
|
||||||
|
# 构建并推送 Docker Hub
|
||||||
|
./run.sh kubernetes push v1.5.0
|
||||||
|
|
||||||
# 清理
|
# 清理
|
||||||
./run.sh kubernetes delete
|
./run.sh kubernetes delete
|
||||||
```
|
```
|
||||||
|
|
||||||
|
镜像仓库:`lghost/aiops:<tag>`(由 `./run.sh release` 或 `kubernetes build` 构建注入版本号)。
|
||||||
|
|
||||||
### 方式二:手动 kubectl
|
### 方式二:手动 kubectl
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
cd deploy/kubernetes
|
cd deploy/kubernetes
|
||||||
|
|
||||||
# 1. 全量部署(文件按序: namespace → secret → configmap → mysql → redis → deployment)
|
|
||||||
kubectl apply -f namespace.yaml
|
kubectl apply -f namespace.yaml
|
||||||
kubectl apply -f secret.yaml
|
kubectl apply -f secret.yaml
|
||||||
kubectl apply -f configmap.yaml
|
kubectl apply -f configmap.yaml
|
||||||
|
kubectl apply -f pvc-aiops-data.yaml
|
||||||
kubectl apply -f mysql.yaml
|
kubectl apply -f mysql.yaml
|
||||||
kubectl apply -f redis.yaml
|
kubectl apply -f redis.yaml
|
||||||
|
|
||||||
# 2. 等待数据库就绪
|
|
||||||
kubectl -n devops rollout status statefulset/mysql
|
kubectl -n devops rollout status statefulset/mysql
|
||||||
kubectl -n devops rollout status statefulset/redis
|
kubectl -n devops rollout status statefulset/redis
|
||||||
|
|
||||||
# 3. 构建镜像(在本地)
|
# 构建镜像(Mac/Linux 均可,按 TARGETARCH 自动选架构)
|
||||||
cd ../..
|
cd ../..
|
||||||
docker build -f Dockerfile.embed -t aiops:embed .
|
./run.sh kubernetes build v1.5.0
|
||||||
|
|
||||||
# 4. 部署应用
|
kubectl apply -f deploy/kubernetes/deployment.yaml
|
||||||
kubectl apply -f deployment.yaml
|
|
||||||
kubectl -n devops rollout status deployment/aiops
|
kubectl -n devops rollout status deployment/aiops
|
||||||
|
|
||||||
# 5. Ingress(按需修改 host)
|
kubectl apply -f deploy/kubernetes/ingress.yaml # 可选
|
||||||
kubectl apply -f ingress.yaml
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 访问
|
## 访问
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# NodePort 方式
|
# NodePort 方式(推荐 /version,无 DB 强依赖)
|
||||||
curl http://<NODE_IP>:30080/health
|
curl http://<NODE_IP>:30080/version
|
||||||
|
|
||||||
# 或配置 Ingress host
|
# 或配置 Ingress host
|
||||||
echo "<INGRESS_IP> aiops.local" | sudo tee -a /etc/hosts
|
echo "<INGRESS_IP> aiops.local" | sudo tee -a /etc/hosts
|
||||||
@@ -115,8 +117,9 @@ kubectl -n devops exec -it deployment/aiops -- bash
|
|||||||
# 进入 MySQL
|
# 进入 MySQL
|
||||||
kubectl -n devops exec -it mysql-0 -- mysql -uaiops -paiops_pass_2026 aiops
|
kubectl -n devops exec -it mysql-0 -- mysql -uaiops -paiops_pass_2026 aiops
|
||||||
|
|
||||||
# 滚动更新(重新构建镜像后)
|
# 滚动更新(换镜像 tag 后)
|
||||||
kubectl -n devops rollout restart deployment/aiops
|
kubectl -n devops set image deployment/aiops aiops=lghost/aiops:v1.5.0 --record
|
||||||
|
kubectl -n devops rollout status deployment/aiops
|
||||||
|
|
||||||
# 查看 PVC
|
# 查看 PVC
|
||||||
kubectl -n devops get pvc
|
kubectl -n devops get pvc
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name _;
|
|
||||||
|
|
||||||
root /usr/share/nginx/html;
|
|
||||||
index index.html;
|
|
||||||
|
|
||||||
gzip on;
|
|
||||||
gzip_vary on;
|
|
||||||
gzip_min_length 1024;
|
|
||||||
gzip_types text/plain text/css application/json application/javascript text/xml application/xml image/svg+xml;
|
|
||||||
|
|
||||||
# HTML 不缓存 — 确保每次加载最新 JS bundle
|
|
||||||
location ~* \.html$ {
|
|
||||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
||||||
add_header Pragma "no-cache";
|
|
||||||
add_header Expires "0";
|
|
||||||
try_files $uri =404;
|
|
||||||
}
|
|
||||||
|
|
||||||
# SPA 前端路由
|
|
||||||
location / {
|
|
||||||
try_files $uri $uri/ /index.html;
|
|
||||||
}
|
|
||||||
|
|
||||||
# 静态资源长缓存(Vite 已做 content hash)
|
|
||||||
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
||||||
expires 1y;
|
|
||||||
add_header Cache-Control "public, immutable";
|
|
||||||
}
|
|
||||||
|
|
||||||
# API 反向代理
|
|
||||||
location /api/ {
|
|
||||||
proxy_pass http://backend:8080;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "upgrade";
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
proxy_read_timeout 86400;
|
|
||||||
}
|
|
||||||
|
|
||||||
# WebSocket 反向代理
|
|
||||||
location /ws {
|
|
||||||
proxy_pass http://backend:8080;
|
|
||||||
proxy_http_version 1.1;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "upgrade";
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
proxy_read_timeout 86400;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user