目 录CONTENT

文章目录

在Ubuntu环境安装ollama, 本地运行大型语言模型(LLMs)

Administrator
2025-12-25 / 0 评论 / 0 点赞 / 1 阅读 / 0 字

在Ubuntu环境安装ollama, 本地运行大型语言模型(LLMs)

Ollama 是一个开源项目,旨在简化在本地运行大型语言模型(LLMs)的过程。允许用户轻松下载、运行和管理各种开源大语言模型,而无需依赖云服务或复杂的配置。提供跨平台的模型管理和使用能力:原生支持 macOS 和 Linux,Windows。
官方地址:https://ollama.com/download/linux

Ollama 的主要特点

本地运行:所有模型都在用户的本地设备上运行,保障数据隐私和安全性。
一键部署:通过简单的命令(如 ollama run llama3),即可快速启动模型。
支持多种模型:Ollama 支持 Meta 的 Llama 系列(如 Llama 2、Llama 3)、Mistral、Gemma、Phi、Qwen 等主流开源模型。
模型管理:提供类似 Docker 的体验,可以拉取(pull)、运行(run)、列出(list)和删除(rm)模型。
API 接口:Ollama 提供 RESTful API,方便开发者将本地模型集成到自己的应用中。

方案1:安装ollama

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

下载加速

140.82.114.3 github.com
199.232.69.194 github.global.ssl.fastly.net
185.199.108.153 assets-cdn.github.com
185.199.109.153 assets-cdn.github.com
185.199.110.153 assets-cdn.github.com
185.199.111.153 assets-cdn.github.com

开始安装

ctyun@00gcbjih-0OqRgn1nUE:/media/vdb/ollama$ curl -fsSL https://ollama.com/install.sh | sh
>>> Cleaning up old version at /usr/local/lib/ollama
>>> Installing ollama to /usr/local
>>> Downloading Linux amd64 bundle
#################                                                         24.2%

服务管理

状态检查:systemctl status ollama
开机启动:systemctl enable ollama

方案2:容器部署ollama

version: '3.3'
services:
  ollama:
    restart: always
    image: docker.1ms.run/ollama/ollama
    container_name: ollama
    # runtime: nvidia  # GPU支持
    environment:
      - TZ=Asia/Shanghai
      - NVIDIA_VISIBLE_DEVICES=all
    networks:
      - platform-common-net
    ports:
      - "11434:11434"
    volumes:
      - ./data:/root/.ollama
networks:
  platform-common-net:
    external: true

使用上面的docker-compose.yaml完成配置并启动,会自动生成private key。务必牢记!

ctyun@00gcbjih-0OqRgn1nUE:/media/vdb/code/deployment/deployment_micro_dev/ollama$ docker-compose up
[+] Running 3/5
 ⠸ ollama 4 layers [⣿⣿⣿⠀] 599.9MB/0B      Pulling                                                                                                                                                                                                    62.3s 
   ✔ 20043066d3d5 Pull complete                                                                                                                                                                                                                       7.7s 
   ✔ 1b83b22fdc34 Pull complete                                                                                                                                                                                                                      13.0s 
   ✔ 2ebb8c780efd Pull complete                                                                                                                                                                                                                      13.4s 
   ⠼ 5d7637d33c73 Downloading  599.9MB          

下载和使用模型

下载模型

以模型mxbai-embed-large: The largest and highest-quality embedding model.为例

root@006f4b1818e8:/# ollama pull mxbai-embed-large
pulling manifest 
pulling 819c2adf5ce6:  28% ▕████████████████████████████████████████████                                                                                                                    ▏ 187 MB/669 MB   18 MB/s     26s

参考文档:代码库索引 | Kilo Code Docs

模型调用

我在使用【Kilo Code 提供 codebase_search 工具以进行智能代码发现】,使用刚才下载的模型,可以看到模型正在疯狂运行,进行使用 AI 模型创建每个代码块的嵌入!

root@006f4b1818e8:/# ollama ps
NAME                        ID              SIZE      PROCESSOR    CONTEXT    UNTIL            
mxbai-embed-large:latest    468836162de7    758 MB    100% CPU     512        4 minutes from now  

ollama直接验证

curl http://localhost:11434/api/embeddings -d '{
  "model": "mxbai-embed-large",
  "prompt": "Represent this sentence for searching relevant passages: The sky is blue because of Rayleigh scattering"
}'

谢谢关注收藏

刚刷到的朋友注意啦
点击【关注】锁定宝藏库,从此升职加薪不迷路 ✨


我的博客网站:

我的技术博客:Tesla,https://funkygod.vip/

我的投资博客:MakeMoney,https://blog-demo-559.pages.dev/

我的微信公众号


轻量云主机限时优惠

RackNerd

☁ 主机显示特惠:只要80元(3TB流量,1vcpu,50GB硬盘)
购买地址:https://my.racknerd.com/aff.php?aff=14942

CloudCone

CloudCone 特惠轻量云主机购买地址:https://app.cloudcone.com/?ref=12332


📢 腾讯云资源限时福利

有云服务器、CDN、对象存储、网络防护等需求的朋友,欢迎联系下方腾讯云官方销售 👇
✔️ 内部专属折扣,价格更优 ✔️ 量大可谈,支持定制方案 ✔️ 技术咨询与售后无忧


智谱Ai GLM Coding 超值订阅

🚀 速来拼好模,智谱 GLM Coding 超值订阅,邀你一起薅羊毛!Claude Code、Cline 等 20+ 大编程工具无缝支持,“码力”全开,越拼越爽!立即开拼,享限时惊喜价! 链接:https://www.bigmodel.cn/glm-coding?ic=RTWWS8HOD6
活动截止时间:2026年1月15日

0
  1. 支付宝打赏

    qrcode alipay
  2. 微信打赏

    qrcode weixin

评论区