🚀 FastGPT 私有化部署完整指南
📋 環境要求
硬件要求
最低配置:CPU: 4核內存: 8GB存儲: 50GB網絡: 穩定互聯網連接推薦配置:CPU: 8核+內存: 16GB+存儲: 100GB+ SSD網絡: 10Mbps+帶寬
軟件環境
必需軟件:- Docker: >= 20.10.0- Docker Compose: >= 2.0.0- Git: 最新版本操作系統:- Ubuntu 20.04+ (推薦)- CentOS 7+- Windows Server (支持Docker)- macOS (開發測試)
🐳 Docker Compose 部署(推薦)
1. 獲取源碼
# 克隆倉庫
git clone https://github.com/labring/FastGPT.git
cd FastGPT# 切換到穩定版本
git checkout v4.9.14
2. 配置環境
# 進入部署目錄
cd projects/app/docker# 復制配置文件
cp .env.template .env
cp config.json.template config.json
3. 修改配置文件
編輯 .env
文件
# 數據庫配置
MONGO_PASSWORD=your_mongo_password
PG_PASSWORD=your_postgres_password# 服務端口
PORT=3000# 域名配置(可選)
DEFAULT_ROOT_PSW=your_admin_password
編輯 config.json
文件
{"SystemParams": {"gitBranch": "v4.9.14","chatApiKey": "","vectorMaxProcess": 15,"qaMaxProcess": 15,"pgHNSWEfSearch": 100},"llmModels": [{"model": "gpt-3.5-turbo","name": "GPT-3.5-turbo","apiKey": "YOUR_OPENAI_API_KEY","baseUrl": "https://api.openai.com/v1","maxTokens": 4000,"maxTemperature": 1.2}],"vectorModels": [{"model": "text-embedding-ada-002","name": "OpenAI-Ada","apiKey": "YOUR_OPENAI_API_KEY", "baseUrl": "https://api.openai.com/v1","dbConfig": {}}]
}
4. 啟動服務
# 啟動所有服務
docker-compose up -d# 查看服務狀態
docker-compose ps# 查看日志
docker-compose logs -f fastgpt
?? 詳細配置說明
大模型配置
OpenAI 配置
{"model": "gpt-4","name": "GPT-4","apiKey": "sk-xxxxxxxx","baseUrl": "https://api.openai.com/v1","maxTokens": 8000,"maxTemperature": 1.2,"vision": true
}
國產大模型配置
// 阿里通義千問
{"model": "qwen-max", "name": "通義千問Max","apiKey": "sk-xxxxxxxx","baseUrl": "https://dashscope.aliyuncs.com/compatible-mode/v1","maxTokens": 6000
}// 深度求索
{"model": "deepseek-chat","name": "DeepSeek Chat", "apiKey": "sk-xxxxxxxx","baseUrl": "https://api.deepseek.com/v1","maxTokens": 4000
}
向量模型配置
// 本地BGE模型
{"model": "bge-large-zh-v1.5","name": "BGE-Large-ZH","baseUrl": "http://localhost:6006/v1", "dbConfig": {"dimensions": 1024}
}// OpenAI Embedding
{"model": "text-embedding-3-large","name": "OpenAI-Embedding-3-Large","apiKey": "sk-xxxxxxxx","baseUrl": "https://api.openai.com/v1","dbConfig": {"dimensions": 3072}
}
🛠? 本地模型部署
1. Ollama 本地部署
# 安裝 Ollama
curl -fsSL https://ollama.com/install.sh | sh# 拉取模型
ollama pull qwen2.5:7b
ollama pull bge-m3:latest# 啟動服務
ollama serve
FastGPT 配置 Ollama
{"llmModels": [{"model": "qwen2.5:7b","name": "通義千問2.5-7B","baseUrl": "http://host.docker.internal:11434/v1","apiKey": "ollama","maxTokens": 4000}],"vectorModels": [{"model": "bge-m3:latest", "name": "BGE-M3","baseUrl": "http://host.docker.internal:11434/v1","apiKey": "ollama"}]
}
2. Xinference 部署
# 安裝 Xinference
pip install xinference# 啟動服務
xinference-local --host 0.0.0.0 --port 9997# 通過 Web UI 管理模型
# http://localhost:9997
🌐 反向代理配置
Nginx 配置
server {listen 80;server_name your-domain.com;# 重定向到 HTTPSreturn 301 https://$server_name$request_uri;
}server {listen 443 ssl;server_name your-domain.com;# SSL 證書配置ssl_certificate /path/to/cert.pem;ssl_certificate_key /path/to/key.pem;location / {proxy_pass http://localhost:3000;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";}
}
📊 數據庫管理
MongoDB 管理
# 連接 MongoDB
docker exec -it fastgpt-mongo mongo -u myusername -p mypassword# 備份數據庫
docker exec fastgpt-mongo mongodump -u myusername -p mypassword -d fastgpt -o /backup# 恢復數據庫
docker exec fastgpt-mongo mongorestore -u myusername -p mypassword -d fastgpt /backup/fastgpt
PostgreSQL 管理
# 連接 PostgreSQL
docker exec -it fastgpt-pg psql -U username -d postgres# 備份數據庫
docker exec fastgpt-pg pg_dump -U username fastgpt > backup.sql# 恢復數據庫
docker exec -i fastgpt-pg psql -U username fastgpt < backup.sql
🔧 常見問題解決
1. 服務啟動失敗
# 檢查端口占用
netstat -tulpn | grep :3000# 檢查磁盤空間
df -h# 重啟服務
docker-compose restart
2. 內存不足
# 在 docker-compose.yml 中限制內存
services:fastgpt:deploy:resources:limits:memory: 4Greservations:memory: 2G
3. API 連接問題
# 測試 API 連通性
curl -X POST https://api.openai.com/v1/chat/completions \-H "Authorization: Bearer YOUR_API_KEY" \-H "Content-Type: application/json" \-d '{"model":"gpt-3.5-turbo","messages":[{"role":"user","content":"Hello"}]}'
🚀 生產環境優化
性能優化配置
# docker-compose.yml 優化
version: '3.8'
services:fastgpt:restart: alwayslogging:driver: "json-file"options:max-size: "100m"max-file: "3"deploy:resources:limits:cpus: '4.0'memory: 8Greservations:cpus: '2.0'memory: 4G
監控配置
# 添加健康檢查
healthcheck:test: ["CMD", "curl", "-f", "http://localhost:3000/api/system/getInitData"]interval: 30stimeout: 10sretries: 3
📋 部署檢查清單
部署前檢查 ?
□ 服務器資源充足
□ Docker 環境正常
□ 網絡連接穩定
□ 域名解析配置
□ SSL 證書準備
□ API Key 有效
部署后驗證 ?
□ 服務正常啟動
□ Web 界面可訪問
□ 數據庫連接正常
□ 大模型調用成功
□ 文件上傳功能正常
□ 對話功能測試通過
🎯 總結
FastGPT 私有化部署相對簡單,關鍵要點:
- 環境準備:確保 Docker 環境和硬件資源充足
- 配置管理:正確配置大模型和向量模型 API
- 安全考慮:使用 HTTPS、強密碼、防火墻配置
- 監控維護:定期備份、日志監控、性能優化
部署成功后,你將擁有一個完全私有的 AI 知識庫平臺!🎉