2条命令本地部署deepseek
- Ai
- 2025-02-10
- 273热度
- 2评论
环境是centos,下面是部署步骤。
命令1: 安装ollama
安装命令:curl -fsSL https://ollama.com/install.sh | sh
安装日志:
>>> Cleaning up old version at /usr/local/lib/ollama
>>> Installing ollama to /usr/local
>>> Downloading Linux amd64 bundle
######################################################################## 100.0
>>> Creating ollama user...
>>> Adding ollama user to video group...
>>> Adding current user to ollama group...
>>> Creating ollama systemd service...
>>> Enabling and starting ollama service...
Created symlink from /etc/systemd/system/default.target.wants/ollama.service to /etc/systemd/system/ollama.service.
>>> The Ollama API is now available at 127.0.0.1:11434.
>>> Install complete. Run "ollama" from the command line.
命令2:下载deepseek模型
安装命令:ollama run deepseek-r1:7b
安装完成后,会直接进入交互控制台:
pulling manifest
pulling 96c415656d37... 100
pulling 369ca498f347... 100
pulling 6e4c38e1172f... 100
pulling f4d24e9138dd... 100
pulling 40fb844194b2... 100
verifying sha256 digest
writing manifest
success
>>> hello
<think>
</think>
Hello! How can I assist you today? 😊
>>> 你好
<think>
</think>
你好!有什么我可以帮助你的吗?😊
>>> 你是什么模型
<think>
</think>
您好!我是由中国的深度求索(DeepSeek)公司开发的智能助手DeepSeek-R1。如您有任何任何问题,我会尽我所能为您提供帮助。
运行时,如果加上--verbose可以查看运行性能参数,如下:
total duration: 379.511567ms
load duration: 14.749448ms
prompt eval count: 60 token(s)
prompt eval duration: 15.863495ms
prompt eval rate: 3782.27 tokens/s
eval count: 64 token(s)
eval duration: 322.980292ms
eval rate: 198.15 tokens/s
- total duration:总耗时379.51ms,表示从请求开始到响应完成的整体处理时间
- load duration: 模型加载耗时14.75ms,可能涉及模型初始化或数据加载阶段的时间消耗
- prompt eval count:输入提示词(prompt)解析的token数量为60个
- prompt eval duration:提示词解析耗时15.86ms,反映模型对输入文本的预处理效率
- prompt eval rate: 提示词解析速率3782.27 tokens/s,属于高性能表现(通常千级tokens/s为优秀)
- eval count: 生成输出的token数量为64个
- eval duration: 生成耗时322.98ms,占整体耗时的主要部分。
- eval rate: 生成速率198.15 tokens/s,属于典型的大模型推理速度(百级tokens/s为常见范围)
GGUF导入部署
这种方式可以通过导入GUFF格式的大模型,GUFF格式大模型可以从Hugging Face获取https://huggingface.co/。也可以在modelscope上获取https://modelscope.cn/models。
首先从Hugging Face或者modelscope下载GGUF格式的模型,然后部署主要分为两个步骤
创建模型
通过create指定模型modelfile。
ollama create qwen2.5:7b -f qwen2.5-7b.modelfile
modelfile内容如下,指定了模型的路径,模型配置文件描述了模型的参数,更多信息这里不做阐述。
FROM "./qwen2.5-7b-instruct-q4_0.gguf"
运行模型
列出模型
ollama list
运行模型 verbose参数可以打印性能。
ollama run qwen2.5:7b --verbose
也可以使用ollama pull从ollama官方下载,https://ollama.com/search
支持API访问
修改ollama的本地端口
/etc/systemd/system/ollama.service
[Unit]
Description=Ollama Service
After=network-online.target
[Service]
ExecStart=/usr/local/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin"
Environment="OLLAMA_HOST=0.0.0.0"
[Install]
WantedBy=default.target
然后重新启动
systemctl daemon-reload
systemctl restart ollama
确认是否启动成功:
sudo netstat -tulpn | grep 11434 # 确认监听0.0.0.0:11434:cite[3]:cite[6]
远程API调用示例
# 查询API版本(验证连通性)
curl http://<服务器公网IP>:11434/api/version
# 发送生成请求
curl http://localhost:11434/api/generate -d "{\\\\\\\\\\\\\\\\"model\\\\\\\\\\\\\\\\": \\\\\\\\\\\\\\\\"deepseek-r1:7b\\\\\\\\\\\\\\\\", \\\\\\\\\\\\\\\\"prompt\\\\\\\\\\\\\\\\": \\\\\\\\\\\\\\\\"为什么草是绿的\\\\\\\\\\\\\\\\"}"
参考:https://github.com/datawhalechina/handy-ollama/blob/main/docs/C4/1.%20Ollama%20API%20%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97.md
支持web聊天
安装docker
如果要按照网页版的聊天需要安装open ui,先安装docker。
(1)更新系统
sudo yum update -y
(2)Docker 需要一些依赖包,你可以通过运行以下命令来安装:
sudo yum install -y yum-utils device-mapper-persistent-data lvm2
(3)更新本地镜像源
sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
sed -i 's/download.docker.com/mirrors.aliyun.com\\\\\\\\\\\\\\\\/docker-ce/g' /etc/yum.repos.d/docker-ce.repo
yum makecache fast
(4)安装docker
sudo yum install -y docker-ce
(5)设置开机自启动
sudo systemctl start docker
sudo systemctl enable docker
(6)验证
sudo docker --version
systemctl status docker
docker安装open webui
拉取并运行 Open WebUI 容器,将容器端口 8080 映射到主机 3000 端口
docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main
如果3000端口被占用了,会报错,重新启动也会提示错误如下。
报错解决:
docker run -d -p 6664:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main
docker: Error response from daemon: Conflict. The container name "/open-webui" is already in use by container "88f6e12e8e3814038911c30d788cb222d0792a9fc0af45f41140e07186e62a16". You have to remove (or rename) that container to be able to reuse that name.
你遇到的问题是 Docker 容器名称冲突。错误消息表明,容器名称 /open-webui 已经被另一个正在运行的容器占用,因此你无法启动新的容器。
(1)查看当前运行的容器: docker ps -a
88f6e12e8e38 ghcr.io/open-webui/open-webui:main "bash start.sh" 3 minutes ago Created open-webui
(2)停止并删除已有的容器
docker stop open-webui
docker rm open-webui
登录网址https://xxx:6664 配置即可访问。
My partner and I absolutely love your blog and find a lot of your post’s to be what precisely I’m looking for. Do you offer guest writers to write content available for you? I wouldn’t mind writing a post or elaborating on some of the subjects you write related to here. Again, awesome site!
Great beat ! I would like to apprentice while you amend your site, how can i subscribe for a blog site? The account helped me a acceptable deal. I had been tiny bit acquainted of this your broadcast provided bright clear concept