Ollama Installation: Lokale LLM-Ausführungsanleitung
Ollama-Installation, lokale LLM-Modelle ausführen (Llama 3, Mistral, Gemma), API-Nutzung, Modellverwaltung, GPU-Beschleunigung und Docker-Deployment.
Inhaltsverzeichnis
Ollama Installation: Lokale LLM-Ausführungsanleitung
Ollama ist ein Open-Source-Tool, mit dem Sie große Sprachmodelle (LLMs) einfach auf Ihrem lokalen Server ausführen können. Sie können Llama 3, Mistral, Gemma, Phi-3 und viele weitere Modelle mit einem einzigen Befehl herunterladen und verwenden. Diese Anleitung behandelt die Ollama-Installation, Modellverwaltung, API-Nutzung und GPU-Beschleunigung im Detail.
Was ist Ollama?
Ollama ist eine leichtgewichtige Laufzeitumgebung zum lokalen Ausführen von LLM-Modellen. Es ermöglicht das Herunterladen und Verwalten von Modellen mit einem Docker-ähnlichen Ansatz. Hauptmerkmale:
- Einfache Installation: Einrichtung und Modell-Download mit einem Befehl
- Breite Modellunterstützung: Llama 3, Mistral, Gemma, Phi-3, CodeLlama, Qwen und mehr
- REST-API: OpenAI-kompatibler API-Endpunkt
- GPU-Beschleunigung: NVIDIA- und AMD-GPU-Unterstützung
- Modelfile: Benutzerdefinierte Modellkonfigurationen erstellen
- Geringer Ressourcenverbrauch: Niedriger Speicherverbrauch mit quantisierten Modellen
Systemanforderungen
| Komponente | Minimum | Empfohlen |
|---|---|---|
| RAM | 8 GB | 16 GB+ |
| Festplatte | 20 GB | 50 GB+ |
| GPU (optional) | NVIDIA 4 GB VRAM | NVIDIA 8 GB+ VRAM |
| Betriebssystem | Linux, macOS, Windows | Ubuntu 22.04 LTS |
Installation unter Linux
Verwenden Sie das offizielle Installationsskript:
curl -fsSL https://ollama.com/install.sh | sh
Nach der Installation startet der Ollama-Dienst automatisch. Überprüfen Sie den Status:
systemctl status ollama
Manuelle Installation
Falls das Skript nicht funktioniert:
# Binary herunterladen
curl -L https://ollama.com/download/ollama-linux-amd64 -o /usr/local/bin/ollama
chmod +x /usr/local/bin/ollama
# Ollama-Benutzer erstellen
useradd -r -s /bin/false -m -d /usr/share/ollama ollama
# Systemd-Servicedatei
cat > /etc/systemd/system/ollama.service << 'EOF'
[Unit]
Description=Ollama Service
After=network-online.target
[Service]
ExecStart=/usr/local/bin/ollama serve
User=ollama
Group=ollama
Restart=always
RestartSec=3
Environment="HOME=/usr/share/ollama"
[Install]
WantedBy=default.target
EOF
systemctl daemon-reload
systemctl enable --now ollama
Docker-Installation
CPU-Modus
docker run -d \
--name ollama \
-p 11434:11434 \
-v ollama_data:/root/.ollama \
ollama/ollama
GPU-Modus (NVIDIA)
docker run -d \
--name ollama \
--gpus all \
-p 11434:11434 \
-v ollama_data:/root/.ollama \
ollama/ollama
Docker Compose
version: '3.8'
services:
ollama:
image: ollama/ollama
container_name: ollama
ports:
- "11434:11434"
volumes:
- ollama_data:/root/.ollama
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
restart: unless-stopped
volumes:
ollama_data:
Modelle herunterladen und ausführen
# Llama 3.1 8B Modell
ollama pull llama3.1
# Mistral 7B
ollama pull mistral
# Google Gemma 2 9B
ollama pull gemma2
# Interaktiver Chat
ollama run llama3.1
# Einzelne Abfrage
ollama run llama3.1 "Wie überprüfe ich die Festplattennutzung unter Linux?"
Modellverwaltung
# Installierte Modelle auflisten
ollama list
# Modellinformationen
ollama show llama3.1
# Modell löschen
ollama rm mistral
# Laufende Modelle anzeigen
ollama ps
REST-API-Nutzung
Ollama bietet eine REST-API auf Port 11434:
Chat-Vervollständigung
curl http://localhost:11434/api/chat -d '{
"model": "llama3.1",
"messages": [
{"role": "system", "content": "Du bist ein hilfreicher Assistent."},
{"role": "user", "content": "Was ist Docker?"}
],
"stream": false
}'
Textgenerierung
curl http://localhost:11434/api/generate -d '{
"model": "llama3.1",
"prompt": "Schreibe eine Nginx Reverse-Proxy-Konfiguration",
"stream": false
}'
Python-API-Nutzung
import requests
def chat_with_ollama(prompt, model="llama3.1"):
response = requests.post(
"http://localhost:11434/api/chat",
json={
"model": model,
"messages": [{"role": "user", "content": prompt}],
"stream": False
}
)
return response.json()["message"]["content"]
result = chat_with_ollama("Wie sortiere ich eine Liste in Python?")
print(result)
Benutzerdefinierte Modelle mit Modelfile
# Modelfile
FROM llama3.1
SYSTEM """Du bist ein REXE Technology technischer Support-Assistent.
Du hilfst bei Serververwaltung, Docker, Linux und Netzwerkthemen."""
PARAMETER temperature 0.7
PARAMETER top_p 0.9
PARAMETER num_ctx 4096
Modell erstellen:
ollama create rexe-assistant -f Modelfile
ollama run rexe-assistant
GPU-Beschleunigung
NVIDIA GPU
# NVIDIA-Treiber prüfen
nvidia-smi
# CUDA-Version
nvcc --version
AMD GPU (ROCm)
curl -fsSL https://ollama.com/install.sh | OLLAMA_ACCELERATION=rocm sh
# Docker mit AMD GPU
docker run -d \
--name ollama \
--device /dev/kfd \
--device /dev/dri \
-p 11434:11434 \
-v ollama_data:/root/.ollama \
ollama/ollama:rocm
GPU-Speicherverwaltung
export OLLAMA_NUM_GPU=1
export OLLAMA_GPU_MEMORY=6144
export OLLAMA_MAX_LOADED_MODELS=2
export CUDA_VISIBLE_DEVICES=0
Umgebungsvariablen
# /etc/systemd/system/ollama.service.d/override.conf
[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
Environment="OLLAMA_MODELS=/data/ollama"
Environment="OLLAMA_NUM_PARALLEL=4"
Environment="OLLAMA_MAX_LOADED_MODELS=2"
Environment="OLLAMA_KEEP_ALIVE=5m"
Änderungen anwenden:
systemctl daemon-reload
systemctl restart ollama
Leistungstipps
# RAM sparen mit quantisierten Modellen
ollama pull llama3.1:8b-q4_0 # 4-Bit (~4,7 GB)
ollama pull llama3.1:8b-q5_1 # 5-Bit (~5,7 GB)
ollama pull llama3.1:8b-q8_0 # 8-Bit (~8,5 GB)
# Kontextfenster-Einstellung
ollama run llama3.1 --num-ctx 2048
Mit REXE GPU-Servern können Sie große Sprachmodelle mit hoher Leistung über Ollama ausführen. NVIDIA A100/H100 GPUs liefern schnelle Antworten selbst bei 70B-Parameter-Modellen.
Verwandte Artikel
Open WebUI Einrichtung: ChatGPT-ähnliche Oberfläche für lokale KI
Open WebUI Installation mit Docker, Ollama-Integration, Benutzerverwaltung, RAG (Dokumentenabfrage), Modellverwaltung, benutzerdefinierte Prompts und Mehrbenutzersupport.
AI-Modell-Deployment auf GPU-Servern: NVIDIA CUDA Anleitung
NVIDIA-Treiberinstallation, CUDA-Toolkit, nvidia-container-toolkit, Modell-Serving mit vLLM, GPU-Monitoring und AI-Modell-Deployment mit Docker Anleitung.
Stable Diffusion Einrichtung: Self-Hosted Bilderzeugung
Stable Diffusion Installation, AUTOMATIC1111 und ComfyUI Oberflächen, Modell-Download, LoRA-Training, ControlNet-Nutzung und Docker Self-Hosted Bilderzeugung Anleitung.