Press "Enter" to skip to content

windows/linux使用ollama搭建ai模型

windows/linux使用ollama搭建ai模型

背景:最近看到朋友圈挺多朋友私有化部署了ai模型,感觉挺6的,决定跟一波风,学习一下本地部署

首先,我们需要安装模型载体,这里我们选用ollama

1.访问ollama官网,下载安装包Ollama.Setup

  • windows版本直接下载安装包,双击安装

1741328919736

  • linux版本官网上安装的指令是 curl -fsSL https://ollama.com/install.sh | sh

    下载速度急慢,有兴趣的朋友可以了解一下

    于是在网上找到一个解决方案,亲测有效

    1.下载ollama_install.sh并保存
    curl -fsSL https://ollama.com/install.sh -o ollama_install.sh
    2.使用github文件加速替换github下载地址
    sed -i 's|https://ollama.com/download/ollama-linux|https://gh.llkk.cc/https://github.com/ollama/ollama/releases/download/v0.5.7/ollama-linux|g' ollama_install.sh
    3.替换后增加可执行权限
    chmod +x ollama_install.sh
    4.执行sh下载安装
    sh ollama_install.sh
    

2.安装后,可查看版本

1741328976483

3.选择合适的模型,我选择网友们推荐的qwen2【说是对中文支持比较好】

1741329083246

4.安装模型【windows和linux操作一样】

ollama run qwen2:7b

1741337644929

安装完成之后就可以直接对话了

7.07B的参数【1B=10亿】,会占用大量的系统资源

1741337915392

1741337952986

5.使用open-webui搭建可视化界面

使用docker搭建比较方便

  • 使用docker搭建【换过快速地址】
docker run -d -p 6000:8080 --add-host=host.docker.internal:host-gateway -v open-webui:/app/backend/data --name open-webui --restart always ghcr.nju.edu.cn/open-webui/open-webui:main
  • 使用docker-compose搭建
version: '3.8'
services:
  open-webui:
    image: ghcr.nju.edu.cn/open-webui/open-webui:main
    container_name: open-webui
    restart: always
    ports:
      - "3000:8080"
    extra_hosts:
      - "host.docker.internal:host-gateway"
    volumes:
      - open-webui:/app/backend/data

volumes:
  open-webui:

我用docker-compose搭建

1741338249077

安装完成之后,可以实用本地ip:3000端口访问,也可以配置nginx转发,使用域名访问

1741660941546

webui.conf

server {
    listen 80;
    listen 443 ssl;
    server_name xxx.com;  # 将此处替换为您的域名
    ssl_certificate /etc/nginx/ssl/*.xxx.com/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/*.xxx.com/key.pem;
    ssl_session_timeout 5m;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;

    location / {
        proxy_pass http://127.0.0.1:6000;  # 将请求转发到 open-webui
        proxy_set_header Host $host;  # 保留主机头
        proxy_set_header X-Real-IP $remote_addr;  # 客户端 IP
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  # 代理 IP
        proxy_set_header X-Forwarded-Proto $scheme;  # 协议
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        }
}

由于线上服务器配置不够,只有4核16G,不足以支撑需要的最低配置,在webui调用api/models接口503超时,导致页面无法正常打开,有资源且感兴趣的同学可以试试

1741661104050