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

发布于:2025-03-25 ⋅ 阅读:(14) ⋅ 点赞:(0)

🌹作者主页:青花锁 🌹简介:Java领域优质创作者🏆、Java微服务架构公号作者😄

🌹简历模板、学习资料、面试题库、技术互助

🌹文末获取联系方式 📝

在这里插入图片描述



一、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 的版本

在这里插入图片描述
3、使用旧版本的 HTTP 协议
如果问题仍然存在,尝试使用 HTTP/1.1 而不是 HTTP/2。可以通过添加 --http1.1 参数到你的 curl 命令中:

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

在这里插入图片描述
在这里插入图片描述

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
在这里插入图片描述

1.4.1、模型下载配置建议

询问文心一言,给出的指导建议
在这里插入图片描述

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

例如:选中14b,复制命令:ollama run deepseek-r1:14b
在这里插入图片描述
安装过程, 等待进度100%
在这里插入图片描述
在这里插入图片描述


二、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


网站公告

今日签到

点亮在社区的每一天
去签到