ollama离线部署+大语言模型

环境要求

  • Ubuntu >= 22.04
  • NVIDIA GPU

一.安装ollama客户端

资源来源

所有版本安装包 安装脚本
https://github.com/ollama/ollama/releases/ https://ollama.com/install.sh

安装

1. 下载资源

bash 复制代码
mkdir -p /root/ollama/
cd  /root/ollama
wget 'https://github.com/ollama/ollama/releases/download/v0.5.13/ollama-linux-amd64.tgz'
wget 'https://ollama.com/install.sh'

2. 修改安装脚本内容 : install.sh

bash 复制代码
#注释下面三行代码,并添加一行代码
#curl --fail --show-error --location --progress-bar \
#"https://ollama.com/download/ollama-linux-${ARCH}.tgz${VER_PARAM}" | \
#$SUDO tar -xzf - -C "$OLLAMA_INSTALL_DIR"  
$SUDO tar -xzf /root/ollama/ollama-linux-${ARCH}.tgz -C "$OLLAMA_INSTALL_DIR" 

3. 执行安装命令

bash install.sh

4. 检测安装

ollama --version

5. 修改环境变量

vim /etc/systemd/system/ollama.service

bash 复制代码
# 在原有的Environment下,添加一下内容
Environment="OLLAMA_HOST=0.0.0.0:11434" #允许其他ip地址请求访问
Environment="OLLAMA_NUM_PARALLEL=4" #并行处理请求的数量
Environment="OLLAMA_MAX_LOADED_MODELS=4" #同时加载的模型数量

sudo systemctl daemon-reload
systemctl stop ollama

6. 启动服务

ollama serve

// 或
sudo systemctl start ollama

// 或
nohup ollama serve &

7.关闭服务

service ollama stop

二.部署模型

资源来源

模型仓库 地址
ModelScope https://modelscope.cn/models/unsloth/DeepSeek-R1-Distill-Qwen-14B-GGUF/files
Huggingface https://huggingface.co

安装

1. 下载资源

复制代码
  说明:将下载好的GGUF格式的大模型文件上传到服务器中,如果是多个分片需要合并。
  注意:ollama需要使用GGUF格式文件,如果模型仓库没有,需要自己转换。
模型 下载链接
DeepSeek-R1-Distill-Qwen-7B https://modelscope.cn/models/unsloth/DeepSeek-R1-Distill-Qwen-7B-GGUF/resolve/master/DeepSeek-R1-Distill-Qwen-7B-Q4_K_M.gguf
DeepSeek-R1-Distill-Qwen-14B https://modelscope.cn/models/unsloth/DeepSeek-R1-Distill-Qwen-14B-GGUF/resolve/master/DeepSeek-R1-Distill-Qwen-14B-Q4_K_M.gguf
DeepSeek-R1-Distill-Qwen-32B https://modelscope.cn/models/unsloth/DeepSeek-R1-Distill-Qwen-32B-GGUF/resolve/master/DeepSeek-R1-Distill-Qwen-32B-Q4_K_M.gguf
DeepSeek-R1 https://modelscope.cn/models/lmstudio-community/DeepSeek-R1-GGUF/resolve/master/DeepSeek-R1-Q4_K_M-00001-of-00011.gguf
QwQ-32B https://modelscope.cn/models/Qwen/QwQ-32B-GGUF/resolve/master/qwq-32b-q4_0-00001-of-00005.gguf
Qwen2.5-14B-Instruct https://modelscope.cn/models/Qwen/Qwen2.5-14B-Instruct-GGUF/resolve/master/qwen2.5-14b-instruct-q4_0-00001-of-00003.gguf

2. 合并GGUF(可选)*

安装llama.cpp预编译工具

bash 复制代码
# 示例版本 b5162,请替换为最新版本号
wget https://github.com/ggerganov/llama.cpp/releases/download/b5162/llama-b5162-bin-ubuntu-vulkan-x64.zip

