首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >ollama 离线安装本地模型

ollama 离线安装本地模型

作者头像
云技术以及云存储
发布2025-10-31 18:27:05
发布2025-10-31 18:27:05
3980
举报
文章被收录于专栏:云技术与云技术与

1 环境

以下是以centos 7.9.2009 安装ollama为例

[docker@**-**-**-50 ~]$ cat /etc/redhat-release

CentOS Linux release 7.9.2009 (Core)

[docker@**-**-**-50 ~]$

2.下载ollama安装包

可以直接浏览器下载

官网地址:https://ollama.com/download/linux

GitHub手动安装文档地址:https://github.com/ollama/ollama/blob/main/docs/linux.md

安装包下载地址:https://ollama.com/download/ollama-linux-amd64.tgz

3.上传到服务器

[docker@**-**-**-50 hyh]$ ls -l

total 1642996

-rwxr-x--- 1 docker docker 13921 Feb 7 14:27 install.sh

-rw-r----- 1 docker docker 1682401421 Feb 6 10:27 ollama-linux-amd64.tgz

-rw-r----- 1 docker docker 2569 Feb 6 10:00 wget-log

[docker@**-**-**-50 hyh]$

4. 下载安装脚本install.sh

下载 https://ollama.com/install.sh,编辑如下

修改安装路径改成本地安装

#!/bin/sh

# This script installs Ollama on Linux.

# It detects the current operating system architecture and installs the appropriate version of Ollama.

set -eu

status() { echo ">>> $*" >&2; }

error() { echo "ERROR $*"; exit 1; }

warning() { echo "WARNING: $*"; }

TEMP_DIR=$(mktemp -d)

cleanup() { rm -rf $TEMP_DIR; }

trap cleanup EXIT

available() { command -v $1 >/dev/null; }

require() {

local MISSING=''

for TOOL in $*; do

if ! available $TOOL; then

MISSING="

fi

done

echo $MISSING

}

[ "$(uname -s)" = "Linux" ] || error 'This script is intended to run on Linux only.'

ARCH=$(uname -m)

case "$ARCH" in

x86_64) ARCH="amd64" ;;

aarch64|arm64) ARCH="arm64" ;;

*) error "Unsupported architecture: $ARCH" ;;

esac

IS_WSL2=false

KERN=$(uname -r)

case "$KERN" in

*icrosoft*WSL2 | *icrosoft*wsl2) IS_WSL2=true;;

*icrosoft) error "Microsoft WSL1 is not currently supported. Please use WSL2 with 'wsl --set-version2'" ;;

*) ;;

esac

VER_PARAM="

SUDO=

if [ "$(id -u)" -ne 0 ]; then

# Running as root, no need for sudo

if ! available sudo; then

error "This script requires superuser permissions. Please re-run as root."

fi

SUDO="sudo"

fi

NEEDS=$(require curl awk grep sed tee xargs)

if [ -n "$NEEDS" ]; then

status "ERROR: The following tools are required but missing:"

for NEED in $NEEDS; do

echo " - $NEED"

done

exit 1

fi

for BINDIR in /usr/local/bin /usr/bin /bin; do

echo PATH | grep -q BINDIR && break || continue

done

OLLAMA_INSTALL_DIR=(dirname {BINDIR})

status "Installing ollama to $OLLAMA_INSTALL_DIR"

SUDO install -o0 -g0 -m755 -d BINDIR

SUDO install -o0 -g0 -m755 -d "

#if curl -I --silent --fail --location "https://ollama.com/download/ollama-linux-

#注释掉以下代码

# status "Downloading Linux ${ARCH} bundle"

# curl --fail --show-error --location --progress-bar \

# "https://ollama.com/download/ollama-linux-

# SUDO tar -xzf - -C "

# BUNDLE=1

# if [ "

# status "Making ollama accessible in the PATH in $BINDIR"

# SUDO ln -sf "

# fi

#else

# status "Downloading Linux ${ARCH} CLI"

# curl --fail --show-error --location --progress-bar -o "$TEMP_DIR/ollama"\

# "https://ollama.com/download/ollama-linux-

# SUDO install -o0 -g0 -m755 TEMP_DIR/ollama

# BUNDLE=0

# if [ "

# status "Making ollama accessible in the PATH in $BINDIR"

