Ollama+Open WebUI部署大模型在linux平台

Ollama安装运行

Ollama容器拉取

docker pull ollama/ollama

Ollama容器CPU运行

docker run -d --restart=always -v /home/docker/ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama

Ollama容器GPU运行

# nvidia-container-runtime-script.sh

sudo curl -s -L https://nvidia.github.io/nvidia-container-runtime/gpgkey | \
  sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
sudo curl -s -L https://nvidia.github.io/nvidia-container-runtime/$distribution/nvidia-container-runtime.list | \
  sudo tee /etc/apt/sources.list.d/nvidia-container-runtime.list
sudo apt-get update

运行上述指令

##运行等待事件较长
sudo sh nvidia-container-runtime-script.sh
##要想成功执行这句,必须把源做好。
sudo apt-get install nvidia-container-runtime
#验证
which nvidia-container-runtime
#重启docker
sudo systemctl restart docker
#指定gpu模板
docker run -it --gpus '"device=0,2"' --shm-size 32g image_name:tag_name
docker run --gpus all -d -v /your/path/docker/ollama:/root/.ollama -p 11435:11435 --name ollama-gpu ollama/ollama

Open WebUI安装运行

Open WebUI容器拉取

docker pull ghcr.io/open-webui/open-webui:main

Open WebUI容器运行

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

Open WebUI端口重定向

这一步是为了在windows端可以访问

ssh -N -L 3000:localhost:3000 linux@linux.ip

容器删除

docker ps -l
#会返回CONTAINER ID,假设ed01c65da2cf
docker rm ed01c65da2cf

用户添加到docker用户组

## 将登陆用户加入到docker用户组中
sudo gpasswd -a $USER docker
# 更新用户组
newgrp docker

错误解决

sudo apt-get install -y nvidia-docker2 Reading package lists... Done
Building dependency tree        Reading state information... Error! E:
Unable to parse package file /var/lib/apt/extended_states (1)

extended_states 做好备份,删除这个文件后,执行

sudo apt-get update

open webui非容器安装

环境准备

[nodejs最新版](https://nodejs.cn/download/current/)
npm -g install npm@10.5.0
npm config set prefix "D:\Program Files\nodejs\node_global"
npm config set cache "D:\Program Files\nodejs\node_cache"
npm config set registry=http://registry.npm.taobao.org

安装

git clone https://github.com/open-webui/open-webui.git
cd open-webui/

# Copying required .env file
cp -RPp .env.example .env

# Building Frontend Using Node
npm i
npm run build

# Serving Frontend with the Backend
cd ./backend
pip install -r requirements.txt -U
bash start.sh

Ollama非容器安装

一句话安装命令

curl -fsSL https://ollama.com/install.sh | sh

创建用户

sudo useradd -r -s /bin/false -m -d /usr/share/ollama ollama

在 /etc/systemd/system/ollama.service 中创建一个服务文件:
这个文件也是启动时候执行的命令,可以指定ollama所需要的一切参数。

[Unit]
Description=Ollama Service
After=network-online.target

[Service]
ExecStart=/usr/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3

Environment="OLLAMA_NUM_PARALLEL=4" #并行处理请求的数量
Environment="OLLAMA_MAX_LOADED_MODELS=4" #同时加载的模型数量
Environment=OLLAMA_MODELS="/docker/ollama/models/" 
Environment="OLLAMA_FLASH_ATTENTION=true"
Environment="OLLAMA_KEEP_ALIVE=-1"
Environment="OLLAMA_ORIGINS=*"
[
Install]
WantedBy=default.target

启动服务:

sudo systemctl daemon-reload
sudo systemctl enable ollama

启动 Ollama

使用 systemd 启动 Ollama:

sudo systemctl start ollama
# 重启
sudo systemctl restart ollama

更新

通过再次运行安装脚本来更新 ollama:

curl -fsSL https://ollama.com/install.sh | sh

查看日志

要查看作为启动服务运行的 Ollama 的日志,请运行:

journalctl -u ollama

移除 ollama 服务

sudo systemctl stop ollama
sudo systemctl disable ollama

局域网访问

export OLLAMA_HOST=192.168.1.3
systemctl start firewalld
firewall-cmd --zone=public --add-port=11434/tcp --permanent 
firewall-cmd --reload
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值