Ubuntu 系统部署 Ollama + DeepSeek + Docker + Ragflow

青花锁 2025-03-26 11:57:13编程技术
612

随着人工智能技术的飞速发展,自然语言处理(NLP)模型在各个领域的应用越来越广泛。Ollama和DeepSeek作为当前领先的NLP模型,其强大的功能和灵活性使其在各种应用场景中备受青睐。为了更好地利用这些模型,许多开发者和企业选择在本地环境中进行部署。本文将详细介绍如何在Ubuntu系统上使用Docker和Ragflow部署Ollama和DeepSeek,帮助读者实现高效、稳定的本地化部署。

一、Ollama 安装与端口配置

1.1 一键安装

curl -fsSL https://ollama.com/install.sh | sh

错误

curl: (56) OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while reading, errno 0

 

 

gzip: stdin: unexpected end of file

tar: Child returned status 1

tar: Error is not recoverable: exiting now

解决方法

1、更新 Curl 和相关软件

首先,确保你的 curl 和其他相关软件(如 tar)是最新版本。可以通过以下命令更新:

 sudo apt update

2、检查 Curl 的 HTTP2 支持

确保你的 curl 支持 HTTP/2。可以通过以下命令查看:

curl --version

查看输出中是否包含 “HTTP2” 支持。如果没有,你可能需要重新安装支持 HTTP/2 的 curl 版本:

sudo apt install curl  # 通常会自动安装支持 HTTP/2 的版本

Ubuntu 系统部署 Ollama + DeepSeek + Docker + Ragflow

3、使用旧版本的 HTTP 协议

如果问题仍然存在,尝试使用 HTTP/1.1 而不是 HTTP/2。可以通过添加 --http1.1 参数到你的 curl 命令中:

curl --http1.1  -fsSL https://ollama.com/install.sh | sh

Ubuntu 系统部署 Ollama + DeepSeek + Docker + Ragflow

Ubuntu 系统部署 Ollama + DeepSeek + Docker + Ragflow

1.2 修改默认端口(11434 → 50002)

方法1:永久生效(推荐)

# 创建配置文件
mkdir -p ~/.ollama && echo '{"OLLAMA_HOST": "0.0.0.0:50002"}' > ~/.ollama/config.json

# 重启服务
sudo systemctl restart ollama

方法2:临时生效

export OLLAMA_HOST="0.0.0.0:50002"  # 或使用 OLLAMA_PORT=50002
ollama serve

方法3:设置开机自启

sudo tee /etc/systemd/system/ollama.service <<EOF
[Service]
Environment="OLLAMA_HOST=0.0.0.0:50002"
EOF

sudo systemctl daemon-reload && sudo systemctl restart ollama

1.3 验证服务状态

systemctl status ollama
curl http://localhost:50002/health  # 应返回 {"status": "healthy"}

1.4 在ollama里安装deepSeek r1模型

找到ollama里的模型下载地址:https://ollama.com/library/deepseek-r1

Ubuntu 系统部署 Ollama + DeepSeek + Docker + Ragflow

1.4.1、模型下载配置建议

询问文心一言,给出的指导建议

Ubuntu 系统部署 Ollama + DeepSeek + Docker + Ragflow

1.4.2、根据电脑配置,选择一个安装

例如:选中14b,复制命令:ollama run deepseek-r1:14b

Ubuntu 系统部署 Ollama + DeepSeek + Docker + Ragflow

安装过程, 等待进度100%

Ubuntu 系统部署 Ollama + DeepSeek + Docker + Ragflow

Ubuntu 系统部署 Ollama + DeepSeek + Docker + Ragflow

二、Docker 安装与优化

2.1 安装前准备

sudo apt update && sudo apt upgrade -y

# 卸载旧版本(如有)
sudo apt remove docker docker-engine docker.io containerd runc -y

2.2 安装依赖项

sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y

2.3 添加官方源并安装

# 添加 GPG 密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

# 添加 APT 源
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

# 安装 Docker
sudo apt update && sudo apt install docker-ce docker-ce-cli containerd.io -y

2.4 配置国内镜像加速

sudo tee /etc/docker/daemon.json <<EOF
{
  "registry-mirrors": [
    "https://docker.mirrors.ustc.edu.cn",
    "https://reg-mirror.qiniu.com"
  ]
}
EOF

sudo systemctl restart docker

2.5 验证安装

docker --version
docker info | grep -A4 "Registry Mirrors"  # 检查镜像加速是否生效

三、Ragflow 部署指南

3.1 下载代码

