Garden of KnowledgeApplied Sciences › Computer Science › Software › Security › Certifications › LFCS

q24-system-logs

Énoncé§

Solve this question on: web-srv1

  1. Write all nginx.service log entries from the last boot into /opt/course/24/nginx.log.
  2. Configure systemd-journald to store logs persistently across reboots.
  3. List all kernel error messages since 2024-01-01 into /opt/course/24/kernel-errors.log.
  4. Limit the journal disk usage to a maximum of 200M.

Solution§

Step 1 — Service logs from current boot§

journalctl -u nginx.service -b 0 > /opt/course/24/nginx.log

journalctl cheat sheet:

FlagMeaning
-u <unit>filter by systemd unit
-b / -b -1 / -b 0current boot / previous boot / current
--list-bootslist available boots
-p errpriority ≤ error (emerg, alert, crit, err, warning, notice, info, debug)
-kkernel messages only (= dmesg)
-ffollow (like tail -f)
--since "2024-01-01" --until "1h ago"time-based filter
-n 50last 50 lines
-o json-prettyoutput format
--disk-usagespace used by journal
--vacuum-size=200M / --vacuum-time=2weeksshrink

Step 2 — Make the journal persistent§

By default, on systems without /var/log/journal/, logs live in /run/log/journal/ (RAM, lost at reboot).

sudo mkdir -p /var/log/journal
sudo systemd-tmpfiles --create --prefix /var/log/journal
sudo systemctl restart systemd-journald

Or edit /etc/systemd/journald.conf:

[Journal]
Storage=persistent       # persistent | volatile | auto | none
SystemMaxUse=200M
SystemMaxFileSize=50M
MaxRetentionSec=1month

Then sudo systemctl restart systemd-journald.

Step 3 — Kernel errors since a date§

journalctl -k -p err --since "2024-01-01" > /opt/course/24/kernel-errors.log

Step 4 — Disk usage cap§

Either via the conf file above, or one-shot:

sudo journalctl --vacuum-size=200M

Traditional log files§

Even with systemd, classic /var/log files often remain (via rsyslog):

FileContent
/var/log/messages (RHEL) / /var/log/syslog (Debian)general system messages
/var/log/secure (RHEL) / /var/log/auth.log (Debian)authentication, sudo, sshd
/var/log/kern.logkernel ring buffer
/var/log/dmesglast boot kernel messages
/var/log/audit/audit.logauditd (SELinux denials)
/var/log/boot.logboot-time messages

Rotation is handled by logrotate — configs under /etc/logrotate.d/. Force a run with sudo logrotate -f /etc/logrotate.conf.

—The Gardener