Files
nexus/wiki/sources/zai-ubuntu-an-zhuang-ollama-bing-yun-hang-qwen2-5-coder-7b.md
2026-04-14 16:02:50 +08:00

93 lines
2.2 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
title: "在 Ubuntu 安装 Ollama 并运行 Qwen2.5-Coder 7B"
type: source
tags: [ollama, qwen, qwen-coder, ubuntu, local-llm]
date: 2026-04-13
source_file: raw/Technical/Home Office/在 Ubuntu 安装 Ollama 并运行 Qwen2.5Coder 7B.md
---
## Summary
- 核心主题Ubuntu服务器安装Ollama运行Qwen2.5-Coder 7B本地大模型
- 问题域本地LLM部署、模型服务化、API开放
- 方法/机制Ollama一键安装 + systemd服务 + REST API暴露
- 结论/价值构建本地AI编码助手基础设施
## Key Claims
- Ollama提供一键式LLM部署
- Qwen2.5-Coder 7B适合代码生成和DevOps任务
- 默认只监听127.0.0.1,需配置才能远程访问
- GPU加速开箱即用需CUDA
## Key Concepts
- [[本地LLM]]:本地部署的大语言模型
- [[Ollama]]LLM运行平台
- [[Qwen2.5-Coder]]:阿里通义千问代码模型
- [[REST API]]:模型服务接口
## Key Entities
- [[Ollama]]LLM服务平台
- [[Qwen2.5-Coder]]:代码生成模型
- [[Ubuntu]]:部署系统
## 系统要求
| 资源 | 最低 | 推荐 |
|------|------|------|
| CPU | 4核 | 8+核 |
| RAM | 8GB | 16GB |
| GPU | 无需 | NVIDIA |
| 磁盘 | 10GB | 20GB |
模型大小约4.5GB
## 安装步骤
```bash
# 1. 安装
curl -fsSL https://ollama.com/install.sh | sh
# 2. 下载模型
ollama pull qwen2.5-coder:7b
# 3. 运行
ollama run qwen2.5-coder:7b
```
## API调用
### REST API
```bash
curl http://localhost:11434/api/chat -d '{
"model": "qwen2.5-coder:7b",
"messages": [{"role": "user", "content": "Write a bash script"}]
}'
```
### Python调用
```python
from ollama import chat
response = chat(model="qwen2.5-coder:7b", messages=[{"role": "user", "content": "..."}])
```
### NodeJS调用
```javascript
import ollama from 'ollama'
const response = await ollama.chat({ model: 'qwen2.5-coder:7b', messages: [...] })
```
## 开放远程API
编辑`/etc/systemd/system/ollama.service`,添加:
```ini
Environment="OLLAMA_HOST=0.0.0.0"
```
然后:
```bash
sudo systemctl daemon-reload
sudo systemctl restart ollama
```
## 推荐搭配
| 工具 | 用途 |
|------|------|
| Open WebUI | ChatGPT UI |
| n8n | AI自动化 |
| OpenClaw | AI coding agent |
| LangChain | Agent framework |