Lesson 015 · Linux Administration Learning Path

RHEL Logging with journald, rsyslog and logrotate

· Published · 7 min read

Labelled RHEL Linux administration path highlighting application events journald rsyslog remote retention rotation UTC correlation and incident evidence

Logs are evidence only when their source, time, completeness, retention and access are understood. /var/log/messages is not a universal answer: systemd services write to the journal, applications may use files or structured remote telemetry, and rsyslog can route selected events. Rotation controls local files but does not guarantee durable central retention or successful ingestion.

Design the evidence path before an incident

Record which layer emits an event, how journald receives and stores it, whether rsyslog forwards or writes it, where central storage timestamps it and how long each copy remains. Preserve event time and ingestion time when delayed delivery matters. Synchronize clocks, but never assume all sources use the same timezone or precision.

Logs may contain addresses, identifiers, message content, tokens or secrets. Collection needs least privilege, transport protection, retention and deletion policy. Debug logging can expose more sensitive data and consume storage rapidly.

Follow an event from producer to retention

LayerQuestion to answerEvidence
ProducerWhich unit/process emitted what event?Unit, PID, structured fields and application ID
Local journalWas it accepted and persisted?Boot ID, cursor, storage mode and disk use
RoutingWhich rsyslog selector/action handles it?Validated configuration and queue/action stats
Remote storeWas it received, indexed and protected?Ingestion timestamp, source identity and access
RetentionCan required history be retrieved intact?Rotation/archive policy and restore/search test

Build and test a logging contract

  1. List critical services, event classes, owners, retention and alert use.
  2. Confirm UTC/time synchronization and record boot IDs.
  3. Set journal storage and limits appropriate to local recovery needs.
  4. Validate rsyslog syntax and configure protected forwarding with queueing where required.
  5. Configure logrotate only for application files not managed by another owner.
  6. Emit a unique harmless test event and trace it through local and remote destinations.
  7. Test rotation, service reopen behavior, storage pressure and remote outage recovery.

Query journals and validate logging components

timedatectl
chronyc tracking
journalctl --list-boots
journalctl -u sshd.service -b --since '-30 minutes' --no-pager
journalctl -p warning..alert -b --no-pager
journalctl --disk-usage
journalctl --verify
systemd-analyze cat-config systemd/journald.conf
rsyslogd -N1
logrotate --debug /etc/logrotate.conf
logger --tag nitwings-lab --priority user.notice 'logging path verification'
journalctl -t nitwings-lab --since '-5 minutes' --no-pager
  • journalctl --verify checks journal-file consistency, not whether every expected producer emitted or forwarded events.
  • A successful rsyslog syntax check does not prove TLS trust, network delivery or remote indexing.
  • Use a unique benign test marker and remove no evidence during an active incident.
  • Do not force rotation against active application logs until reopen/copytruncate behavior and data-loss boundary are understood.

Evidence and acceptance criteria

EvidenceHealthy resultFailure meaning
TimeSynchronized clock and explicit UTC correlationEvents can appear out of order or break TLS/authentication analysis
Local journalExpected unit event, boot ID and cursor retainedProducer, rate limit, volatile storage or access issue
ForwardingQueued action reaches authenticated remote endpointNetwork, TLS, queue or receiver failure
RotationFiles rotate with correct owner/mode and application reopenDisk growth or writes continue to unlinked file
RetrievalRequired historical event is searchable under access policyRetention or indexing does not meet incident needs

Worked scenario: disk fills although logs were rotated

A large application log is renamed and compressed, but the process keeps the old file descriptor open. The pathname looks small while the deleted inode still consumes space. Repeated deletion does not release it.

The operator proves the deleted-open descriptor with lsof +L1, confirms the application supports a documented reopen signal or controlled reload, and watches the descriptor move to the new file. Rotation is changed to use the application’s supported reopen behavior. Disk, journal and remote evidence remain intact.

Practical how-to cases

Case 1: Enable persistent journal storage

Create the supported storage directory and verify effective journald configuration. Preserve UTC time, original event order and access control because logs can contain credentials and customer data.

sudo mkdir -p /var/log/journal
sudo systemd-tmpfiles --create --prefix /var/log/journal
sudo systemctl restart systemd-journald
journalctl --flush
journalctl --list-boots
journalctl --disk-usage
CheckpointWhat to establish
Expected resultBoot history persists under /var/log/journal and storage use is measurable.
If it failsDirectory existence alone does not prove retention; inspect effective limits and boots after reboot.
Safe recoveryRestore the saved configuration, validate syntax before restart, and prove both local retention and remote delivery resume.

Case 2: Query one incident window

Filter by unit, priority, boot and UTC time without exporting the entire journal. Preserve UTC time, original event order and access control because logs can contain credentials and customer data.

