Files
ViGent2/Docs/DEPLOY_MANUAL.md
Kevin Wong 3db15cee4e 更新
2026-01-22 09:22:23 +08:00

241 lines
5.0 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.
# ViGent 手动部署指南
## 服务器信息
| 配置 | 规格 |
|------|------|
| 服务器 | Dell PowerEdge R730 |
| CPU | 2× Intel Xeon E5-2680 v4 (56 线程) |
| 内存 | 192GB DDR4 |
| GPU 0 | NVIDIA RTX 3090 24GB |
| GPU 1 | NVIDIA RTX 3090 24GB (用于 LatentSync) |
| 部署路径 | `/home/rongye/ProgramFiles/ViGent2` |
---
## 步骤 1: 环境检查
```bash
# 检查 GPU
nvidia-smi
# 检查 Python 版本 (需要 3.10+)
python3 --version
# 检查 Node.js 版本 (需要 18+)
node --version
# 检查 FFmpeg
ffmpeg -version
```
如果缺少 FFmpeg:
```bash
sudo apt update
sudo apt install ffmpeg
```
---
## 步骤 2: 创建目录结构
```bash
mkdir -p /home/rongye/ProgramFiles/ViGent2
cd /home/rongye/ProgramFiles/ViGent2
```
将项目文件复制到该目录。
---
## 步骤 3: 安装后端依赖
```bash
cd /home/rongye/ProgramFiles/ViGent2/backend
# 创建虚拟环境
python3 -m venv venv
source venv/bin/activate
# 安装 PyTorch (CUDA 12.1)
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121
# 安装 Python 依赖
pip install -r requirements.txt
# 安装 Playwright 浏览器(社交发布需要)
playwright install chromium
```
---
## 步骤 4: 部署 AI 模型 (LatentSync 1.6)
> ⚠️ **重要**LatentSync 需要独立的 Conda 环境和 **~18GB VRAM**。请**不要**直接安装在后端环境中。
请参考详细的独立部署指南:
**[LatentSync 部署指南](../models/LatentSync/DEPLOY.md)**
该指南包含以下关键步骤,请务必严格按照文档操作:
1. 创建独立的 `latentsync` Conda 环境
2. 安装 PyTorch 2.5.1 和相关依赖
3. 下载模型权重 (HuggingFace CLI)
4. 复制核心推理代码
5. 验证推理脚本
确保 LatentSync 部署成功后,再继续后续步骤。
---
## 步骤 5: 启动 LatentSync 常驻加速服务 (可选)
为了消除每次生成视频时的 30-40秒 模型加载时间,建议启动常驻服务:
```bash
cd /home/rongye/ProgramFiles/ViGent2/models/LatentSync
# 后台启动服务 (自动读取 backend/.env 中的 GPU 配置)
nohup python -m scripts.server > server.log 2>&1 &
```
---
## 步骤 7: 配置环境变量
```bash
cd /home/rongye/ProgramFiles/ViGent2/backend
# 复制配置模板 (默认配置已经就绪)
cp .env.example .env
```
> 💡 **说明**`.env.example` 已包含正确的 LatentSync 默认配置,直接复制即可使用。
> 如需自定义,可编辑 `.env` 修改以下参数:
| 配置项 | 默认值 | 说明 |
|--------|--------|------|
| `LATENTSYNC_GPU_ID` | 1 | GPU 选择 (0 或 1) |
| `LATENTSYNC_USE_SERVER` | false | 设为 true 以启用常驻服务加速 |
| `LATENTSYNC_INFERENCE_STEPS` | 20 | 推理步数 (20-50) |
| `LATENTSYNC_GUIDANCE_SCALE` | 1.5 | 引导系数 (1.0-3.0) |
| `DEBUG` | true | 生产环境改为 false |
---
## 步骤 8: 安装前端依赖
```bash
cd /home/rongye/ProgramFiles/ViGent2/frontend
# 安装依赖
npm install
```
---
## 步骤 9: 测试运行
### 启动后端
```bash
cd /home/rongye/ProgramFiles/ViGent2/backend
source venv/bin/activate
uvicorn app.main:app --host 0.0.0.0 --port 8006
```
### 启动前端 (新开终端)
```bash
cd /home/rongye/ProgramFiles/ViGent2/frontend
npm run dev -- -H 0.0.0.0 --port 3002
```
---
## 步骤 10: 验证
1. 访问 http://服务器IP:3002 查看前端
2. 访问 http://服务器IP:8006/docs 查看 API 文档
3. 上传测试视频,生成口播视频
---
## 使用 systemd 管理服务 (可选)
### 后端服务
创建 `/etc/systemd/system/vigent2-backend.service`:
```ini
[Unit]
Description=ViGent2 Backend API
After=network.target
[Service]
Type=simple
User=rongye
WorkingDirectory=/home/rongye/ProgramFiles/ViGent2/backend
Environment="PATH=/home/rongye/ProgramFiles/ViGent2/backend/venv/bin"
ExecStart=/home/rongye/ProgramFiles/ViGent2/backend/venv/bin/uvicorn app.main:app --host 0.0.0.0 --port 8006
Restart=always
[Install]
WantedBy=multi-user.target
```
### 前端服务
创建 `/etc/systemd/system/vigent2-frontend.service`:
```ini
[Unit]
Description=ViGent2 Frontend
After=network.target
[Service]
Type=simple
User=rongye
WorkingDirectory=/home/rongye/ProgramFiles/ViGent2/frontend
ExecStart=/usr/bin/npm run start
Restart=always
[Install]
WantedBy=multi-user.target
```
### 启用服务
```bash
sudo systemctl daemon-reload
sudo systemctl enable vigent2-backend vigent2-frontend
sudo systemctl start vigent2-backend vigent2-frontend
```
---
## 故障排除
### GPU 不可用
```bash
# 检查 CUDA
nvidia-smi
python3 -c "import torch; print(torch.cuda.is_available())"
```
### 端口被占用
```bash
# 查看端口占用
sudo lsof -i :8006
sudo lsof -i :3002
```
### 查看日志
```bash
# 后端日志
journalctl -u vigent2-backend -f
# 前端日志
journalctl -u vigent2-frontend -f
```