164 lines
3.1 KiB
Markdown
164 lines
3.1 KiB
Markdown
# 快速开始
|
||
|
||
## 环境要求
|
||
|
||
| 工具 | 最低版本 | 说明 |
|
||
|------|---------|------|
|
||
| Go | 1.21+ | 后端编译运行(需 CGO 支持 SQLite) |
|
||
| Node.js | 18+ | 前端构建 |
|
||
| npm | 9+ | 包管理 |
|
||
| gcc/clang | - | CGO 编译 SQLite 需要 |
|
||
|
||
### 检查环境
|
||
|
||
```bash
|
||
go version # >= 1.21
|
||
node -v # >= 18
|
||
gcc --version # macOS 自带 clang
|
||
```
|
||
|
||
## 安装
|
||
|
||
### 1. 克隆仓库
|
||
|
||
```bash
|
||
git clone https://gitee.com/attacker/aiops.git
|
||
cd aiops
|
||
```
|
||
|
||
### 2. 安装依赖
|
||
|
||
```bash
|
||
make install
|
||
# 或手动安装
|
||
cd backend && go mod download && cd ..
|
||
cd frontend cd app &&cd app && npm install && cd ..
|
||
```
|
||
|
||
### 3. 配置(可选)
|
||
|
||
默认使用 SQLite,无需任何额外配置即可启动。
|
||
|
||
如需使用 MySQL 等其他数据库,编辑 `backend/config.yaml`:
|
||
|
||
```yaml
|
||
database:
|
||
driver: mysql # 改为 mysql / postgres
|
||
host: localhost
|
||
port: 3306
|
||
user: root
|
||
password: your_password
|
||
dbname: aiops
|
||
```
|
||
|
||
## 启动
|
||
|
||
### 方式一:一键启动(推荐)
|
||
|
||
```bash
|
||
chmod +x run.sh
|
||
./run.sh start
|
||
```
|
||
|
||
输出示例:
|
||
```
|
||
[INFO] ========== AIOps 启动脚本 ==========
|
||
[INFO] 正在启动后端服务...
|
||
[INFO] 编译 Go 程序...
|
||
[SUCCESS] 后端服务已启动 (PID: 12345, 端口: 8080)
|
||
[INFO] 正在启动前端服务...
|
||
[SUCCESS] 前端服务已启动 (PID: 12346, 端口: 5173)
|
||
[SUCCESS] ========== 所有服务已启动 ==========
|
||
[INFO] 前端地址: http://localhost:5173
|
||
[INFO] 后端地址: http://localhost:8080
|
||
[INFO] 健康检查: http://localhost:8080/health
|
||
```
|
||
|
||
### 方式二:分别启动
|
||
|
||
```bash
|
||
# 仅后端
|
||
./run.sh backend
|
||
|
||
# 仅前端
|
||
./run.sh frontend
|
||
```
|
||
|
||
### 方式三:使用 Makefile
|
||
|
||
```bash
|
||
make dev # 启动
|
||
make status # 查看状态
|
||
make stop # 停止
|
||
```
|
||
|
||
## 访问
|
||
|
||
| 地址 | 说明 |
|
||
|------|------|
|
||
| http://localhost:5173 | 前端界面 |
|
||
| http://localhost:8080/health | 后端健康检查 |
|
||
| http://localhost:8080/version | 版本信息 |
|
||
| http://localhost:8080/api/v1/auth/login | 登录接口 |
|
||
|
||
## 常用命令
|
||
|
||
```bash
|
||
./run.sh status # 查看服务状态
|
||
./run.sh stop # 停止所有服务
|
||
./run.sh restart # 重启所有服务
|
||
./run.sh help # 查看帮助
|
||
|
||
make logs # 查看实时日志
|
||
make build # 构建生产包
|
||
make clean # 清理构建产物
|
||
```
|
||
|
||
## 日志位置
|
||
|
||
| 服务 | 日志文件 |
|
||
|------|---------|
|
||
| 后端 | `backend/logs/server.log` |
|
||
| 前端 | `frontend/logs/dev.log` |
|
||
| 数据库 | `backend/data/aiops.db`(SQLite 文件) |
|
||
|
||
## 数据库
|
||
|
||
默认使用 SQLite,数据库文件位于 `backend/data/aiops.db`,首次启动时自动创建表结构(AutoMigrate)。
|
||
|
||
### 重置数据库
|
||
|
||
```bash
|
||
./run.sh stop
|
||
rm -f backend/data/aiops.db
|
||
./run.sh start
|
||
```
|
||
|
||
## 常见问题
|
||
|
||
### Q: CGO 编译失败?
|
||
|
||
SQLite 需要 CGO 支持。确保环境变量 `CGO_ENABLED=1`:
|
||
|
||
```bash
|
||
export CGO_ENABLED=1
|
||
```
|
||
|
||
### Q: Go 模块下载慢?
|
||
|
||
设置国内代理:
|
||
|
||
```bash
|
||
export GOPROXY=https://goproxy.cn,direct
|
||
```
|
||
|
||
### Q: 端口被占用?
|
||
|
||
```bash
|
||
./run.sh stop # 先停止
|
||
./run.sh start # 再启动
|
||
# 或强制释放端口
|
||
lsof -ti:8080 | xargs kill -9
|
||
lsof -ti:5173 | xargs kill -9
|
||
```
|