Zentrales Logging und Rotation mit journald und logrotate
Halten Sie automatisierte Systeme gesund, indem Sie systemd-Logs mit journalctl lesen und mit logrotate verhindern, dass Logdateien die Datenträger füllen.
Zentrales Logging und Rotation mit journald und logrotate ist eine kostenlose Linux Command Line Mastery-Lektion auf CoddyKit. Dies ist Lektion 4 von 4. Du kannst die komplette Lektion unten kostenlos lesen – dann übst du sie direkt im Browser mit einem integrierten Code-Editor und einem KI-Tutor rund um die Uhr. Sie ist Teil des Linux Command Line Mastery-Lernpfads, und dein Fortschritt wird über Web und CoddyKit-App synchronisiert. Der Linux Command Line Mastery-Kurs umfasst insgesamt 4 Lektionen.
Teile dieser Lektion wurden noch nicht übersetzt und werden auf Englisch angezeigt.
Automation Needs Logs
Cron jobs, systemd services, and shell functions all produce output. To run unattended systems you must capture, search, and rotate that output. Enter journalctl and logrotate.
What Is journald?
systemd-journald collects logs from services you manage with systemctl into a structured binary journal you query with journalctl.
Viewing Logs
Plain journalctl shows everything; -e jumps to the end (newest entries).
journalctl -eFiltering by Service
-u limits the journal to one unit, perfect for debugging a single service.
journalctl -u nginx.serviceFollowing Logs Live
-f streams new entries as they arrive, like tail -f for systemd.
journalctl -u nginx.service -fFiltering by Time and Priority
--since and -p narrow results. Here we show errors from the last hour.
journalctl --since '1 hour ago' -p errControlling Journal Size
Journals can grow large. --vacuum-size trims them to a target size.
sudo journalctl --vacuum-size=200MPlain-Text Logs and logrotate
Many apps still write to /var/log/*.log. logrotate rotates, compresses, and deletes these on a schedule so disks do not fill.
cat /etc/logrotate.confA logrotate Rule
Drop a config in /etc/logrotate.d/. This rotates daily, keeps 7 copies, and compresses old ones.
/var/log/myapp/*.log {
daily
rotate 7
compress
missingok
notifempty
}Testing logrotate
-d does a debug dry run that shows what would happen without changing files; -f forces an immediate rotation.
sudo logrotate -d /etc/logrotate.d/myappTying It to Automation
Have cron jobs and functions log to a dedicated file, manage that file with a logrotate rule, and use journalctl for everything run as a systemd service. Now nothing fills the disk silently.
Quick Check
Which journalctl option shows logs for a single systemd service?
Recap
You can keep automated systems observable and tidy:
journalctl -u,-f,--since,-pquery systemd logs--vacuum-sizetrims the journallogrotaterotates/compresses plain-text logs via/etc/logrotate.d/logrotate -ddry-runs your config
Lerne Linux Command Line Mastery mit einem KI-Tutor — kostenlos
Schreibe und führe echten Code in deinem Browser aus, bekomme sofortige Hilfe von einem 24/7 KI-Tutor und setze dein Lernen im Web oder in der App fort.
- Kurse
- 12
- Lektionen
- 48
Häufig gestellte Fragen
Ist die Lektion „Zentrales Logging und Rotation mit journald und logrotate“ kostenlos?
Ja — der vollständige Text von „Zentrales Logging und Rotation mit journald und logrotate“ ist hier im Web kostenlos zu lesen. Um sie interaktiv zu üben (integrierter Code-Editor und 24/7 KI-Tutor) und den Rest des Linux Command Line Mastery-Kurses freizuschalten, upgrade auf CoddyKit PRO. Der Linux Command Line Mastery-Kurs umfasst insgesamt 4 Lektionen.
Was lerne ich in „Zentrales Logging und Rotation mit journald und logrotate“?
Halten Sie automatisierte Systeme gesund, indem Sie systemd-Logs mit journalctl lesen und mit logrotate verhindern, dass Logdateien die Datenträger füllen. Du übst Linux Command Line Mastery mit praktischem Code, den du direkt im Browser ausführst, und ein 24/7 KI-Tutor beantwortet deine Fragen während du die Lektion bearbeitest.
Brauche ich Erfahrung, um Linux Command Line Mastery zu starten?
Keine Vorkenntnisse erforderlich. Linux Command Line Mastery auf CoddyKit ist für Anfänger bis fortgeschrittene Lernende strukturiert, sodass du hier starten oder von Anfang an beginnen und in deinem eigenen Tempo voranschreiten kannst. Dies ist Lektion 4 von 4.
Wie lange dauert die Lektion „Zentrales Logging und Rotation mit journald und logrotate“?
Die meisten CoddyKit-Lektionen dauern etwa 5–10 Minuten. Jede ist kompakt und interaktiv, sodass du stetig Fortschritte machst und genau dort weitermachst, wo du aufgehört hast – im Web und in der App.
Kann ich in dieser Linux Command Line Mastery-Lektion Code schreiben und ausführen?
Ja. Jede Linux Command Line Mastery-Lektion enthält einen integrierten Code-Editor, sodass du echten Code direkt in deinem Browser schreibst und ausführst und sofort KI-Feedback erhältst — ohne lokale Einrichtung erforderlich.
Alle Lektionen in diesem Kurs
- Aufgabenplanung: `cron` und `at`
- Dienstverwaltung: `systemctl` (systemd)
- Aufgaben mit Shell-Funktionen automatisieren
- Zentrales Logging und Rotation mit journald und logrotate