Files
aiops/docs/deployment.md
T
attacker 97c4207ff8 refactor: 标准化项目结构 frontend/ + backend/ + SQLite + run.sh
- 目录重构: app/ -> frontend/,与 backend/ 并列
- 数据库: 默认 SQLite(零配置),修复 DSN() bug
- run.sh: 一键启动前后端,支持 start/stop/restart/status
- Makefile: install/dev/build/lint/clean 快捷命令
- vite.config.ts: 配置 dev server 端口 5173 + API 代理到 8080
- config.yaml: SQLite 默认配置,开箱即用
- docs/: 完整开发文档(项目结构/API/数据库/规范/部署)
- 修复: GORM foreign key 关联声明
- 修复: go get gorm.io/driver/sqlite 依赖
2026-06-13 23:34:23 +08:00

140 lines
2.4 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.
# 部署指南
## 开发环境
参见 [快速开始](./quick-start.md)。
```bash
./run.sh start
```
## 生产构建
### 后端编译
```bash
cd backend
CGO_ENABLED=1 go build -ldflags="-s -w" -o aiops-server cmd/main.go
```
### 前端构建
```bash
cd app
npm run build # 输出到 dist/
```
### 使用 Makefile
```bash
make build # 同时构建前后端
```
## Docker 部署
### Dockerfile
后端已有 `backend/Dockerfile`,可基于此构建镜像。
```bash
cd backend
docker build -t aiops-server .
```
### docker-compose
```bash
cd backend
docker-compose up -d
```
## Nginx 反向代理
前端构建后部署到 Nginx,后端 API 反向代理:
```nginx
server {
listen 80;
server_name aiops.example.com;
# 前端静态文件
location / {
root /usr/share/nginx/html;
try_files $uri $uri/ /index.html;
}
# 后端 API 代理
location /api/ {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
# WebSocket 代理
location /ws/ {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
```
参考配置文件:`backend/nginx.conf`
## 系统服务(systemd)
创建 `/etc/systemd/system/aiops.service`:
```ini
[Unit]
Description=EZOps AIOps Server
After=network.target
[Service]
Type=simple
User=www-data
WorkingDirectory=/opt/aiops
ExecStart=/opt/aiops/aiops-server
Restart=always
RestartSec=5
Environment=GIN_MODE=release
[Install]
WantedBy=multi-user.target
```
```bash
systemctl enable aiops
systemctl start aiops
```
## 环境变量
| 变量 | 默认值 | 说明 |
|------|--------|------|
| PORT | 8080 | 后端端口 |
| GIN_MODE | debug | Gin 模式(release/debug) |
| GOPROXY | - | Go 模块代理 |
## 生产配置建议
1. **数据库**: 生产环境使用 MySQL/PostgreSQL,不要用 SQLite
2. **JWT Secret**: 更换为高强度随机字符串
3. **CORS**: 生产环境配置允许的具体域名,不要用 `*`
4. **HTTPS**: 配置 TLS 证书
5. **日志**: 使用文件日志 + 日志轮转
6. **备份**: 定期备份数据库
## 健康检查
```bash
# 检查后端是否正常
curl http://localhost:8080/health
# {"status":"ok"}
# 检查版本
curl http://localhost:8080/version
# {"version":"dev","build_time":"...","git_commit":"..."}
```