← 返回 admin

🖥️ 服务器环境与部署指南

从零搭建 FunASR 视频/音频文案提取服务所需的全部软硬件信息

📑 本页目录

  1. 硬件要求
  2. 软件下载地址汇总
  3. 网络与端口要求
  4. 环境变量配置
  5. 目录结构与权限
  6. Nginx 反向代理
  7. 进程管理 (Systemd / Supervisor / NSSM)
  8. 完整部署示例 (Ubuntu)

1️⃣ 硬件要求

4 ~ 8 核
CPU (最低 4 / 推荐 8 核+)
8 ~ 16 GB
内存 (最低 8G / 推荐 16G+)
可选 GPU
NVIDIA 4GB+ (RTX 3050+)
15 GB+
SSD 磁盘空间

2️⃣ 软件下载地址汇总

📦 核心运行环境

软件版本用途下载地址
Python 3.8 ~ 3.10 运行环境 python.org/downloads
FFmpeg Win/Linux 4.0+ 音视频处理 Windows 下载  |  apt install ffmpeg
Git Win/Linux 2.0+ 代码管理 Windows 下载  |  apt install git

🚀 GPU 加速组件 (可选,推荐)

软件版本用途下载地址
NVIDIA 驱动 ≥ 525.x GPU 支持 nvidia.com/Download
CUDA Toolkit ≥ 11.8 GPU 加速 developer.nvidia.com/cuda-toolkit
cuDNN ≥ 8.7 深度学习 developer.nvidia.com/cudnn (需注册)

🛠️ 服务管理 & 反向代理

软件版本用途下载地址
NSSM Windows 最新 Windows 服务 nssm.cc/download
Nginx Win/Linux 1.20+ 反向代理 nginx.org  |  apt install nginx
Certbot Linux 最新 HTTPS 证书 apt install certbot python3-certbot-nginx
Redis Win/Linux 6.0+ 任务队列 (可选) Windows Redis  |  apt install redis-server

3️⃣ 网络与端口要求

🌐 需要放行的域名 (防火墙)

域名用途端口
www.modelscope.cn首次自动下载 ASR 模型 (~2-3 GB)443
api.deepseek.comLLM 语义纠错 (可选)443

🔌 服务端口

端口用途说明
8000FunASR API 服务可在启动参数修改
80 / 443Nginx 反向代理对外提供 HTTP/HTTPS

📂 目录结构

目录用途默认大小
uploads/用户上传文件按需
results/转写结果按需
logs/应用日志~100MB
models/ASR 模型缓存2 ~ 3 GB

4️⃣ 环境变量配置 (.env)

在项目根目录创建 .env 文件:

# ---- 服务配置 ----
PRELOAD_MODELS=true

# ---- 模型缓存 ----
MODELSCOPE_CACHE=/opt/FunASR-Service/models

# ---- DeepSeek LLM 纠错 (可选) ----
DEEPSEEK_API_KEY=sk-your-api-key-here
DEEPSEEK_BASE_URL=https://api.deepseek.com
DEEPSEEK_MODEL=deepseek-chat
ENABLE_LLM_CORRECT=true
LLM_CORRECT_TIMEOUT=15
LLM_CORRECT_MAX_CHARS=2000

🔑 DeepSeek API Key 获取: platform.deepseek.com

5️⃣ 目录结构与权限 (Linux)

# 创建必要目录
mkdir -p uploads results logs models

# 设置权限 (假设以 www-data 用户运行)
sudo chown -R www-data:www-data /opt/FunASR-Service
sudo chmod 755 /opt/FunASR-Service/{uploads,results,logs,models}

6️⃣ Nginx 反向代理

配置 /etc/nginx/sites-available/funasr

server {
    listen 80;
    server_name your-domain.com;

    # 上传文件大小限制
    client_max_body_size 100M;
    client_body_timeout 300s;

    location / {
        proxy_pass http://127.0.0.1:8000;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # WebSocket 支持
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        # 超时设置
        proxy_read_timeout 300s;
        proxy_send_timeout 300s;
    }
}
# 启用配置
sudo ln -s /etc/nginx/sites-available/funasr /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

7️⃣ 进程管理

🐧 Linux - Systemd (推荐)

创建 /etc/systemd/system/funasr.service

[Unit]
Description=FunASR Speech Recognition Service
After=network.target

[Service]
Type=simple
User=www-data
Group=www-data
WorkingDirectory=/opt/FunASR-Service
EnvironmentFile=/opt/FunASR-Service/.env
ExecStart=/opt/FunASR-Service/venv/bin/uvicorn api.main:app \
    --host 127.0.0.1 --port 8000 --workers 4
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable funasr
sudo systemctl start funasr
sudo systemctl status funasr     # 状态
sudo journalctl -u funasr -f     # 实时日志

🪟 Windows - NSSM (推荐)

下载 NSSM: nssm.cc/download

REM 安装为 Windows 服务
nssm install FunASR

REM 配置:
REM Application:    D:\FunASR-Service\venv\Scripts\uvicorn.exe
REM Arguments:      api.main:app --host 0.0.0.0 --port 8000 --workers 2
REM Start directory: D:\FunASR-Service

nssm start FunASR

8️⃣ 完整部署示例 (Ubuntu 20.04+)

# 1. 安装系统依赖
sudo apt update
sudo apt install -y python3.10 python3.10-venv python3.10-dev ffmpeg git nginx

# 2. 克隆项目
cd /opt
git clone https://github.com/your/FunASR-Service.git
cd FunASR-Service

# 3. 创建虚拟环境并安装依赖
python3.10 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

# 4. 创建必要目录
mkdir -p uploads results logs models

# 5. 配置环境变量
cp .env.example .env
nano .env    # 编辑配置

# 6. 配置 Nginx (粘贴上面的 Nginx 配置)
sudo nano /etc/nginx/sites-available/funasr
sudo ln -s /etc/nginx/sites-available/funasr /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx

# 7. 配置 Systemd 服务 (粘贴上面的 Systemd 配置)
sudo nano /etc/systemd/system/funasr.service
sudo systemctl daemon-reload
sudo systemctl enable --now funasr

# 8. 配置 HTTPS (可选)
sudo apt install -y certbot python3-certbot-nginx
sudo certbot --nginx -d your-domain.com

# 9. 验证
curl http://localhost:8000/health