# SUDO ln -sf "

# fi

#fi

#新增以下代码

LOCAL_OLLAMA_TGZ="./ollama-linux-${ARCH}.tgz"

if [ -f "$LOCAL_OLLAMA_TGZ" ]; then

status "Installing from local file $LOCAL_OLLAMA_TGZ"

SUDO tar -xzf "

BUNDLE=1

if [ ! -e "$BINDIR/ollama" ]; then

status "Making ollama accessible in the PATH in $BINDIR"

SUDO ln -sf "

fi

else

echo "Error: The local file $LOCAL_OLLAMA_TGZ does not exist."

exit 1

fi

install_success() {

status 'The Ollama API is now available at 127.0.0.1:11434.'

status 'Install complete. Run "ollama" from the command line.'

}

trap install_success EXIT

# Everything from this point onwards is optional.

configure_systemd() {

if ! id ollama >/dev/null 2>&1; then

status "Creating ollama user..."

$SUDO useradd -r -s /bin/false -U -m -d /usr/share/ollama ollama

fi

if getent group render >/dev/null 2>&1; then

status "Adding ollama user to render group..."

$SUDO usermod -a -G render ollama

fi

if getent group video >/dev/null 2>&1; then

status "Adding ollama user to video group..."

$SUDO usermod -a -G video ollama

fi

status "Adding current user to ollama group..."

SUDO usermod -a -G ollama (whoami)

status "Creating ollama systemd service..."

cat </dev/null

[Unit]

Description=Ollama Service

After=network-online.target

[Service]

ExecStart=$BINDIR/ollama serve

User=ollama

Group=ollama

Restart=always

RestartSec=3

Environment="PATH=$PATH"

[Install]

WantedBy=default.target

EOF

SYSTEMCTL_RUNNING="$(systemctl is-system-running || true)"

case $SYSTEMCTL_RUNNING in

running|degraded)

status "Enabling and starting ollama service..."

$SUDO systemctl daemon-reload

$SUDO systemctl enable ollama

start_service() { $SUDO systemctl restart ollama; }

trap start_service EXIT

;;

esac

}

if available systemctl; then

configure_systemd

fi

# WSL2 only supports GPUs via nvidia passthrough

# so check for nvidia-smi to determine if GPU is available

if [ "$IS_WSL2" = true ]; then

if available nvidia-smi && [ -n "$(nvidia-smi | grep -o "CUDA Version: [0-9]*\.[0-9]*")" ]; then

status "Nvidia GPU detected."

fi

install_success

exit 0

fi

# Install GPU dependencies on Linux

if ! available lspci && ! available lshw; then

warning "Unable to detect NVIDIA/AMD GPU. Install lspci or lshw to automatically detect and install GPU dependencies."

exit 0

fi

check_gpu() {

# Look for devices based on vendor ID for NVIDIA and AMD

case $1 in

lspci)

case $2 in

nvidia) available lspci && lspci -d '10de:' | grep -q 'NVIDIA' || return 1 ;;

amdgpu) available lspci && lspci -d '1002:' | grep -q 'AMD' || return 1 ;;

esac ;;

lshw)

case $2 in

nvidia) available lshw && $SUDO lshw -c display -numeric -disable network | grep -q 'vendor: .* \[10DE\]' || return 1 ;;

amdgpu) available lshw && $SUDO lshw -c display -numeric -disable network | grep -q 'vendor: .* \[1002\]' || return 1 ;;

esac ;;

nvidia-smi) available nvidia-smi || return 1 ;;

esac

}

if check_gpu nvidia-smi; then

status "NVIDIA GPU installed."

exit 0

fi

if ! check_gpu lspci nvidia && ! check_gpu lshw nvidia && ! check_gpu lspci amdgpu && ! check_gpu lshw amdgpu; then

install_success

warning "No NVIDIA/AMD GPU detected. Ollama will run in CPU-only mode."

exit 0

fi

if check_gpu lspci amdgpu || check_gpu lshw amdgpu; then

if [ $BUNDLE -ne 0 ]; then

status "Downloading Linux ROCm ${ARCH} bundle"

curl --fail --show-error --location --progress-bar \

"https://ollama.com/download/ollama-linux-

SUDO tar -xzf - -C "

install_success

