add docs
This commit is contained in:
508
docs/08-Cleanup-Aufgaben.md
Normal file
508
docs/08-Cleanup-Aufgaben.md
Normal file
@@ -0,0 +1,508 @@
|
||||
# Cleanup-Aufgaben
|
||||
|
||||
## Übersicht
|
||||
|
||||
Diese Kategorie umfasst Wartungs- und Bereinigungsroutinen für verschiedene Systemkomponenten. Regelmäßige Cleanup-Aufgaben sind wichtig für Speicherplatz-Management, Performance-Optimierung und System-Hygiene.
|
||||
|
||||
**Anwendungsfälle**:
|
||||
- Löschen alter Proxmox-Snapshots
|
||||
- Bereinigung ungenutzter CheckMK-Agent-Plugins
|
||||
- Entfernung veralteter Docker-Images und -Container
|
||||
- Speicherplatz-Freigabe
|
||||
|
||||
---
|
||||
|
||||
## Playbooks
|
||||
|
||||
### cleanups/clean-pve-snapshots.yml
|
||||
|
||||
Löschen von Proxmox VE Snapshots auf VM-Hosts.
|
||||
|
||||
**Datei**: `playbooks/cleanups/clean-pve-snapshots.yml`
|
||||
|
||||
**Zweck**: Bereinigung aller Proxmox-VM-Snapshots (außer "current") zur Freigabe von Speicherplatz nach erfolgreichen Updates oder Wartungsarbeiten.
|
||||
|
||||
**Ziel-Hosts**: `all`
|
||||
|
||||
**Benutzer**: `tincadmin` (mit sudo-Rechten)
|
||||
|
||||
**Verwendete Rollen**:
|
||||
- `proxmox-automation` (get-vmid, delete-snapshots)
|
||||
|
||||
**Wichtige Variablen**:
|
||||
- Keine (verwendet Vault-Variablen)
|
||||
|
||||
**Verwendungsbeispiel**:
|
||||
|
||||
```bash
|
||||
# Alle Snapshots auf allen VMs entfernen
|
||||
ansible-playbook playbooks/cleanups/clean-pve-snapshots.yml \
|
||||
-i inventories/icp-fra-pve1.yml \
|
||||
-K --ask-vault-pass
|
||||
|
||||
# Nur für spezifische Hosts
|
||||
ansible-playbook playbooks/cleanups/clean-pve-snapshots.yml \
|
||||
-i inventories/icp-fra-pve1.yml \
|
||||
--limit mail-server-01.example.com \
|
||||
-K --ask-vault-pass
|
||||
|
||||
# Mit Verbose-Output
|
||||
ansible-playbook playbooks/cleanups/clean-pve-snapshots.yml \
|
||||
-i inventories/icp-fra-pve1.yml \
|
||||
-v \
|
||||
-K --ask-vault-pass
|
||||
```
|
||||
|
||||
**Abhängigkeiten**:
|
||||
- Vault-Datei (`vault.yml`) für Proxmox API-Tokens
|
||||
- Hosts müssen Proxmox-VMs sein
|
||||
- Proxmox API-Zugriff
|
||||
|
||||
**Besonderheiten**:
|
||||
- **`gather_facts: false`** - Keine Fact-Sammlung für Performance
|
||||
- **Löscht ALLE Snapshots** außer "current" (aktiver VM-Zustand)
|
||||
- **Snapshot-ID-Abruf** vor Löschung
|
||||
- **API-basiert** - Delegiert zu localhost
|
||||
|
||||
**Workflow**:
|
||||
1. Lädt Vault-Datei mit Proxmox-Zugangsdaten
|
||||
2. Für jeden Host:
|
||||
- Ermittelt Proxmox VM-ID
|
||||
- Listet alle Snapshots auf
|
||||
- Filtert "current" aus
|
||||
- Löscht alle verbleibenden Snapshots
|
||||
3. Gibt Speicherplatz frei
|
||||
|
||||
**⚠️ Warnung**: Dieses Playbook löscht **ALLE** Snapshots! Stellen Sie sicher, dass keine wichtigen Snapshots mehr benötigt werden.
|
||||
|
||||
**Wann verwenden**:
|
||||
- Nach erfolgreichen OS-Major-Upgrades
|
||||
- Nach erfolgreichen Mailcow-Updates
|
||||
- Monatliche Speicherplatz-Bereinigung
|
||||
- Vor großen Updates (alte Snapshots entfernen, neue erstellen)
|
||||
|
||||
**Siehe auch**: [Virtualisierung → delete-snapshots.yaml](06-Virtualisierung.md#3-delete-snapshotsyaml)
|
||||
|
||||
---
|
||||
|
||||
### cleanups/cleanup-cmk-agent-plugins.yml
|
||||
|
||||
Bereinigung von CheckMK-Agent-Plugins auf überwachten Hosts.
|
||||
|
||||
**Datei**: `playbooks/cleanups/cleanup-cmk-agent-plugins.yml`
|
||||
|
||||
**Zweck**: Entfernung nicht benötigter oder veralteter CheckMK-Agent-Plugins zur Reduzierung des Monitoring-Overheads.
|
||||
|
||||
**Ziel-Hosts**: `all`
|
||||
|
||||
**Benutzer**: `tincadmin` (mit sudo-Rechten)
|
||||
|
||||
**Verwendete Rollen**:
|
||||
- `checkmk-monitoring` (Task: `cleanup-agent-plugins`)
|
||||
|
||||
**Wichtige Variablen**:
|
||||
- `checkmk_agent_plugins_to_remove` (aus Rolle)
|
||||
|
||||
**Verwendungsbeispiel**:
|
||||
|
||||
```bash
|
||||
# Standard-Cleanup (entfernt Plugins aus defaults/main.yaml)
|
||||
ansible-playbook playbooks/cleanups/cleanup-cmk-agent-plugins.yml \
|
||||
-i inventories/icp-fra-pve1.yml \
|
||||
-K
|
||||
|
||||
# Mit custom Plugin-Liste
|
||||
ansible-playbook playbooks/cleanups/cleanup-cmk-agent-plugins.yml \
|
||||
-i inventories/icp-fra-pve1.yml \
|
||||
-e '{"checkmk_agent_plugins_to_remove": ["docker-mailq-monitoring", "old-plugin"]}' \
|
||||
-K
|
||||
|
||||
# Nur auf Mail-Servern
|
||||
ansible-playbook playbooks/cleanups/cleanup-cmk-agent-plugins.yml \
|
||||
-i inventories/extern.yml \
|
||||
-K
|
||||
```
|
||||
|
||||
**Abhängigkeiten**:
|
||||
- `checkmk-monitoring` Rolle
|
||||
- CheckMK-Agent muss installiert sein
|
||||
|
||||
**Besonderheiten**:
|
||||
- **Minimales Playbook** - Nur Rollen-Aufruf
|
||||
- **`gather_facts: false`** - Performance-Optimierung
|
||||
- **Idempotent** - Mehrfache Ausführung sicher
|
||||
|
||||
**Workflow**:
|
||||
1. Liest Plugin-Liste aus `checkmk_agent_plugins_to_remove`
|
||||
2. Für jeden Host:
|
||||
- Lokalisiert CheckMK-Agent-Plugin-Verzeichnis
|
||||
- Löscht spezifizierte Plugins
|
||||
- Bereinigt zugehörige Konfigurationsdateien
|
||||
3. CheckMK-Agent wird automatisch neu geladen
|
||||
|
||||
**Standard-Plugins zur Entfernung** (aus `roles/checkmk-monitoring/defaults/main.yaml`):
|
||||
```yaml
|
||||
checkmk_agent_plugins_to_remove:
|
||||
- "docker-mailq-monitoring"
|
||||
```
|
||||
|
||||
**Wann verwenden**:
|
||||
- Nach Migration zu alternativen Monitoring-Lösungen
|
||||
- Nach Dekommissionierung von Services
|
||||
- Bei Performance-Problemen durch zu viele Plugins
|
||||
- Regelmäßige Bereinigung (quartalsweise)
|
||||
|
||||
**Plugin-Verzeichnisse** (typisch):
|
||||
- `/usr/lib/check_mk_agent/plugins/`
|
||||
- `/usr/lib/check_mk_agent/local/`
|
||||
- `/etc/check_mk/`
|
||||
|
||||
**Siehe auch**: [Monitoring → Rolle checkmk-monitoring](02-Monitoring.md#5-cleanup-agent-pluginsyaml)
|
||||
|
||||
---
|
||||
|
||||
## Docker-Cleanup-Playbooks
|
||||
|
||||
Die Docker-Cleanup-Playbooks sind in der [Container-Management](03-Container-Management.md)-Kategorie dokumentiert:
|
||||
|
||||
- **[docker/cleanup-images.yml](03-Container-Management.md#dockercleanup-imagesyml)** - Bereinigung ungenutzter Docker-Images
|
||||
- **[docker/cleanup-all.yml](03-Container-Management.md#dockercleanup-allyml)** - Vollständige Docker-Bereinigung
|
||||
|
||||
Diese Playbooks sind ebenfalls Teil der Cleanup-Strategie und sollten regelmäßig ausgeführt werden.
|
||||
|
||||
---
|
||||
|
||||
## Cleanup-Strategie und Best Practices
|
||||
|
||||
### 1. Regelmäßige Ausführung
|
||||
|
||||
Empfohlener Cleanup-Zeitplan:
|
||||
|
||||
| Aufgabe | Häufigkeit | Playbook | Begründung |
|
||||
|---------|------------|----------|------------|
|
||||
| Docker-Images | Wöchentlich | `docker/cleanup-images.yml` | Speicherplatz-Management |
|
||||
| Proxmox-Snapshots | Monatlich | `cleanups/clean-pve-snapshots.yml` | Nach erfolgreichen Updates |
|
||||
| CMK-Agent-Plugins | Quartalsweise | `cleanups/cleanup-cmk-agent-plugins.yml` | Nach Plugin-Änderungen |
|
||||
| Docker-Full-Cleanup | Monatlich | `docker/cleanup-all.yml` | Vollständige Bereinigung |
|
||||
|
||||
### 2. Automatisierung mit Cron/Systemd-Timer
|
||||
|
||||
**Beispiel Cron-Job** (auf Ansible-Control-Node):
|
||||
|
||||
```bash
|
||||
# /etc/cron.d/ansible-cleanup
|
||||
|
||||
# Wöchentliches Docker-Image-Cleanup (Sonntag 02:00 Uhr)
|
||||
0 2 * * 0 ansible-user /usr/local/bin/cleanup-docker-images.sh
|
||||
|
||||
# Monatliches Snapshot-Cleanup (1. des Monats, 03:00 Uhr)
|
||||
0 3 1 * * ansible-user /usr/local/bin/cleanup-snapshots.sh
|
||||
```
|
||||
|
||||
**Wrapper-Script** (`/usr/local/bin/cleanup-docker-images.sh`):
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
cd /opt/operating-automation
|
||||
ansible-playbook playbooks/docker/cleanup-images.yml \
|
||||
-i inventories/icp-fra-pve1.yml \
|
||||
>> /var/log/ansible-cleanup.log 2>&1
|
||||
```
|
||||
|
||||
### 3. Pre-Cleanup-Checks
|
||||
|
||||
Vor größeren Cleanups:
|
||||
|
||||
```bash
|
||||
# 1. Überprüfen Sie aktuelle Snapshot-Liste
|
||||
ansible all -i inventories/icp-fra-pve1.yml \
|
||||
-m shell -a "qm listsnapshot \$(qm list | grep $(hostname) | awk '{print \$1}')" \
|
||||
-b
|
||||
|
||||
# 2. Überprüfen Sie Docker-Speichernutzung
|
||||
ansible all -i inventories/icp-fra-pve1.yml \
|
||||
-m shell -a "docker system df" \
|
||||
-b
|
||||
|
||||
# 3. Überprüfen Sie CheckMK-Plugins
|
||||
ansible all -i inventories/icp-fra-pve1.yml \
|
||||
-m shell -a "ls -la /usr/lib/check_mk_agent/plugins/" \
|
||||
-b
|
||||
```
|
||||
|
||||
### 4. Post-Cleanup-Verifizierung
|
||||
|
||||
Nach Cleanup-Operationen:
|
||||
|
||||
```bash
|
||||
# 1. Verifizieren Sie freigegebenen Speicherplatz
|
||||
ansible all -i inventories/icp-fra-pve1.yml \
|
||||
-m shell -a "df -h /" \
|
||||
-b
|
||||
|
||||
# 2. Überprüfen Sie Service-Status
|
||||
ansible all -i inventories/icp-fra-pve1.yml \
|
||||
-m shell -a "systemctl status docker check-mk-agent" \
|
||||
-b
|
||||
|
||||
# 3. Überprüfen Sie ob kritische Snapshots gelöscht wurden
|
||||
# (manuell im Proxmox Web-Interface)
|
||||
```
|
||||
|
||||
### 5. Backup vor Cleanup
|
||||
|
||||
Für sicherheitskritische Cleanups:
|
||||
|
||||
```bash
|
||||
# 1. Erstellen Sie neue Snapshots BEVOR Sie alte löschen
|
||||
ansible-playbook playbooks/os-update.yml \
|
||||
-e "do_snapshots=true" \
|
||||
-e "snapshot_name=pre-cleanup-$(date +%Y%m%d)" \
|
||||
-i inventories/... \
|
||||
-K --ask-vault-pass
|
||||
|
||||
# 2. Dann Cleanup durchführen
|
||||
ansible-playbook playbooks/cleanups/clean-pve-snapshots.yml \
|
||||
-i inventories/... \
|
||||
-K --ask-vault-pass
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Speicherplatz-Monitoring
|
||||
|
||||
### Speichernutzung überwachen
|
||||
|
||||
```bash
|
||||
# Gesamte Festplattennutzung
|
||||
ansible all -i inventories/icp-fra-pve1.yml \
|
||||
-m shell -a "df -h | grep -E 'Filesystem|/$'" \
|
||||
-b
|
||||
|
||||
# Docker-Speichernutzung detailliert
|
||||
ansible all -i inventories/icp-fra-pve1.yml \
|
||||
-m shell -a "docker system df -v" \
|
||||
-b
|
||||
|
||||
# Proxmox-Storage-Status
|
||||
pvesm status
|
||||
```
|
||||
|
||||
### Top-Speicherverbraucher identifizieren
|
||||
|
||||
```bash
|
||||
# Größte Verzeichnisse finden
|
||||
ansible all -i inventories/icp-fra-pve1.yml \
|
||||
-m shell -a "du -h / --max-depth=2 2>/dev/null | sort -rh | head -20" \
|
||||
-b
|
||||
|
||||
# Docker-Volume-Größen
|
||||
ansible all -i inventories/icp-fra-pve1.yml \
|
||||
-m shell -a "docker system df -v | grep VOLUME -A 100" \
|
||||
-b
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Fehlerbehebung
|
||||
|
||||
### Problem: Snapshot-Cleanup schlägt fehl
|
||||
|
||||
**Symptome**: delete-snapshots Task meldet Fehler
|
||||
|
||||
**Lösung**:
|
||||
1. Überprüfen Sie Proxmox-API-Zugangsdaten in Vault
|
||||
2. Überprüfen Sie ob Snapshots tatsächlich existieren:
|
||||
```bash
|
||||
qm listsnapshot <vmid>
|
||||
```
|
||||
3. Versuchen Sie manuelles Löschen:
|
||||
```bash
|
||||
qm delsnapshot <vmid> <snapshot-name>
|
||||
```
|
||||
4. Überprüfen Sie Proxmox-Logs:
|
||||
```bash
|
||||
journalctl -u pveproxy -n 100
|
||||
```
|
||||
|
||||
### Problem: Plugin-Cleanup entfernt benötigte Plugins
|
||||
|
||||
**Symptome**: CheckMK-Services fehlen nach Cleanup
|
||||
|
||||
**Prävention**:
|
||||
- Überprüfen Sie `checkmk_agent_plugins_to_remove` Liste vor Ausführung
|
||||
- Testen Sie auf einzelnem Host zuerst
|
||||
|
||||
**Lösung**:
|
||||
1. Re-installation des CheckMK-Agents:
|
||||
```bash
|
||||
ansible-playbook playbooks/reinstall-cmk-agent.yml
|
||||
```
|
||||
2. Service-Discovery neu ausführen:
|
||||
```bash
|
||||
ansible-playbook playbooks/setup-checkmk-monitoring.yml \
|
||||
--limit affected-host
|
||||
```
|
||||
|
||||
### Problem: Docker-Cleanup löscht benötigte Images
|
||||
|
||||
**Symptome**: Container können nicht starten nach Cleanup
|
||||
|
||||
**Prävention**:
|
||||
- Verwenden Sie `cleanup-images.yml` statt `cleanup-all.yml` für konservatives Cleanup
|
||||
- Stellen Sie sicher alle Container laufen vor `cleanup-all.yml`
|
||||
|
||||
**Lösung**:
|
||||
1. Re-pull Images:
|
||||
```bash
|
||||
cd /opt/mailcow-dockerized
|
||||
docker-compose pull
|
||||
docker-compose up -d
|
||||
```
|
||||
|
||||
### Problem: Zu wenig Speicherplatz freigegeben
|
||||
|
||||
**Symptome**: Nach Cleanup immer noch hohe Speichernutzung
|
||||
|
||||
**Lösung**:
|
||||
1. Identifizieren Sie Top-Verbraucher:
|
||||
```bash
|
||||
du -h / --max-depth=2 | sort -rh | head -20
|
||||
```
|
||||
2. Überprüfen Sie Log-Dateien:
|
||||
```bash
|
||||
journalctl --vacuum-size=100M
|
||||
find /var/log -type f -name "*.log" -size +100M
|
||||
```
|
||||
3. Bereinigen Sie alte Kernels:
|
||||
```bash
|
||||
apt autoremove --purge
|
||||
```
|
||||
4. Überprüfen Sie Mailcow-Logs:
|
||||
```bash
|
||||
cd /opt/mailcow-dockerized
|
||||
du -sh data/logs/*
|
||||
# Bereinigen Sie alte Logs manuell
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Erweiterte Cleanup-Operationen
|
||||
|
||||
### APT-Cache-Bereinigung
|
||||
|
||||
```bash
|
||||
# Auf allen Hosts
|
||||
ansible all -i inventories/icp-fra-pve1.yml \
|
||||
-m apt -a "autoclean=yes" \
|
||||
-b
|
||||
|
||||
ansible all -i inventories/icp-fra-pve1.yml \
|
||||
-m apt -a "autoremove=yes purge=yes" \
|
||||
-b
|
||||
```
|
||||
|
||||
### Journalctl-Log-Rotation
|
||||
|
||||
```bash
|
||||
# Logs älter als 30 Tage löschen
|
||||
ansible all -i inventories/icp-fra-pve1.yml \
|
||||
-m shell -a "journalctl --vacuum-time=30d" \
|
||||
-b
|
||||
|
||||
# Logs auf max 500MB begrenzen
|
||||
ansible all -i inventories/icp-fra-pve1.yml \
|
||||
-m shell -a "journalctl --vacuum-size=500M" \
|
||||
-b
|
||||
```
|
||||
|
||||
### Alte Kernel-Versionen entfernen
|
||||
|
||||
```bash
|
||||
# Automatische Entfernung alter Kernels (Debian)
|
||||
ansible all -i inventories/icp-fra-pve1.yml \
|
||||
-m apt -a "autoremove=yes purge=yes" \
|
||||
-b
|
||||
```
|
||||
|
||||
### Mailcow-Log-Bereinigung
|
||||
|
||||
```bash
|
||||
# Alte Mailcow-Logs löschen (älter als 30 Tage)
|
||||
ansible all -i inventories/extern.yml \
|
||||
-m shell -a "find /opt/mailcow-dockerized/data/logs -type f -mtime +30 -delete" \
|
||||
-b
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Cleanup-Checkliste
|
||||
|
||||
Verwenden Sie diese Checkliste für monatliche Wartung:
|
||||
|
||||
- [ ] **Pre-Check**: Speichernutzung dokumentieren
|
||||
- [ ] **Backup**: Wichtige Snapshots oder Backups erstellen
|
||||
- [ ] **Docker-Images**: `playbooks/docker/cleanup-images.yml` ausführen
|
||||
- [ ] **Proxmox-Snapshots**: `playbooks/cleanups/clean-pve-snapshots.yml` ausführen (nach erfolgreichen Updates)
|
||||
- [ ] **CMK-Plugins**: `playbooks/cleanups/cleanup-cmk-agent-plugins.yml` ausführen (quartalsweise)
|
||||
- [ ] **APT-Cache**: `apt autoclean` und `apt autoremove` auf allen Hosts
|
||||
- [ ] **Logs**: Journalctl und Application-Logs rotieren
|
||||
- [ ] **Post-Check**: Speicherplatz-Freigabe verifizieren
|
||||
- [ ] **Monitoring**: Services und Container-Status prüfen
|
||||
- [ ] **Dokumentation**: Cleanup-Ergebnisse dokumentieren
|
||||
|
||||
---
|
||||
|
||||
## Nützliche Kommandos
|
||||
|
||||
### Speicherplatz-Analyse
|
||||
|
||||
```bash
|
||||
# Top 10 größte Verzeichnisse
|
||||
ansible all -i inventories/... \
|
||||
-m shell -a "du -h / --max-depth=2 2>/dev/null | sort -rh | head -10" \
|
||||
-b
|
||||
|
||||
# Inode-Nutzung
|
||||
ansible all -i inventories/... \
|
||||
-m shell -a "df -i" \
|
||||
-b
|
||||
```
|
||||
|
||||
### Cleanup-Status
|
||||
|
||||
```bash
|
||||
# Anzahl Docker-Images
|
||||
ansible all -i inventories/... \
|
||||
-m shell -a "docker images | wc -l" \
|
||||
-b
|
||||
|
||||
# Anzahl Snapshots pro VM
|
||||
pvesh get /nodes/<node>/qemu/<vmid>/snapshot
|
||||
|
||||
# CheckMK-Plugin-Liste
|
||||
ansible all -i inventories/... \
|
||||
-m shell -a "ls /usr/lib/check_mk_agent/plugins/ | wc -l" \
|
||||
-b
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## Zusammenfassung
|
||||
|
||||
Cleanup-Aufgaben sind essentiell für:
|
||||
- ✅ **Speicherplatz-Management**: Verhindert Disk-Full-Situationen
|
||||
- ✅ **Performance**: Reduziert Overhead durch alte Snapshots/Images
|
||||
- ✅ **Sicherheit**: Entfernt veraltete Software-Komponenten
|
||||
- ✅ **Compliance**: Erfüllt Datenaufbewahrungsrichtlinien
|
||||
- ✅ **Wartungsfreundlichkeit**: Übersichtlichere Systeme
|
||||
|
||||
**Empfohlene Cleanup-Routine**:
|
||||
1. Wöchentlich: Docker-Image-Cleanup
|
||||
2. Monatlich: Vollständiges Docker-Cleanup, APT-Cache
|
||||
3. Nach Updates: Proxmox-Snapshot-Cleanup
|
||||
4. Quartalsweise: CheckMK-Plugin-Cleanup, Log-Rotation
|
||||
|
||||
---
|
||||
|
||||
**Navigation**: [← Zurück: Basis-System](07-Basis-System.md) | [Zurück zur Übersicht](00-Übersicht.md)
|
||||
Reference in New Issue
Block a user