156 lines
3.7 KiB
Markdown
156 lines
3.7 KiB
Markdown
# 部署指南
|
|
|
|
## 1. NAS 端部署 (FAM-Core + FAM-UI + MariaDB)
|
|
|
|
### 1.1 MariaDB
|
|
```bash
|
|
# 安装 MariaDB (通过 Synology 套件中心)
|
|
# 确认端口 3306 可用
|
|
|
|
# 执行 DDL
|
|
python3 scripts/init_db.py --host 127.0.0.1 --port 3306 --user root --password <密码>
|
|
```
|
|
|
|
### 1.2 FAM-Core
|
|
```bash
|
|
cd /path/to/sentinel-home-ai/fam-core
|
|
python3 -m venv venv
|
|
source venv/bin/activate
|
|
pip install -r requirements.txt
|
|
|
|
# 配置
|
|
cp config/config.yaml.example config/config.yaml
|
|
# 编辑 config.yaml: 数据库密码、Oracle Tailscale IP、token 等
|
|
|
|
# 启动
|
|
./scripts/start_core.sh
|
|
# 或手动: gunicorn -w 1 -b 0.0.0.0:8000 --timeout 120 src.fam_core.app:app
|
|
```
|
|
|
|
### 1.3 FAM-UI
|
|
```bash
|
|
cd /path/to/sentinel-home-ai/fam-ui
|
|
python3 -m venv venv
|
|
source venv/bin/activate
|
|
pip install -r requirements.txt
|
|
|
|
# 配置
|
|
cp config/config.yaml.example config/config.yaml
|
|
# 编辑 config.yaml: 数据库连接、FAM-Core 地址
|
|
|
|
# 启动
|
|
./scripts/start_ui.sh
|
|
# 或手动: streamlit run src/app.py --server.port 8501 --server.address 0.0.0.0
|
|
```
|
|
|
|
## 2. Oracle 端部署 (FAM-Edge + Ollama + FFmpeg)
|
|
|
|
### 2.1 系统依赖
|
|
```bash
|
|
# FFmpeg
|
|
sudo apt update && sudo apt install -y ffmpeg
|
|
|
|
# OpenCV 依赖
|
|
sudo apt install -y python3-opencv libopencv-dev
|
|
|
|
# Ollama
|
|
curl -fsSL https://ollama.com/install.sh | sh
|
|
systemctl enable ollama
|
|
systemctl start ollama
|
|
|
|
# 拉取模型
|
|
ollama pull llava-phi3
|
|
```
|
|
|
|
### 2.2 FAM-Edge
|
|
```bash
|
|
cd /path/to/sentinel-home-ai/fam-edge
|
|
python3 -m venv venv
|
|
source venv/bin/activate
|
|
pip install -r requirements.txt
|
|
|
|
# 配置
|
|
cp config/config.yaml.example config/config.yaml
|
|
# 编辑 config.yaml: NAS Tailscale IP、media_token、Gemini API Key
|
|
|
|
# 设置 Gemini API Key 环境变量
|
|
export GEMINI_API_KEY="your-api-key-here"
|
|
|
|
# 启动
|
|
./scripts/start_edge.sh
|
|
# 或手动: gunicorn -w 1 -b 0.0.0.0:5000 --timeout 600 src.fam_edge.app:app
|
|
```
|
|
|
|
### 2.3 模型可行性压测 (阶段一验证)
|
|
```bash
|
|
# 测试 llava-phi3 单张图推理耗时
|
|
ollama run llava-phi3 "描述这张图片" --images /path/to/test.jpg
|
|
|
|
# 预期:
|
|
# - 单张 ≤ 8 秒 → 可行
|
|
# - 单张 ≤ 30 秒 → 可接受
|
|
# - 单张 > 30 秒 → 需换更小模型或减帧
|
|
```
|
|
|
|
## 3. Tailscale 组网
|
|
|
|
```bash
|
|
# NAS 端
|
|
curl -fsSL https://tailscale.com/install.sh | sh
|
|
sudo tailscale up
|
|
|
|
# Oracle 端
|
|
curl -fsSL https://tailscale.com/install.sh | sh
|
|
sudo tailscale up
|
|
|
|
# 验证
|
|
# NAS: ping 100.x.x.20 (Oracle Tailscale IP)
|
|
# Oracle: ping 100.x.x.10 (NAS Tailscale IP)
|
|
```
|
|
|
|
## 4. 开机自启 (可选)
|
|
|
|
### NAS 端 (使用任务计划)
|
|
```bash
|
|
# Synology DSM -> 控制面板 -> 任务计划 -> 新增 -> 触发的任务 -> 开机
|
|
# 脚本:
|
|
cd /path/to/sentinel-home-ai
|
|
./scripts/start_core.sh &
|
|
./scripts/start_ui.sh &
|
|
```
|
|
|
|
### Oracle 端 (使用 systemd)
|
|
```bash
|
|
sudo tee /etc/systemd/system/fam-edge.service << 'EOF'
|
|
[Unit]
|
|
Description=FAM-Edge Service
|
|
After=network.target ollama.service
|
|
|
|
[Service]
|
|
Type=simple
|
|
User=ubuntu
|
|
WorkingDirectory=/path/to/sentinel-home-ai/fam-edge
|
|
Environment=GEMINI_API_KEY=your-api-key
|
|
ExecStart=/path/to/sentinel-home-ai/fam-edge/venv/bin/gunicorn -w 1 -b 0.0.0.0:5000 --timeout 600 src.fam_edge.app:app
|
|
Restart=always
|
|
RestartSec=10
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
|
|
sudo systemctl enable fam-edge
|
|
sudo systemctl start fam-edge
|
|
```
|
|
|
|
## 5. 验证清单
|
|
|
|
| 项目 | 命令 | 预期 |
|
|
|------|------|------|
|
|
| NAS MariaDB | `mysql -u root -p -e "SHOW DATABASES"` | 包含 sentinel_home_ai |
|
|
| NAS FAM-Core | `curl http://localhost:8000/health` | `{"status":"ok"}` |
|
|
| NAS FAM-UI | 浏览器访问 `http://192.168.50.64:8501` | Streamlit 页面 |
|
|
| Oracle FAM-Edge | `curl http://localhost:5000/health` | `{"status":"ok"}` |
|
|
| Oracle Ollama | `curl http://localhost:11434/api/tags` | 模型列表含 llava-phi3 |
|
|
| Tailscale | NAS `ping 100.x.x.20` | 通 |
|