好的!以下是一个详细的关于在生产环境中部署 DeepSeek 的教程。这个教程将从环境准备到最终运行进行全面介绍:
《DeepSeek 智能助手部署指南》
目录
- 环境要求
- 部署前的准备工作
- 服务器部署步骤
- 数据库配置
- 存储服务配置
- 网络与安全设置
- 源码编译与安装
- 依赖项管理
- 启动与测试
- 高可用性与扩展
1. 环境要求
1.1 操作系统
- Linux(推荐):Ubuntu 22.04 LTS 或 CentOS 7/8
- Windows 或 macOS 可以用于开发,但生产环境建议使用 Linux。
1.2 硬件要求
- CPU:至少 4 核 8 线程(根据负载调整)
- 内存:至少 8GB RAM(根据负载扩展)
- 存储:至少 50GB 可用空间(SSD 优先)
1.3 网络要求
- 稳定的网络连接
- 公网 IP 或反向代理配置
2. 部署前的准备工作
2.1 下载 DeepSeek 源码
# 使用 Git 克隆仓库
git clone https://github.com/DeepSeek-R1/deepseek.git
cd deepseek
2.2 安装依赖工具
- Git:用于代码管理。
- Docker 或 Kubernetes(可选):用于容器化部署。
- Python 3.8+:DeepSeek 的主要开发语言。
3. 服务器部署步骤
3.1 安装操作系统
# 以 Ubuntu 22.04 LTS 为例:
sudo apt update && sudo apt upgrade -y
sudo apt install -y python3 python3-pip git docker.io
3.2 配置服务器网络
- 确保服务器有公网 IP 或配置反向代理(如 Nginx)。
- 示例:使用 Nginx 反向代理 DeepSeek 的 WebSocket 和 HTTP 请求。
4. 数据库配置
4.1 安装数据库
推荐使用 PostgreSQL 或 MySQL:
# PostgreSQL 安装示例:
sudo apt install -y postgresql postgresql-contrib
4.2 创建数据库和用户
# 进入 PostgreSQL 控制台:
sudo -u postgres psql
# 创建数据库:
CREATE DATABASE deepseek;
# 创建用户:
CREATE USER deepseek_user WITH PASSWORD 'your_password';
ALTER DATABASE deepseek OWNER TO deepseek_user;
GRANT ALL PRIVILEGES ON DATABASE deepseek TO deepseek_user;
4.3 配置数据库连接
将以下配置添加到 deepseek/config/database.yml
:
default:
adapter: postgresql
database: deepseek
user: deepseek_user
password: your_password
host: localhost
port: 5432
5. 存储服务配置
5.1 安装存储服务
推荐使用 MinIO 或 阿里云 OSS:
# MinIO 安装示例:
wget https://dl.min.io.cn/minio-RELEASE-LINUX-X86_64
chmod +x minio-RELEASE-LINUX-X86_64
sudo ./minio-RELEASE-LINUX-X86_64 install /usr/local/bin/
5.2 配置存储服务
将以下配置添加到 deepseek/config/storage.yml
:
storage:
type: minio
access_key: your_minio_access_key
secret_key: your_minio_secret_key
endpoint: http://localhost:9000
6. 网络与安全设置
6.1 配置反向代理(Nginx 示例)
sudo apt install -y nginx
sudo nano /etc/nginx/sites-available/deepseek.conf
添加以下配置:
server {
listen 80;
server_name your_domain.com;
location / {
proxy_pass http://localhost:5000; # DeepSeek 默认端口
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /ws {
proxy_pass http://localhost:5000/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
重启 Nginx:
sudo nginx -s reload
6.2 配置防火墙
sudo ufw allow 'Nginx Full'
sudo ufw allow 22 # SSH 访问
sudo ufw allow 5000 # DeepSeek 端口(可选)
sudo ufw default deny
7. 源码编译与安装
7.1 安装依赖
pip install -r requirements.txt
7.2 配置环境变量
编辑 ~/.env
文件:
DEEPSEEK_ENV=production
DEEPSEEK_DB_URI=postgresql://deepseek_user:your_password@localhost:5432/deepseek
DEEPSEEK_STORAGE_TYPE=minio
DEEPSEEK_STORAGE_ENDPOINT=http://localhost:9000
8. 启动与测试
8.1 启动 DeepSeek
# 使用 Gunicorn 启动(示例)
gunicorn --bind "0.0.0.0:5000" deepseek.app:app
8.2 测试部署
访问你的域名或 IP,检查是否正常显示 DeepSeek 界面。
9. 高可用性与扩展
9.1 使用 Docker 容器化
# Dockerfile 示例
FROM python:3.8-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["gunicorn", "--bind", "0.0.0.0:5000", "deepseek.app:app"]
9.2 使用 Kubernetes 扩展
- 部署到 Kubernetes 集群,配置 Horizontal Pod Autoscaler 和 Ingress。
结语
至此,DeepSeek 已经成功部署。可以根据需要进一步优化和扩展!