在 VPS 服务器上部署 DeepSeek 需要什么配置?怎么部署?

大家新年好,很久没有更新了,今天分享一下在 VPS 服务器上部署 DeepSeek-R1 需综合考虑的配置和步骤,具体还是请参考 DeepSeek 官方文档。

DeepSeek 官方地址:

一、基础硬件配置

  1. CPU
  2. 内存
  3. 存储
  4. GPU(可选但推荐)

二、软件环境

  1. 操作系统
  2. 深度学习框架
  3. Python环境
  4. 依赖库

三、部署步骤

  1. 环境初始化
    # 更新系统
    sudo apt update && sudo apt upgrade -y
    
    # 安装基础工具
    sudo apt install -y git curl wget python3-pip
    
    # 安装CUDA(GPU场景)
    # 参考NVIDIA官方文档:https://developer.nvidia.com/cuda-downloads
    
  2. 安装Python环境
    # 使用conda管理环境
    wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
    bash Miniconda3-latest-Linux-x86_64.sh
    conda create -n deepseek python=3.10
    conda activate deepseek
    
  3. 安装模型依赖
    pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu117  # 根据CUDA版本调整
    pip install transformers accelerate sentencepiece
    
  4. 下载模型从Hugging Face Hub或官方渠道获取模型权重:
    from transformers import AutoModel, AutoTokenizer
    model = AutoModel.from_pretrained("deepseek-ai/deepseek-llm-7b")
    tokenizer = AutoTokenizer.from_pretrained("deepseek-ai/deepseek-llm-7b")
    
  5. 部署API服务使用FastAPI编写推理接口:
    from fastapi import FastAPI
    from pydantic import BaseModel
    
    app = FastAPI()
    
    class Query(BaseModel):
        text: str
    
    @app.post("/predict")
    async def predict(query: Query):
        inputs = tokenizer(query.text, return_tensors="pt")
        outputs = model.generate(**inputs)
        return {"response": tokenizer.decode(outputs[0])}
    
  6. 配置Web服务器使用Nginx反向代理并配置SSL:
    server {
        listen 80;
        server_name your-domain.com;
        return 301 https://$host$request_uri;
    }
    
    server {
        listen 443 ssl;
        server_name your-domain.com;
        ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
    
        location / {
            proxy_pass http://localhost:8000;
            proxy_set_header Host $host;
        }
    }
    

四、安全与优化

  1. 防火墙设置
    sudo ufw allow ssh
    sudo ufw allow http
    sudo ufw allow https
    sudo ufw enable
    
  2. 进程管理使用systemd托管服务:
    # /etc/systemd/system/deepseek.service
    [Unit]
    Description=DeepSeek API
    After=network.target
    
    [Service]
    User=ubuntu
    WorkingDirectory=/opt/deepseek
    ExecStart=/opt/miniconda3/envs/deepseek/bin/uvicorn main:app --host 0.0.0.0 --port 8000
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
    
  3. 监控与日志使用journalctl查看日志:
    journalctl -u deepseek.service -f
    

五、成本参考

配置 示例厂商方案 月成本估算
中端CPU+大内存 AWS EC2 r6i.xlarge (4vCPU, 32GB) ~$150
高端GPU Google Cloud A100 (40GB显存) ~$3000+

注意事项

根据实际需求调整配置,建议从低配测试后逐步升级。


【AD】美国洛杉矶CN2 VPS/香港CN2 VPS/日本CN2 VPS推荐,延迟低、稳定性高、免费备份_搬瓦工vps

【AD】搬瓦工限量套餐:POWERBOX-30-1536,美国洛杉矶DC99 CN2 GIA,年付仅$41.95!