How to enable persistent logging for the systemd journal
Environment
- Red Hat Enterprise Linux 7
- Red Hat Enterprise Linux 8
- Red Hat Enterprise Linux 9
- Red Hat Enterprise Linux 10
Issue
-
The
systemdjournal is configured by default to store logs only in a small ring-buffer in/run/log/journal, which is not persistent. -
Journal database logs do not survive a system reboot.
Resolution
- There are two methods to enable persistent
systemdjournal logs in/var/log/journal.
Method 1
-
Create the directory
journalusing the below command:# mkdir -p /var/log/journal -
Once the above directory is created the system will automatically start storing the logs at
/var/log/journalonce any loggable event is encountered inRHEL 7&RHEL 8. -
After that run the below command only in
RHEL 9andRHEL 10:# journalctl --flush
Method 2
Step 1. Edit Journald configuration
-
For RHEL 9 and below set the
Storageparameter equals topersistentin/etc/systemd/journald.conf:# sed -i 's/#Storage=auto/Storage=persistent/' /etc/systemd/journald.conf -
In RHEL 10, location of main configuration files is changed to
/usr/lib/systemd/folder. Still in/etc/systemd/folder override configurations can be placed like this.# cat /etc/systemd/journald.conf [Journal] Storage=persistent -
With the storage option
persistent, data will be stored preferably on disk, i.e. below the/var/log/journalhierarchy (which is created if needed), with a fallback to/run/log/journal(which is created if needed), during early boot and if the disk is not writable.
Step 2 Varies depending on the RHEL version:
-
On RHEL 7 & 8, restart the
systemd-journald.service:# systemctl restart systemd-journald.service -
On RHEL 9 and RHEL 10:
# systemctl restart systemd-journald.service # journalctl --flush -
Note: In RHEL 9,
journalctl --flushis required after restarting thesystemd-journald.service. This makes the journal work nicer with systems which have the root file system writable early, but still need to rearrange /var before journald should start writing and creating files to it, for example because ACLs need to be applied first, or because /var is to be mounted from another file system, NFS or tmpfs.
Additional Information
-
You may decide if you need to keep or remove the
rsyslogpackage installed on the system at this point, depending on your requirements. -
See
man journalctlfor more information on querying the journal database for specific logs. -
How to rotate systemd-journald log under /var/log/journal// or /run/log/journal//?
-
Journal have capability to forward logs too. Refer to How to configure systemd journal remote logging
Root Cause
- By default in Red Hat Enterprise Linux 7, 8, 9 & 10
systemdis not configured to maintain logs persistently.
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments