
deepseek部署教程
1、此次教程为Ollama家用级本地模型部署,供个人测试使用并对 Ollama 做好安全策略以防止黑客攻击;
2、使用满血版的部署需要专业服务器,建议在1T内存+起码双H100 80G的推理服务器实现,可以选SGLANG框架或者VLLM框架;视硬件选择最优方案。
一、下载安装 Ollama
家用级部署DeepSeek要用到 Ollama,它支持多种大模型,Ollama官网https://ollama.com
下载安装Ollama,macOS、Linux 和 Windows都可以下载安装
linux安装:curl -fsSL https://ollama.com/install.sh | sh
macOS 和 windows 直接下载就行
注意:ollama 所需的GNU C 库(glibc)的版本为 2.27,但我使用的 centos7.9 默认提供的是 glibc 2.17,导致 glibc 版本低于 ollama 所需的版本,为了系统稳定性和安全性问题,不对 glibc 进行升级,故采用容器方式安装 ollama
运行 docker 有两种方式:
1、CPU 运行
[root@gpu-test 2t]# docker pull ollama/ollama
Using default tag: latest
latest: Pulling from ollama/ollama
d9802f032d67: Pull complete
161508c220d5: Pull complete
a5fe86995597: Pull complete
dfe8fac24641: Pull complete
Digest: sha256:74a0929e1e082a09e4fdeef8594b8f4537f661366a04080e600c90ea9f712721
Status: Downloaded newer image for ollama/ollama:latest
docker.io/ollama/ollama:latest
[root@gpu-test 2t]# mkdir ollama && cd ollama && docker run -d -v ./ollama:/root/.ollama -p 11111:11434 --name ollama ollama/ollama
2、GPU 运行
可参考官方文档:https://github.com/ollama/ollama/blob/main/docs/docker.md
[root@gpu-test ollama]# curl -s -L https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo | sudo tee /etc/yum.repos.d/nvidia-container-toolkit.repo
[root@gpu-test ollama]# yum install -y nvidia-container-toolkit
[root@gpu-test ollama]# nvidia-ctk runtime configure --runtime=docker
[root@gpu-test ollama]# systemctl restart docker
[root@gpu-test ollama]# docker run -d --gpus=all -v ./ollama:/root/.ollama -p 11111:11434 --name ollama ollama/ollama
安装完成后访问http://172.16.10.222:11111,出现Ollama is running即安装成功
以下是 Ollama 使用常见的指令:
ollama serve #启动ollama
ollama create #从模型文件创建模型
ollama show #显示模型信息
ollama run #运行模型
ollama pull #从注册表中拉取模型
ollama push #将模型推送到注册表
ollama list #列出模型
ollama cp #复制模型
ollama rm #删除模型
ollama help #获取有关任何命令的帮助信息
我的系统配置为:
[root@gpu-test 2t]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
[root@gpu-test 2t]# free -h
total used free shared buff/cache available
Mem: 125G 3.0G 122G 197M 535M 121G
Swap: 0B 0B 0B
[root@gpu-test 2t]# nvidia-smi
Thu Mar 20 10:54:15 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 550.78 Driver Version: 550.78 CUDA Version: 12.4 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA A800 80GB PCIe On | 00000000:01:00.0 Off | 0 |
| N/A 29C P0 44W / 300W | 1MiB / 81920MiB | 0% Default |
| | | Disabled |
+-----------------------------------------+------------------------+----------------------+
| 1 NVIDIA A800 80GB PCIe On | 00000000:C1:00.0 Off | 0 |
| N/A 30C P0 43W / 300W | 1MiB / 81920MiB | 0% Default |
| | | Disabled |
+-----------------------------------------+------------------------+----------------------+
+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
| No running processes found |
+-----------------------------------------------------------------------------------------+
[root@gpu-test 2t]# df -hT | grep 2t
/dev/nvme0n1 ext4 1.8T 77M 1.7T 1% /mnt/2t
二、下载运行deepseek-R1
进入Ollama官网,找到Models。
进入就可以看到deepseek-r1模型,如果没有,在搜索栏搜索即可。
选择对应的模型来下载,1.5b、7b、8b、14b、32b、70b或671b,这里有很多版本可选,模型越大,要求电脑内存、显卡等的配置越高。老韩这台机子还不错,选择70b的模型,不要羡慕哦😀;大家根据自己的机器配置来进行选择,具体硬件配置可以参考这篇文章。
使用命令来下载:ollama pull deepseek-R1:70b
由于模型比较大,依赖于网速,等待 pull 完成即可
root@2f4303a9d74f:/# ollama list
NAME ID SIZE MODIFIED
deepseek-R1:70b 0c1615a8ca32 42 GB 18 hours ago
效果:
三、open-webui部署
open-webui提供了一个基于浏览器的前端界面,用户可以方便地与运行中的模型进行交互,实现问答、文本生成等功能。
使用 Open WebUI 增强交互体验,只要是支持Ollama的webUI都可以,如Dify,AnythingLLM都可以。我这里用比较简单,而且也是与Ollama结合比较紧密的open-webui为例:
项目地址:https://github.com/open-webui/open-webui
学习地址:https://docs.openwebui.com
使用 docker 部署 open-webui
[root@gpu-test ollama]# docker pull ghcr.io/open-webui/open-webui:ollama
#我需要使用 google 的联网搜索服务,所以我这里使用了网络代理启动
[root@gpu-test ollama]# docker run -d \
--name open-webui \
-p 3000:8080 \
-v ./open-webui-data:/app/backend/data \
-e OLLAMA_URL="http://172.16.10.222:11111" \
-e HTTP_PROXY="http://172.16.10.130:7890" \
-e HTTPS_PROXY="http://172.16.10.130:7890" \
-e HF_ENDPOINT="https://hf-mirror.com" \
--restart always \
ghcr.io/open-webui/open-webui:main
注意:open-webui启动比较缓慢,需要等二三十秒左右, 直到docker日志中显示服务已经启动完成。
[root@gpu-test open-webui]# docker logs -f 5be51201e1273d10fd07c8041567c344c11804bd5c8d497bee8c979b4452969d
Loading WEBUI_SECRET_KEY from file, not provided as an environment variable.
Generating WEBUI_SECRET_KEY
Loading WEBUI_SECRET_KEY from .webui_secret_key
/app/backend/open_webui
/app/backend
/app
INFO [alembic.runtime.migration] Context impl SQLiteImpl.
INFO [alembic.runtime.migration] Will assume non-transactional DDL.
INFO [alembic.runtime.migration] Running upgrade -> 7e5b5dc7342b, init
INFO [alembic.runtime.migration] Running upgrade 7e5b5dc7342b -> ca81bd47c050, Add config table
INFO [alembic.runtime.migration] Running upgrade ca81bd47c050 -> c0fbf31ca0db, Update file table
INFO [alembic.runtime.migration] Running upgrade c0fbf31ca0db -> 6a39f3d8e55c, Add knowledge table
INFO [alembic.runtime.migration] Running upgrade 6a39f3d8e55c -> 242a2047eae0, Update chat table
INFO [alembic.runtime.migration] Running upgrade 242a2047eae0 -> 1af9b942657b, Migrate tags
INFO [alembic.runtime.migration] Running upgrade 1af9b942657b -> 3ab32c4b8f59, Update tags
INFO [alembic.runtime.migration] Running upgrade 3ab32c4b8f59 -> c69f45358db4, Add folder table
INFO [alembic.runtime.migration] Running upgrade c69f45358db4 -> c29facfe716b, Update file table path
INFO [alembic.runtime.migration] Running upgrade c29facfe716b -> af906e964978, Add feedback table
INFO [alembic.runtime.migration] Running upgrade af906e964978 -> 4ace53fd72c8, Update folder table and change DateTime to BigInteger for timestamp fields
INFO [alembic.runtime.migration] Running upgrade 4ace53fd72c8 -> 922e7a387820, Add group table
INFO [alembic.runtime.migration] Running upgrade 922e7a387820 -> 57c599a3cb57, Add channel table
INFO [alembic.runtime.migration] Running upgrade 57c599a3cb57 -> 7826ab40b532, Update file table
INFO [alembic.runtime.migration] Running upgrade 7826ab40b532 -> 3781e22d8b01, Update message & channel tables
INFO [open_webui.env] 'DEFAULT_LOCALE' loaded from the latest database entry
INFO [open_webui.env] 'DEFAULT_PROMPT_SUGGESTIONS' loaded from the latest database entry
WARNI [open_webui.env]
WARNING: CORS_ALLOW_ORIGIN IS SET TO '*' - NOT RECOMMENDED FOR PRODUCTION DEPLOYMENTS.
INFO [open_webui.env] Embedding model set: sentence-transformers/all-MiniLM-L6-v2
WARNI [langchain_community.utils.user_agent] USER_AGENT environment variable not set, consider setting it to identify your requests.
Creating knowledge table
Migrating data from document table to knowledge table
Converting 'chat' column to JSON
Renaming 'chat' column to 'old_chat'
Adding new 'chat' column of type JSON
Dropping 'old_chat' column
Primary Key: {'name': None, 'constrained_columns': []}
Unique Constraints: [{'name': 'uq_id_user_id', 'column_names': ['id', 'user_id']}]
Indexes: [{'name': 'tag_id', 'column_names': ['id'], 'unique': 1, 'dialect_options': {}}]
Creating new primary key with 'id' and 'user_id'.
Dropping unique constraint: uq_id_user_id
Dropping unique index: tag_id
██████╗ ██████╗ ███████╗███╗ ██╗ ██╗ ██╗███████╗██████╗ ██╗ ██╗██╗
██╔═══██╗██╔══██╗██╔════╝████╗ ██║ ██║ ██║██╔════╝██╔══██╗██║ ██║██║
██║ ██║██████╔╝█████╗ ██╔██╗ ██║ ██║ █╗ ██║█████╗ ██████╔╝██║ ██║██║
██║ ██║██╔═══╝ ██╔══╝ ██║╚██╗██║ ██║███╗██║██╔══╝ ██╔══██╗██║ ██║██║
╚██████╔╝██║ ███████╗██║ ╚████║ ╚███╔███╔╝███████╗██████╔╝╚██████╔╝██║
╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═══╝ ╚══╝╚══╝ ╚══════╝╚═════╝ ╚═════╝ ╚═╝
v0.5.20 - building the best open-source AI user interface.
https://github.com/open-webui/open-webui
Fetching 30 files: 100%|██████████| 30/30 [00:23<00:00, 1.25it/s]
INFO: Started server process [1]
INFO: Waiting for application startup.
2025-03-20 11:18:28.797 | INFO | open_webui.utils.logger:start_logger:140 - GLOBAL_LOG_LEVEL: INFO - {}
配置open-webui与ollama连接
访问http://172.16.10.222:3000
点击开始使用,创建管理员账号
模型添加
设置--->管理员设置--->外部连接--->按情况添加等
开始对话
四、常见问题与解决方法
问题 1: Ollama 下载模型失败
解决方法:检查你的网络连接是否稳定。你可以尝试更换网络环境或重启下载。如果问题持续存在,尝试清空 Ollama 的缓存并重新启动。
问题 2: WebUI 显示 500 错误
解决方法:查看 Open-WebUI 的日志,确认是否有报错信息。如果日志中有关于依赖库缺失或配置错误的提示,按照提示进行修复。
问题 3: WebUI 无法连接到外部 Ollama
解决方法:确认 Ollama 和 Open-WebUI网路互通,且 Ollama 服务已正常启动。如果没有,重新启动 Ollama 或检查网络设置。特别需要提到的是:如果本地host方式启动的Ollama 服务,需要设置: OLLAMA_ORIGINS="*" OLLAMA_HOST=0.0.0.0:11111;WebUI管理员页面配置Ollama时,Ollama的地址需要填写实际地址:http://<实际IP地址>:11111
问题 4: Open-WebUI启动后,页面打开显示空白
解决方法:Open-WebUI启动比较缓慢,需要等待一段时间, 直到docker日志中显示服务已经启动完成。