timedatectl
journalctl --list-boots
journalctl -u sshd -b --since '2026-09-04 10:00:00 UTC' --until '2026-09-04 10:15:00 UTC' -o short-iso-precise
journalctl _PID=1234 --no-pager
CheckpointWhat to establish
Expected resultThe output covers only the correlated window and preserves precise timestamps and source fields.
If it failsWrong clock or timezone makes apparently matching events misleading.
Safe recoveryRestore the saved configuration, validate syntax before restart, and prove both local retention and remote delivery resume.

Case 3: Forward a test event

Validate rsyslog, send one tagged record and confirm it locally and at the collector. Preserve UTC time, original event order and access control because logs can contain credentials and customer data.

sudo rsyslogd -N1
logger -p local0.notice -t nitwings-lab 'forwarding check'
journalctl -t nitwings-lab --since '-5 minutes'
sudo ss -ntup | grep 6514 || true
sudo journalctl -u rsyslog -n 30
CheckpointWhat to establish
Expected resultThe uniquely tagged record appears locally and at the approved TLS collector.
If it failsA running rsyslog process does not prove queue delivery, certificate trust or collector ingestion.
Safe recoveryRestore the saved configuration, validate syntax before restart, and prove both local retention and remote delivery resume.

Case 4: Test log rotation

Debug policy first, force only a lab log, then prove the writer reopens or continues correctly. Preserve UTC time, original event order and access control because logs can contain credentials and customer data.

sudo logrotate --debug /etc/logrotate.conf
sudo logrotate --force /etc/logrotate.d/labapp
ls -l /var/log/labapp*
sudo lsof /var/log/labapp.log
journalctl -u labapp -n 20
CheckpointWhat to establish
Expected resultArchive naming, permissions and retention match policy and the application writes to the active file.
If it failscopytruncate can lose records; rename requires a reopen signal or service behavior that supports it.
Safe recoveryRestore the saved configuration, validate syntax before restart, and prove both local retention and remote delivery resume.

Independent practice tasks

  1. Set journal size and retention limits for a small lab disk.
  2. Route one facility to a dedicated file with secure permissions.
  3. Configure a TLS forwarding queue and simulate collector outage.
  4. Recover a service that keeps writing to a rotated deleted file.

For this lesson on RHEL Logging and Retention, complete each task without copying the worked command sequence. Record the initial state, exact change, verification, negative test and recovery command. A task is unfinished if it works now but does not survive a reboot where persistence is required.

Troubleshooting by symptom

SymptomInspect firstDefensible next action
Prior boot missingJournal storage mode, directory and retentionEnable planned persistence/forwarding before next incident
Local event absent remotelyrsyslog action/queue, TLS and receiver ingestionRepair first failed hop and preserve queued events
Disk grows after rotationDeleted-open files and application reopen behaviorUse supported reopen/reload, not random kill
Journal drops messagesRate-limit notices, producer flood and storage limitsCorrect flood and capacity while preserving critical classes
Timestamps disagreeTimezone, NTP state, event vs ingestion timeNormalize correlation without rewriting original evidence

Unsafe operations and recovery boundaries

  • Unsafe: deleting or vacuuming logs during an incident destroys evidence and may not free deleted-open space.
  • Unsafe: enabling verbose debug globally can expose secrets and exhaust storage; scope and time-bound it.
  • Unsafe: forwarding logs without authenticated encryption or access controls can disclose operational and customer data.

Rewritten knowledge checks

Is <code>/var/log/messages</code> the universal system log?
No. Sources may use journald, application files, audit logs or remote structured telemetry.
What identifies one system boot in the journal?
The boot ID, queried through journalctl --list-boots and -b.
What does logrotate do?
It applies configured rotation, compression, retention and post-rotation actions to file logs.
Why can deleted logs still consume space?
A running process may hold the unlinked inode open.
Does local logging equal durable retention?
No. Local loss, compromise or capacity can remove it; design protected remote retention where required.
Why preserve ingestion time?
It reveals forwarding delay and helps distinguish late arrival from event occurrence.
What validates rsyslog configuration syntax?
rsyslogd -N1, followed by end-to-end delivery testing.
What makes a log useful evidence?
Known source, credible time, completeness limits, protected retention, access control and retrievability.

Guided lab and acceptance test

  1. Record time state and boot ID, then query one unit by time and priority.
  2. Configure a lab rsyslog file action for a unique facility/tag and validate syntax.
  3. Emit a unique logger event and trace fields through journal and file.
  4. Create a logrotate rule for the lab file and run debug before a forced lab-only rotation.
  5. Simulate a held-open file and use lsof +L1 to explain space.
  6. Remove the lab routing/rotation files, reload safely and verify ordinary logging continues.

Primary references

Advertisement