Introduction
logrotate is designed to ease the management of systems that generate a large number of log files. It allows for the rotation, compression, removal, and automatic emailing of log files. Each log file can be handled daily, weekly, monthly, or when it grows too large.
logrotate Installation
By default, logrotate is installed on most Linux distributions, and you can verify this by executing:
# logrotate --version
The currently installed version should appear. If the command is not recognized, you should install it:
# apt install logrotate
# yum install logrotate
Rotation Configuration
First, check that the logrotate configuration includes the directory logrotate.d. You can execute the following to verify it:
# grep include /etc/logrotate.conf
The following grep result should appear:
include /etc/logrotate.d
This means that the configuration includes the settings from the directory. Therefore, create the file for configuration within the directory:
# nano /etc/logrotate.d/example
For example, with the following content:
/var/log/example/logs.log {
weekly
rotate 3
size 10M
compress
delaycompress
}
When the declared log file reaches 10 MB, it will be rotated and compressed, up to a maximum of three files on a weekly basis. You can verify the operation by executing the following:
# logrotate -d /etc/logrotate.d/example
You can also execute it directly without waiting for the scheduled job:
# logrotate -vf /etc/logrotate.d/example
We hope this tutorial has been helpful to you. Have you tried it? Leave us your comments! 🙂
Remember, if you have questions about this or any other issue related to your servers at Clouding, do not hesitate to write to soporte@clouding.io We're here for whatever you need!