How to rotate systemd-journald log in CentOS/RHEL 7
Question: How to rotate systemd-journald log under /var/log/journal/*/ or /run/log/journal/*/?
journald logs can be rotated using the /etc/systemd/journald.conf configuration file. By default all the options in the configuration file will be hashed out and at their default values. We will discuss some of the parameters from this file to rotate systemd-journald logs.
Here is a default /etc/systemd/journald.conf configuration file with all parameters hashed out:
# cat /etc/systemd/journald.conf # This file is part of systemd. # # systemd is free software; you can redistribute it and/or modify it # under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 2.1 of the License, or # (at your option) any later version. # # Entries in this file show the compile time defaults. # You can change settings by editing this file. # Defaults can be restored by simply deleting this file. # # See journald.conf(5) for details. [Journal] #Storage=auto #Compress=yes #Seal=yes #SplitMode=uid #SyncIntervalSec=5m #RateLimitInterval=30s #RateLimitBurst=1000 #SystemMaxUse= #SystemKeepFree= #SystemMaxFileSize= #RuntimeMaxUse= #RuntimeKeepFree= #RuntimeMaxFileSize= #MaxRetentionSec= #MaxFileSec=1month #ForwardToSyslog=yes #ForwardToKMsg=no #ForwardToConsole=no #ForwardToWall=yes #TTYPath=/dev/console #MaxLevelStore=debug #MaxLevelSyslog=debug #MaxLevelKMsg=notice #MaxLevelConsole=info #MaxLevelWall=emerg #LineMax=48K
SystemMaxUse= and RuntimeMaxUse=
These 2 parameters define how much disk space the journal may use up at maximum. If this parameter is not set, it defaults to 10% of the respective filesystem size.
For example, set the maximum size limit for journal logs. The config file for the journalctl lies under /etc/systemd/journald.conf. The following entry limits the size of your journal logs:
# grep -i maxuse /etc/systemd/journald.conf SystemMaxUse=1G ## Change this value as required.
SystemKeepFree= and RuntimeKeepFree=
These 2 parameters will ensure how much disk space is left free by systemd-journald for other users. The default value is 15% of the respective file system size.
# man journald.conf ..... SystemMaxUse=, SystemKeepFree=, SystemMaxFileSize=, RuntimeMaxUse=, RuntimeKeepFree=, RuntimeMaxFileSize= Enforce size limits on the journal files stored. The options prefixed with "System" apply to the journal files when stored on a persistent file system, more specifically /var/log/journal. The options prefixed with "Runtime" apply to the journal files when stored on a volatile in-memory file system, more specifically /run/log/journal. The former is used only when /var is mounted, writable, and the directory /var/log/journal exists. Otherwise, only the latter applies. Note that this means that during early boot and if the administrator disabled persistent logging, only the latter options apply, while the former applies if persistent logging is enabled and the system is fully booted up. journalctl and systemd-journald ignore all files with names not ending with ".journal" or ".journal~", so only such files, located in the appropriate directories, are taken into account when calculating current disk usage.