以下是在16核32G内存的CentOS 7.9服务器上部署DeepSeek的详细步骤,假设部署的是其开源模型(如LLM):
# 1. 更新系统及安装基础工具
sudo yum update -y
sudo yum groupinstall "Development Tools" -y
sudo yum install -y epel-release wget curl git openssl-devel bzip2-devel libffi-devel
# 2. 安装Python 3.8+(通过Miniconda)
wget <https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh>
bash Miniconda3-latest-Linux-x86_64.sh -b -p $HOME/miniconda
echo 'export PATH="$HOME/miniconda/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
# 3. 创建Python虚拟环境
conda create -n deepseek python=3.10 -y
conda activate deepseek
# 1. 查看显卡型号
lspci | grep -i nvidia
# 2. 安装NVIDIA驱动和CUDA(以CUDA 11.8为例)
sudo yum install -y kernel-devel-$(uname -r) kernel-headers-$(uname -r)
wget <https://developer.download.nvidia.com/compute/cuda/11.8.0/local_installers/cuda_11.8.0_520.61.05_linux.run>
sudo sh cuda_11.8.0_520.61.05_linux.run --silent --driver --toolkit
# 3. 添加环境变量
echo 'export PATH=/usr/local/cuda-11.8/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
# 4. 验证安装
nvidia-smi
# 1. 克隆官方仓库(假设为示例仓库)
git clone <https://github.com/deepseek-ai/deepseek-llm.git>
cd deepseek-llm
# 2. 下载模型权重(需申请权限或从HuggingFace下载)
# 示例:使用huggingface-cli下载(需安装)
pip install huggingface_hub
huggingface-cli download deepseek-ai/deepseek-llm-7b-base --local-dir ./model
# 3. 安装依赖库
pip install -r requirements.txt
pip install torch torchvision torchaudio --index-url <https://download.pytorch.org/whl/cu118> # 匹配CUDA版本
# 1. 编写启动脚本(如api_server.py)
cat << EOF > api_server.py
from fastapi import FastAPI
from transformers import AutoModelForCausalLM, AutoTokenizer
app = FastAPI()
model = AutoModelForCausalLM.from_pretrained("./model")
tokenizer = AutoTokenizer.from_pretrained("./model")
@app.post("/generate")
def generate_text(prompt: str, max_length: int = 128):
inputs = tokenizer(prompt, return_tensors="pt")
outputs = model.generate(**inputs, max_length=max_length)
return {"result": tokenizer.decode(outputs[0])}
EOF
# 2. 安装FastAPI和uvicorn
pip install fastapi uvicorn
# 1. 启动API服务(绑定到0.0.0:8000)
uvicorn api_server:app --host 0.0.0.0 --port 8000 --workers 2
# 2. 测试API(新终端)
curl -X POST "<http://localhost:8000/generate>" -H "Content-Type: application/json" -d '{"prompt":"你好,DeepSeek", "max_length":50}'
# 1. 使用systemd守护进程
sudo tee /etc/systemd/system/deepseek.service << EOF
[Unit]
Description=DeepSeek LLM Service
[Service]
User=root
WorkingDirectory=/root/deepseek-llm
ExecStart=/root/miniconda/envs/deepseek/bin/uvicorn api_server:app --host 0.0.0.0 --port 8000
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# 2. 启动服务
sudo systemctl daemon-reload
sudo systemctl start deepseek
sudo systemctl enable deepseek
# 3. 开放防火墙端口
sudo firewall-cmd --permanent --add-port=8000/tcp
sudo firewall-cmd --reload