status "AMD GPU ready."

exit 0

fi

# Look for pre-existing ROCm v6 before downloading the dependencies

for search in "

if [ -n "

status "Compatible AMD GPU ROCm library detected at ${search}"

install_success

exit 0

fi

done

status "Downloading AMD GPU dependencies..."

$SUDO rm -rf /usr/share/ollama/lib

$SUDO chmod o+x /usr/share/ollama

$SUDO install -o ollama -g ollama -m 755 -d /usr/share/ollama/lib/rocm

curl --fail --show-error --location --progress-bar "https://ollama.com/download/ollama-linux-amd64-rocm.tgz${VER_PARAM}" \

| $SUDO tar zx --owner ollama --group ollama -C /usr/share/ollama/lib/rocm .

install_success

status "AMD GPU ready."

exit 0

fi

CUDA_REPO_ERR_MSG="NVIDIA GPU detected, but your OS and Architecture are not supported by NVIDIA. Please install the CUDA driver manually https://docs.nvidia.com/cuda/cuda-installation-guide-linux/"

# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#rhel-7-centos-7

# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#rhel-8-rocky-8

# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#rhel-9-rocky-9

# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#fedora

install_cuda_driver_yum() {

status 'Installing NVIDIA repository...'

case $PACKAGE_MANAGER in

yum)

SUDO PACKAGE_MANAGER -y install yum-utils

if curl -I --silent --fail --location "https://developer.download.nvidia.com/compute/cuda/repos/(uname -m | sed -e 's/aarch64/sbsa/')/cuda-1

SUDO PACKAGE_MANAGER-config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/12/(uname -m | sed -e 's/aarch64/sbsa/')/cuda-1

else

error $CUDA_REPO_ERR_MSG

fi

;;

dnf)

if curl -I --silent --fail --location "https://developer.download.nvidia.com/compute/cuda/repos/(uname -m | sed -e 's/aarch64/sbsa/')/cuda-1

SUDO PACKAGE_MANAGER config-manager --add-repo https://developer.download.nvidia.com/compute/cuda/repos/12/(uname -m | sed -e 's/aarch64/sbsa/')/cuda-1

else

error $CUDA_REPO_ERR_MSG

fi

;;

esac

case $1 in

rhel)

status 'Installing EPEL repository...'

# EPEL is required for third-party dependencies such as dkms and libvdpau

SUDO PACKAGE_MANAGER -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-

;;

esac

status 'Installing CUDA driver...'

if [ "

SUDO PACKAGE_MANAGER -y install nvidia-driver-latest-dkms

fi

SUDO PACKAGE_MANAGER -y install cuda-drivers

}

# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#ubuntu

# ref: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#debian

install_cuda_driver_apt() {

status 'Installing NVIDIA repository...'

if curl -I --silent --fail --location "https://developer.download.nvidia.com/compute/cuda/repos/

curl -fsSL -o TEMP_DIR/cuda-keyring.deb https://developer.download.nvidia.com/compute/cuda/repos/12/(uname -m | sed -e 's/aarch64/sbsa/')/cuda-keyring_1.1-1_all.deb

else

error $CUDA_REPO_ERR_MSG

fi

case $1 in

debian)

status 'Enabling contrib sources...'

SUDO sed 's/main/contrib/' < /etc/apt/sources.list |

if [ -f "/etc/apt/sources.list.d/debian.sources" ]; then

SUDO sed 's/main/contrib/' < /etc/apt/sources.list.d/debian.sources |

fi

;;

esac

status 'Installing CUDA driver...'

SUDO dpkg -i TEMP_DIR/cuda-keyring.deb

$SUDO apt-get update

[ -n "

DEBIAN_FRONTEND=noninteractive $SUDO_E apt-get -y install cuda-drivers -q

}

if [ ! -f "/etc/os-release" ]; then

error "Unknown distribution. Skipping CUDA installation."

fi

. /etc/os-release

OS_NAME=$ID

OS_VERSION=$VERSION_ID

PACKAGE_MANAGER=

for PACKAGE_MANAGER in dnf yum apt-get; do

if available $PACKAGE_MANAGER; then

break

fi

done

if [ -z "$PACKAGE_MANAGER" ]; then

error "Unknown package manager. Skipping CUDA installation."

fi

