Filters
Zo zoek je
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • "twee woorden" vindt precies die zin.
  • --naam of -x vindt een optie.
  • #woord zoekt alleen in commando's.
  • @grep vindt lessen en labs die grep gebruiken.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Zet ! voor een woord om het weg te laten. OR tussen woorden betekent één ervan.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken

Hoofdstuk 13Naam in het boek: Analyzing and Storing Logs

Read, keep and manage system logs

Logs tell you what happened and why something failed. RHEL has two log systems that work together: the systemd journal and rsyslog. This chapter shows how to read logs, search the journal, keep it after a reboot, send messages to your own files, rotate logs and write test messages.

  • 13 Lessen
  • 11 Commando's
  • 1 Labs

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

Examendoelen in dit hoofdstuk

  • Logbestanden en journals van het systeem vinden en lezen
  • Het systeemjournal bewaren na een herstart

13.1

Know the two log systems

systemd-journald collects all messages (kernel, services, boot) in a binary journal. rsyslogd reads them and writes text files in /var/log/.

journaldrsyslogd
StorageBinary journal (/run/log/journal or /var/log/journal)Text files in /var/log/
Read withjournalctlless, tail, grep
Strong atSearch by unit, time, priority, bootSending logs to other servers, long-term files
systemctl status systemd-journald rsyslog
ls /var/log/

13.2

Read the classic log files

The most important text logs on RHEL:

FileContains
/var/log/messagesMost system messages
/var/log/secureLogins, sudo, su, SSH (security)
/var/log/audit/audit.logAudit and SELinux events (written by auditd)
/var/log/boot.logMessages of services at boot
/var/log/croncron jobs
/var/log/maillogMail server
/var/log/httpd/Apache access and error logs
/var/log/dnf.logPackage changes
less /var/log/messages
grep -i 'failed password' /var/log/secure | tail

13.3

Understand a log line

A syslog line has: time, host, program[PID], message.

/var/log/secure
Oct 25 09:02:11 server1 sshd[2215]: Accepted publickey for admin from 192.168.122.1 port 51322 ssh2: ED25519 SHA256:k9...
PartValue
TimeOct 25 09:02:11
Hostserver1
Program [PID]sshd[2215]
MessageAccepted publickey for admin …

13.4

Watch logs live

Follow a log while you test something — you see the error the moment it happens.

tail -f /var/log/messages
journalctl -f
journalctl -fu httpd

Op het werk

Open a second terminal with journalctl -f before you restart a service or change a config. Errors appear right away.

13.5

Search the journal with journalctl

journalctl filters by unit, time, priority, boot and more. Filters can be combined.

journalctl -u sshd
journalctl -p err
journalctl --since today
journalctl --since "2026-10-25 08:00" --until "2026-10-25 09:00"
journalctl -b
journalctl -b -1 -p warning
journalctl -k
journalctl _UID=1001
journalctl -o verbose -n 1
OptionShows
-u UNITOne service
-p errPriority err and worse (also warning, crit …)
--since / --untilA time window (today, yesterday, -1h, a date)
-b / -b -1This boot / the boot before
-kKernel messages
-n 20Last 20 lines
-xExplanations for some messages
-o verboseAll fields of an entry
FIELD=VALUEFilter on a field, like _PID=1010, _COMM=sudo

Onthoud

Type journalctl -u and press Tab twice: bash completes unit names. In -o verbose you see all fields you can filter on.

13.6

Keep the journal after a reboot

By default the journal may live only in memory (/run/log/journal) and is lost at reboot. With a folder /var/log/journal it is stored on disk.

  1. Check where the journal is now.
    journalctl --list-boots
    ls -d /run/log/journal /var/log/journal
  2. Make it persistent: create a drop-in folder and set Storage=persistent in a file there (or simply create /var/log/journal).
    mkdir -p /etc/systemd/journald.conf.d
    /etc/systemd/journald.conf.d/persistent.conf
    [Journal]
    Storage=persistent
    SystemMaxUse=500M
  3. Restart journald and flush the memory journal to disk.
    systemctl restart systemd-journald
    journalctl --flush

Controleer het

More than one boot is listed after a reboot.

journalctl --list-boots
Storage=Meaning
autoDisk if /var/log/journal exists, else memory (default)
persistentDisk; creates the folder
volatileMemory only
noneKeep nothing (only forward to rsyslog)

Examentip

"The journal must survive a reboot" = Storage=persistent (or mkdir /var/log/journal) and a restart of systemd-journald. Check with journalctl --list-boots after a reboot.

13.7

Configure rsyslog

/etc/rsyslog.conf (and files in /etc/rsyslog.d/) decide which messages go where. A rule is: FACILITY.PRIORITY DESTINATION.

