How can I increase the systemd-journal log retention time?

To increase the log retention size for systemd-journald, modify the /etc/systemd/journald.conf file, focusing on the [Journal] section. The key options for controlling disk space usage and log retention are:

  • Storage - Controls where systemd-journald saves logs, with options like 'volatile' (RAM only, lost on reboot), 'persistent' (disk /var/log/journal/), 'auto' (disk if /var/log/journal exists, else RAM), and 'none' (no storage, logs dropped). 'auto' is the default, using /var/log/journal/ if present, otherwise volatile storage, making it easy to enable persistence by just creating that directory.
  • SystemMaxUse - The maximum total disk space that persistent journal logs (stored in /var/log/journal/) can occupy. Set this to a value like 10G for 10 Gigabytes, or 500M for 500 Megabytes.
  • SystemKeepFree - The minimum amount of free disk space that journald should leave available on the filesystem where persistent logs are stored. This prevents the journal from consuming all available space. For example, SystemKeepFree=5G would ensure at least 5 Gigabytes remain free.
  • SystemMaxFileSize - The maximum size of individual persistent journal files before they are rotated. For example, SystemMaxFileSize=1G would cap individual files at 1 Gigabyte.
  • SystemMaxFiles - The maximum number of individual journal files (both active and archived) to keep, acting as a file count limit that works alongside size limits like SystemMaxUse and SystemMaxFileSize to control log retention; if you have many small files or very active logging, SystemMaxFiles can become the limiting factor, causing older logs to be deleted even if total disk space isn't full yet.
  • MaxRetentionSec - The maximum time to store journal entries. You can specify a duration like 1month, 1year, 30days, or 7d. Setting it to 0 disables time-based retention.

Enable Persistent Logs

Create the persistent log directory if it doesn't exist and apply the correct permissions and ownership:

mkdir -p /var/log/journal
systemd-tmpfiles --create --prefix /var/log/journal

Flush the current volatile logs to the new persistent storage (optional, if you don't want to reboot immediately):

journalctl --flush

To increase the journal size to 32GB, ensure 5GB of free space, and keep logs for a maximum of one month edit the systemd-journal configuration file /etc/systemd/journald.conf adding the options below:

[Journal]
Storage=persistent
SystemMaxUse=32G
SystemKeepFree=5G
SystemMaxFileSize=512M
SystemMaxFiles=4096
MaxRetentionSec=1month

Restart the systemd-journal to apply the new configuration:

systemctl restart systemd-journald

Note: Similar Runtime* options exist for volatile logs stored in /run/log/journal/, which are lost upon reboot. Ensure Storage=persistent is set in /etc/systemd/journald.conf for changes to affect persistent logs.

  • systemd-journal, logging, journalctl
  • 0 Los Usuarios han Encontrado Esto Útil
¿Fue útil la respuesta?

Artículos Relacionados

How can I change the interface language of the extension?

You can change the interface language under Settings -> Application Settings -> Locale...

How can I disable admin email notifications in Amavis?

Amavis has different default options for controlling where virus, spam, banned file attachments,...

How can I whitelist or blacklist a mail server from greylisting?

To Whitelist a Mail Server From Greylisting Navigate to Warden -> Settings ->...

How can I enable third party anti-virus signatures within Warden to improve the ClamAV detection rate?

Warden supports enabling third party anti-virus signatures to improve the detection rate. These...

How can I setup a local caching DNS resolver to speed up DNS queries used by Amavis?

Run the following command to check if local DNS caching is enabled: host -tTXT...