2条命令本地部署deepseek
- Ai
- 2025-02-10
- 146热度
- 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。如您有任何任何问题,我会尽我所能为您提供帮助。
支持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