/etc/rsyslog.conf (part)
*.info;mail.none;authpriv.none;cron.none    /var/log/messages
authpriv.*                                  /var/log/secure
mail.*                                      -/var/log/maillog
cron.*                                      /var/log/cron
*.emerg                                     :omusrmsg:*

The config has three parts: modules (inputs like imjournal), global directives, and rules.

13.8

Know facilities and priorities

Every message has a facility (which part of the system) and a priority (how important).

Facilities
auth, authprivLogin and security
cron, mail, daemon, kernCron, mail, services, kernel
userUser programs (default of logger)
local0 … local7Free for your own use
Priority (high → low)Number
emerg0
alert1
crit2
err3
warning4
notice5
info6
debug7

cron.err means: cron messages with priority err or higher. cron.=err means only err. cron.none means none.

  1. Send all messages of facility local5 to their own file.
    /etc/rsyslog.d/app.conf
    local5.*    /var/log/app.log
  2. Restart rsyslog and test with logger.
    systemctl restart rsyslog
    logger -p local5.info "test message for app.log"
    tail -1 /var/log/app.log

Op het werk

Send logs to a central log server so an attacker cannot delete them on the hacked machine: *.* @@logserver.example.com:514 (@@ = TCP, @ = UDP).

13.9

Rotate log files

logrotate renames old logs (like messages-20261025), compresses them and deletes the oldest, so the disk does not fill up. A systemd timer runs it every day.

cat /etc/logrotate.conf
ls /etc/logrotate.d/
systemctl list-timers logrotate.timer
/etc/logrotate.d/app
/var/log/app.log {
    weekly
    rotate 8
    compress
    missingok
    notifempty
    create 0640 root root
}
logrotate -d /etc/logrotate.d/app
logrotate -f /etc/logrotate.d/app
SettingMeaning
daily / weekly / monthly / size 100MWhen to rotate
rotate 8Keep 8 old files
compressgzip old files
missingok, notifemptyNo error if missing; skip empty files
create MODE OWNER GROUPMake a new empty log with these rights
postrotate … endscriptRun commands after the rotation (like a reload)

13.10

Write test messages with logger

logger writes a message to the log from the command line or a script — good to test rules and to log what your scripts do.

logger "backup started"
logger -p user.err -t backup "backup failed: disk full"
journalctl -t backup
grep backup /var/log/messages

13.11

Remember the main points

The most important facts of this chapter, in short.

  • RHEL logs with systemd-journald (the journal) and rsyslogd (text files in /var/log).
  • Important files: /var/log/messages (general), /var/log/secure (logins and sudo), /var/log/audit/audit.log (SELinux and audit).
  • journalctl reads the journal: -u UNIT, -f follow, -p err priority, -b this boot, --since "1 hour ago", -o verbose.
  • By default the journal lives in /run and is lost at reboot. Make it persistent with Storage=persistent in a journald drop-in (or create /var/log/journal), then restart journald.
  • rsyslog sends messages by facility and priority to files: authpriv.* /var/log/secure; own rules go in /etc/rsyslog.d/*.conf.
  • logrotate rotates, compresses and removes old log files (/etc/logrotate.conf, /etc/logrotate.d/).
  • logger writes your own message into the logs, good for testing.

13.12

Learn the key terms

The words of this chapter in simple English.

TermMeaning
journaldThe systemd logging service that keeps the journal.
JournalThe binary log of systemd, read with journalctl.
rsyslogdThe service that writes log messages into text files.
FacilityThe kind of program that sent the message (auth, cron, mail, local0 …).
Priority (severity)How important a message is (debug … emerg).
Persistent journalA journal that is kept on disk in /var/log/journal.
Log rotationMoving old logs away and starting new files.
auditdThe service that writes the audit log (also SELinux denials).

13.13

Check what you learned

Think about the answer first, then open it.

1How do you see all messages of sshd since the last boot?
2How do you watch new journal messages live?
3How do you show only errors and worse?
4How do you make the journal survive a reboot?

Set Storage=persistent in /etc/systemd/journald.conf.d/*.conf (or make /var/log/journal) and run systemctl restart systemd-journald.

5Which file has the failed SSH logins?

/var/log/secure.

6How do you send all messages of facility local5 to /var/log/app.log?

Add local5.* /var/log/app.log in a file in /etc/rsyslog.d/, then systemctl restart rsyslog.

7How do you test that rule?

logger -p local5.info "test message", then look in /var/log/app.log.

8Which program keeps log files from filling the disk?

logrotate (run daily by a systemd timer).

Oefenen

Alle commando's in dit hoofdstuk