天天看点

How to enable persistent logging for the systemd journal?

环境

  • Red Hat Enterprise Linux 7
  • Red Hat Enterprise Linux 8

问题

  • The ​

    ​systemd​

    ​ journal 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

决议

  • Configure ​

    ​systemd​

    ​ to persistently store journal logs in ​

    ​/var/log/journal​

    ​ by running the following commands.

​​Raw​​

# mkdir -p /var/log/journal
      
  • You may decide if you need to keep or remove the ​

    ​rsyslog​

    ​ package installed on the system at this point, depending on your requirements
  • See ​

    ​man journalctl​

    ​ for more information on querying the journal database for specific logs

Instead of manually creating the /var/log/journal directory, one can also change the systemd-journald configuration file:

# sed -i 's/#Storage=auto/Storage=persistent/' /etc/systemd/journald.conf
# systemctl restart systemd-journald.service
      

根源

  • By default in Red Hat Enterprise Linux 7 and 8, ​

    ​systemd​

    ​ is not configured to maintain logs persistently

继续阅读