git clone https://github.com/infiniflow/ragflow.git
cd ragflow/docker

3.2 修改配置

# 修改 .env 文件
sed -i 's/infiniflow\/ragflow:v0.16.0-slim/#infiniflow\/ragflow:v0.16.0-slim/g' .env

# 修改端口(示例改为50003)
sed -i 's/5000/50003/g' docker-compose.yml

3.3 启动服务

docker compose up -d

3.4 查看日志与访问

docker logs -f ragflow-server  # 实时查看日志
curl http://localhost:50003    # 或浏览器访问 http://服务器IP:50003

四、常见问题排查

  1. 端口冲突

    使用 netstat -tuln | grep <端口号> 检查端口占用,修改配置文件中的端口后重启服务。

  2. 防火墙阻止

    sudo ufw allow 50002/tcp  # Ollama
    sudo ufw allow 50003/tcp  # Ragflow
  3. Docker 镜像下载慢

    确保已配置国内镜像源,首次启动需耐心等待镜像下载完成。

  4. GPU 支持问题

    Ollama 需 PyTorch GPU 版本,安装前确认 CUDA 和 cuDNN 已正确安装。

五、性能优化建议

  1. Ollama 缓存路径

    在 ~/.ollama/config.json 中添加:

    "OLLAMA_CACHE_DIR": "/path/to/large/storage"
  2. Docker 资源限制

    在 docker-compose.yml 中限制内存和CPU:

    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 8G
  3. 定期更新

    # Ollama
    sudo systemctl stop ollama && ollama update && sudo systemctl start ollama
    
    # Docker
    sudo apt update && sudo apt upgrade docker-ce -y

完成部署后,您可通过以下架构享受本地AI服务:

在浏览器打开:http://127.0.0.1:50003

总结

通过本文的介绍,我们详细探讨了在Ubuntu系统上使用Docker和Ragflow部署Ollama和DeepSeek的方法和技巧。从环境准备、Docker镜像构建、模型加载到性能优化,每一个环节都进行了深入解析。希望这些内容能够帮助读者在实际操作中更加得心应手,实现高效、稳定的本地化部署。未来,随着技术的不断进步,我们期待看到更多创新的部署方法和技巧,为AI技术的应用和发展注入新的活力。

Ubuntu Ollama DeepSeek Docker Ragflow
THE END
蜜芽
故事不长,也不难讲,四字概括,毫无意义。

相关推荐

Gen-CLI:基于DeepSeek的AI命令行编程工具,谷歌Gemini-CLI平替方案
Gen-CLI是一个开源的命令行编程工具,旨在为国内开发者提供类似于谷歌Gemini-CLI的AI辅助编程体验。该项目基于开源的Gemini-CLI进行改造,通过调用硅基流动(SiliconCloud)平台...
2025-07-09 新闻资讯
262

本地部署大模型必知:llama、ollama与llama.cpp的区别详解
在本地部署大型语言模型(LLM)时,Llama、Ollama和Llama.cpp是三个高频出现的关键词。三者看似关联紧密,但定位与功能差异显著。本文ZHANID工具网将从技术架构、应用场景、性...
2025-04-28 编程技术
780

springBoot集成Ollama大模型及流式传输的问题小结
随着人工智能技术的快速发展,大型语言模型在各个领域的应用越来越广泛。Spring Boot作为一种流行的微服务框架,与Ollama大模型的集成可以为企业带来诸多便利。本文将总结Spr...
2025-04-27 编程技术
399

DeepSite:基于DeepSeek V3的AI前端网页代码生成工具
DeepSite是一个基于AI的网站生成工具,用户只需输入简单的文字描述,就能快速生成一个实时可运行的前端网页。它由Hugging Face社区成员enzostvs开发,依托强大的DeepSeek V3(...
2025-04-14 新闻资讯
777

使用Docker和cpolar在Ubuntu上部署可远程访问的Android模拟器
本文将介绍一种在Linux Ubuntu系统上使用Docker部署Android模拟器,并通过cpolar内网穿透工具实现远程访问的全新方案。通过这一方案,开发者可以轻松地在任何地方通过公网地址...
2025-03-28 编程技术
399

​美图WHEE接入DeepSeek R1,提示词优化可自动补全关键词
近日,美图公司旗下的 AI 素材生成器 WHEE 宣布与 DeepSeek R1满血版成功接入。这一合作旨在将 DeepSeek 的专业提示词设计能力与 WHEE 的易用性相结合,帮助用户在无专业背景...
2025-03-27 新闻资讯
372