The logrotate
tool allows you to rotate the logs that are generated by applications and scripts
It keeps your log directories clutter-free and minimizes disk usage when correctly configured.
The logrotate
tool is installed by default, but I will include the installation instructions here for completeness. This recipe will show you how to rotate logs for rsyslog
. We will rotate the logs everyday, add an extension based on the date, compress them with a one-day delay, and keep them for 365 days. Perform the following steps:
First, to install
logrotate
, perform the following command:~]# yum install -y logrotate
Ensure that it's enabled through the following:
~]# systemctl restart crond
Open
/etc/logrotate.d/syslog
with your favorite editor. The contents of this file are the following, by default:/var/log/cron /var/log/maillog /var/log/messages /var/log/secure /var/log/spooler { sharedscripts postrotate /bin/kill -HUP `cat /var/run/syslogd.pid...