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

相关推荐
水如烟1 分钟前
孤能子视角:原始思维篇·0 总纲——关系场的直接编织:认知的底层呼吸
人工智能
Luminbox紫创测控2 分钟前
太阳模拟器如何模拟真实太阳?积分球与氙灯光源技术解析
人工智能·测试工具·安全性测试·uv·测试标准
mlidongfeng3 分钟前
[AI][shmem] Aiv 直驱RDMA
人工智能
九硕智慧建筑一体化厂家10 分钟前
从电费支出到碳资产收益,直流照明如何让商业楼宇实现柔性用能
运维·人工智能·智慧城市
资深电气设计17 分钟前
800V直流断路器选型指南:ABB电气产品技术解析
人工智能·科技·创业创新·业界资讯
梦想的旅途228 分钟前
企业微信API二次开发:接入 AI 大模型实现外部群智能问答
人工智能·自动化·二次开发·企业微信
碧口科技29 分钟前
湿地鸟类监测设备选型指南:复杂环境下的智能识别系统怎么选?
人工智能
2601_9494999430 分钟前
硬件工程师实操:芯瑞科技两款 400G 高速互联方案参数、场景、选型全解析
大数据·运维·人工智能·科技·光模块
极昆仑智慧31 分钟前
智能问数五级成熟度模型:从“能问“到“能协作“的演进路径
人工智能·语言模型·数据分析
火云牌神34 分钟前
如何用项目规则给 AI 划定编码边界
人工智能·系统架构·ai编程·vibecoding