if ! check_gpu nvidia-smi || [ -z "$(nvidia-smi | grep -o "CUDA Version: [0-9]*\.[0-9]*")" ]; then

case $OS_NAME in

centos|rhel) install_cuda_driver_yum 'rhel' (echo OS_VERSION | cut -d '.' -f 1) ;;

rocky) install_cuda_driver_yum 'rhel' (echo OS_VERSION | cut -c1) ;;

fedora) [ OS_VERSION -lt '39' ] && install_cuda_driver_yum OS_VERSION || install_cuda_driver_yum OS_NAME '39';;

amzn) install_cuda_driver_yum 'fedora' '37' ;;

debian) install_cuda_driver_apt OS_NAME OS_VERSION ;;

ubuntu) install_cuda_driver_apt OS_NAME (echo

*) exit ;;

esac

fi

if ! lsmod | grep -q nvidia || ! lsmod | grep -q nvidia_uvm; then

KERNEL_RELEASE="$(uname -r)"

case $OS_NAME in

rocky) SUDO PACKAGE_MANAGER -y install kernel-devel kernel-headers ;;

centos|rhel|amzn) SUDO PACKAGE_MANAGER -y install kernel-devel-KERNEL_RELEASE kernel-headers-KERNEL_RELEASE ;;

fedora) SUDO PACKAGE_MANAGER -y install kernel-devel-

debian|ubuntu) SUDO apt-get -y install linux-headers-KERNEL_RELEASE ;;

*) exit ;;

esac

NVIDIA_CUDA_VERSION=(SUDO dkms status | awk -F: '/added/ { print

if [ -n "$NVIDIA_CUDA_VERSION" ]; then

SUDO dkms install NVIDIA_CUDA_VERSION

fi

if lsmod | grep -q nouveau; then

status 'Reboot to complete NVIDIA CUDA driver install.'

exit 0

fi

$SUDO modprobe nvidia

$SUDO modprobe nvidia_uvm

fi

# make sure the NVIDIA modules are loaded on boot with nvidia-persistenced

if available nvidia-persistenced; then

$SUDO touch /etc/modules-load.d/nvidia.conf

MODULES="nvidia nvidia-uvm"

for MODULE in $MODULES; do

if ! grep -qxF "$MODULE" /etc/modules-load.d/nvidia.conf; then

echo "

fi

done

fi

status "NVIDIA GPU ready."

install_success

5 运行install.sh脚本进行安装

进入install.sh所在目录

chmod +x install.sh #给脚本赋予执行权限

./install.sh

# 如果报错误: bash: ./build_android.sh:/bin/sh^M:解释器错误: 没有那个文件或目录,执行

sed -i 's/\r$//' install.sh

6 下载运行模型

4c8g 的机器上,下载1.5b 的大小1.1G 的模型 3:47 开始 很慢

打开终端,输入以下命令下载并运行deepseek模型,例如下载1.5B 模型

ollama run deepseek-r1:1.5b

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 45 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 43 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 43 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 43 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 43 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 43 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 43 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 43 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 43 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 43 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 43 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 42 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 42 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 42 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 42 pulling manifest

pulling aabd4debf0c8... 14% ¨Š¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€¨€ ¨‡ 161 MB/1.1 GB 42 pulling manifest

如果本地硬件配置允许的话,可以运行其他模型

ollama run deepseek-r1:7b

ollama run deepseek-r1:14b

ollama run deepseek-r1:32b

DeepSeek本地化部署硬件配置要求一览表:

7 启动ollama 服务

ollama serve

服务启动后,可以通过访问 http://localhost:11434 来与模型进行交互

Ollama 启动默认只有127.0.0.1 本地可以访问,外部要可以访问需要修改ollama 服务文件重启ollama

sudo systemctl daemon-reload

sudo systemctl restart ollama

服务器外部可以访问11434 端口了

8 验证测试

为了方便对话,我们可以下载一个chatboxai (官网:https://chatboxai.app/zh)

本地硬件配置4C 8G

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2025-03-25,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 1 环境
  • 2.下载ollama安装包
  • 3.上传到服务器
  • 4. 下载安装脚本install.sh
  • 5 运行install.sh脚本进行安装
  • 6 下载运行模型
  • 7 启动ollama 服务
  • 8 验证测试
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档