Files
aiops/docs/deployment.md
T

2.4 KiB
Raw Blame History

部署指南

开发环境

参见 快速开始。

./run.sh start

生产构建

后端编译

cd backend
CGO_ENABLED=1 go build -ldflags="-s -w" -o aiops-server cmd/main.go

前端构建

cd app
npm run build  # 输出到 dist/

使用 Makefile

make build  # 同时构建前后端

Docker 部署

Dockerfile

后端已有 backend/Dockerfile,可基于此构建镜像。

cd backend
docker build -t aiops-server .

docker-compose

cd backend
docker-compose up -d

Nginx 反向代理

前端构建后部署到 Nginx,后端 API 反向代理:

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:

[Unit]
Description=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
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. 备份: 定期备份数据库

健康检查

# 检查后端是否正常
curl http://localhost:8080/health
# {"status":"ok"}

# 检查版本
curl http://localhost:8080/version
# {"version":"dev","build_time":"...","git_commit":"..."}