593 字
3 分钟
DeepSeek 本地部署
2025-02-07

背景#

在 2025 的新年中,DeepSeek 推出了R1 模型,对标 openai 的 o1 模型,并提供了本地部署方案,本文主要介绍本地部署方案。

部署#

我这里是使用的 macmini 部署的,配置如下:

  • 处理器:M4
  • 内存:16GB
  • 硬盘:512GB

主要用到以下工具

  • Docker: 容器化部署
  • Ollama: 本地部署模型
  • Open Web UI: 本地部署 UI

安装 Docker#

官网安装#

Docker 官网

使用 Homebrew 安装#

brew install docker

验证#

docker --version

安装 Ollama#

官网安装#

Ollama 官网

使用 Homebrew 安装#

brew install ollama

验证#

ollama --version

配置#

  1. 创建并编辑配置文件
nano ~/Library/LaunchAgents/com.user.ollama.service.plist
  1. 添加以下内容: 配置文件中写入下面内容;定义了服务方式运行,以及做了跨域设置。使得内网其他的网络访问被允许
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.user.ollama.service</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/bin/ollama</string>
        <string>serve</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/tmp/ollama.err</string>
    <key>StandardOutPath</key>
    <string>/tmp/ollama.out</string>
    <key>EnvironmentVariables</key>
    <dict>
        <key>OLLAMA_HOST</key>
        <string>0.0.0.0</string>
        <key>Ollama_ORIGINS</key>
        <string>*</string>
    </dict>
</dict>
</plist>
  1. 赋予权限,启动服务
chmod 644 ~/Library/LaunchAgents/com.user.ollama.service.plist
launchctl load ~/Library/LaunchAgents/com.user.ollama.service.plist

安装 Open Web UI#

docker-compose.yml 文件如下:

services:
  open-webui:
    image: ghcr.io/open-webui/open-webui:main
    restart: always
    ports:
      - "3000:8080"
    volumes:
      - ./open-webui:/app/backend/data

  watchtower:
    image: containrrr/watchtower
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command: --interval 300 open-webui
    depends_on:
      - open-webui

启动#

docker-compose up -d

验证#

docker-compose ps

安装模型#

如果上述内容都安装成功,那么进入浏览器输入 http://localhost:3000 即可看到 Open Web UI 的 UI 界面。

设置 open web ui 关联 ollama#

进入 open web ui 的界面,点击左下角头像,进入设置界面,选择 管理员设置 -> 外部链接 选项,在管理Ollama API连接选项下填写地址 http://host.docker.internal:11434,确保按钮启用,点击 保存 按钮,即可完成设置。

拉取模型#

进入ollama 模型官网,搜索 deepseek 模型,选择 deepseek-r1 模型,选择模型大小,根据你的机器性能选择,我这里选择 14b 模型,点击复制命令,进入终端执行命令,即可拉取模型。

ollama pull deepseek-r1:14b
NOTE

模型大小选择,根据你机器的可用内存,选择合适的模型。通常情况下可以这样计算,你机器的可用内存需要大于模型占用的硬盘存储空间。注意:这里计算的是机器内存和占用硬盘存储空间

alt text

测试模型#

进入 open web ui 的界面,左上角选择模型,选择 deepseek-r1 模型,进行对话测试。

alt text

alt text

DeepSeek 本地部署
https://www.mihouo.com/posts/tool-share/deepseek-local-deploy/
作者
发布于
2025-02-07
许可协议
CC BY-NC-SA 4.0