随着人工智能技术的飞速发展,自然语言处理(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 的版本
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
四、常见问题排查
端口冲突
使用 netstat -tuln | grep <端口号> 检查端口占用,修改配置文件中的端口后重启服务。
防火墙阻止
sudo ufw allow 50002/tcp # Ollama sudo ufw allow 50003/tcp # Ragflow
Docker 镜像下载慢
确保已配置国内镜像源,首次启动需耐心等待镜像下载完成。
GPU 支持问题
Ollama 需 PyTorch GPU 版本,安装前确认 CUDA 和 cuDNN 已正确安装。
五、性能优化建议
Ollama 缓存路径
在 ~/.ollama/config.json 中添加:
"OLLAMA_CACHE_DIR": "/path/to/large/storage"
Docker 资源限制
在 docker-compose.yml 中限制内存和CPU:
deploy: resources: limits: cpus: '2' memory: 8G
定期更新
# 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技术的应用和发展注入新的活力。
本文来源于#青花锁,由@蜜芽 整理发布。如若内容造成侵权/违法违规/事实不符,请联系本站客服处理!
该文章观点仅代表作者本人,不代表本站立场。本站不承担相关法律责任。
如若转载,请注明出处:https://www.zhanid.com/biancheng/3654.html