mkdir -p ~/llama_tools   # 自定义工具存放目录
unzip -j llama-b5162-bin-ubuntu-vulkan-x64.zip 'build/bin/*' -d ~/llama_tools
chmod +x ~/llama_tools/*

合并GGUF分片

bash 复制代码
cd ~/llama_tools

./llama-gguf-split --merge \
  ~/models/DeepSeek-V3-Q3/DeepSeek-V3-0324-Q3_K_M-00001-of-00007.gguf \
  ~/models/DeepSeek-V3-Q3/DeepSeek-V3-Q3_Merged.gguf

// 参数说明:
// --merge:合并模式;
// 第一个参数:任意一个分片文件路径;
// 第二个参数:合并后完整 GGUF 文件的输出路径。

3. 创建Modelfile文件

复制代码
参考:https://github.com/ollama/ollama/blob/main/docs/modelfile.md#format
例如:Qwen2.5-14B.Modelfile
bash 复制代码
# 文件内容为模型的路径
FROM /root/Qwen2.5-14B-Instruct.gguf
PARAMETER temperature 0.7
PARAMETER top_p 0.7
PARAMETER stop "<|im_start|>"
PARAMETER stop "<|im_end|>"
TEMPLATE """{{ if .System }}<|im_start|>system
{{ .System }}<|im_end|>
{{ end }}{{ if .Prompt }}<|im_start|>user
{{ .Prompt }}<|im_end|>
{{ end }}<|im_start|>assistant
{{ .Response }}<|im_end|>
"""
SYSTEM """You are a helpful assistant."""

4. 创建模型

使用ollama创建模型,model_name可自定义
ollama create <model_name> -f <path_to_Modelfile>

5. 查看模型

ollama list

三.GGUF格式转换(可选)*

1. 安装

执行以下命令安装llama.cpp环境
git clone https://github.com/ggerganov/llama.cpp.git
cd llama.cpp
pip install -r requirements.txt

2. 生成GGUF

例如:qwen2_0.5b_instruct

// 如果不量化,保留模型的效果
python llama.cpp/convert_hf_to_gguf.py ./qwen2_0.5b_instruct --outtype f16 --verbose --outfile qwen2_0.5b_instruct_f16.gguf

// 量化
python llama.cpp/convert_hf_to_gguf.py ./qwen2_0.5b_instruct --outtype q8_0 --verbose --outfile qwen2_0.5b_instruct_q8_0.gguf

相关推荐
Geek-Chow4 小时前
05.4 · DeepInfer 推理框架总览:源码结构、开源与未开源部分对照
人工智能
Flynn Liang4 小时前
Spring AI 多模态实战(下):文生图 + TTS 语音合成(含 2.0 流式音频分片)
人工智能·spring·文生图·音视频·语音合成·tts·springai
长不大的杨瑞杰4 小时前
OpenCode v2 Custom Tools 实战:开发数据库、工单与发布工具
人工智能·typescript·开发工具·opencode·custom tools
羊仔AI探索4 小时前
离世仅仅半个月,张雪峰被蒸馏了
人工智能·aigc·蒸馏·张雪峰·skills
zhippt_10144 小时前
只剩截图没有源文件?图转PPT把图片还原成可编辑幻灯片
前端·人工智能·powerpoint
小oo呆4 小时前
【自然语言处理与大模型】自然语言处理的漫漫长路之深度学习时代
人工智能·深度学习·自然语言处理
JavaPub-rodert4 小时前
AI Agent 的记忆系统怎么设计?从短期记忆、长期记忆到 RAG,讲透 Memory 工程化
人工智能
智恒百亿4 小时前
一台 5090 八卡服务器怎么分给一个团队用?多模型多任务的显存分配实战
java·大数据·人工智能
MCT1236544 小时前
AI VRM 高频设计|功率电感磁材选型与电源损耗、效率关系
人工智能·dc-dc电源·功率电感·一体成型电感
汤姆宝库4 小时前
安全深拆:越狱、Sleeper与可解释性
人工智能