Linux系统安装Llama3的技巧

AI技术
小华
2025-06-20

在Linux系统上安装Llama3模型可以通过Ollama工具来实现,以下是详细的步骤和技巧:

安装Ollama

  1. 安装依赖项
sudo apt update && sudo apt install -y curl
  1. 一键安装Ollama
curl -fsSL https://ollama.com/install.sh | sh

或者,您可以先下载脚本查看内容,确认无误后再执行:

curl -fsSL https://ollama.com/install.sh -o install_ollama.sh
cat install_ollama.sh
bash install_ollama.sh

下载并运行Llama3模型

  1. 下载Llama3模型
ollama run llama3:8b

这将下载并运行8亿参数的Llama3模型。您也可以使用ollama run llama3来运行默认的8B模型。

使用OpenWebUI进行交互

  1. 安装Docker(如果尚未安装):
sudo apt-get install -y apt-transport-https ca-certificates curl python-software-properties software-properties-common
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/debian/gpg | sudo apt-key add -
# 根据您的Deepin Linux版本添加相应的Docker CE仓库
deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/debian buster stable
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
sudo systemctl start docker
sudo systemctl enable docker
  1. 安装OpenWebUI
docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main

或者使用国内下载源:

docker run -d -p 3000:8080 --network=host -v open-webui:/app/backend/data -e OLLAMA_BASE_URL=http://127.0.0.1:11434 --name open-webui --restart always ghcr.io/open-webui/open-webui:main

验证安装

  1. 启动Ollama服务
sudo systemctl start ollama
sudo systemctl status ollama

确认状态为“active (running)”。

  1. 运行模型
ollama run llama3:8b

这将启动与模型的交互界面,您可以在浏览器中访问http://localhost:3000来使用OpenWebUI。

常见问题及解决方法

  1. GPU未被识别
  • 验证CUDA驱动版本(需≥12.0),执行 nvidia-smi确认设备可见性,添加 --gpus=all启动参数。
  1. 端口冲突问题
  • 通过 lsof -i:11434检测端口占用,修改服务文件中的监听端口配置。
  1. 模型加载失败
  • 检查磁盘inode剩余数量(df -i),设置 OLLAMA_DEBUG=1输出详细日志。
  1. 中文理解问题
  • 使用王慎执博士微调后的中文版Llama3。在Hugging Face主页搜索“shenzhi”即可找到。
  1. 跨平台通用配置技巧
  • 设置 OLLAMA_ORIGINS="*"解除跨域限制,配置镜像仓库地址提升下载速度。
  • OLLAMA_KEEP_ALIVE=24h防止长时对话中断,OLLAMA_NUM_PARALLEL=100优化并发吞吐。
  • 启用TLS加密通信通过 OLLAMA_MAX_LOADED_MODELS=4限制内存占用。
  • 定期执行 ollama prune清理缓存。
亿速云提供售前/售后服务

售前业务咨询

售后技术保障

400-100-2938

7*24小时售后电话

官方微信小程序