BlogLinux & scripting

Centralized logging with journald and rsyslog

Make the journal persistent, forward it to a central host, and keep logs you can actually search after an incident.

Oct 8, 2024·7 min readBeginner

systemd's journal is structured, queryable, and already running on every modern Linux box — but by default it is in-memory and vanishes on reboot, which is useless the moment you need it. Two changes make it incident-ready: persist it, and forward it somewhere central.

Make the journal survive reboots

/etc/systemd/journald.conf
[Journal]
Storage=persistent
SystemMaxUse=2G
MaxRetentionSec=30day
bash — query a unitlive
journalctl -u sshd --since "1 hour ago" -p warning
Failed password for invalid user admin from 203.0.113.9
structured, filterable by unit, priority, and time

Forward to a central host

A log on a box that got compromised is a log you cannot trust. Ship it off the host with rsyslog.

/etc/rsyslog.d/50-forward.conf
# forward everything to the central collector over TCP
*.* @@logs.acme.internal:514
Watch the rate limiter
journald drops messages past RateLimitBurst per RateLimitInterval. Under a flood you lose exactly the lines you want — tune these on noisy hosts.
Go deeper in a courseLinux essentialssystemd, journals, and everyday operational fluency.View course

Related posts