Unix/Linux Guru and FOSS supporter

Install and Configure Logrotate on CentOS 8

Logs are beneficial to collect information. They can be beneficial while troubleshooting an issue. Logs can also be a pain to deal with but they also are lifesavers while troubleshooting an issue. In this article we will Install and configure logrotate on CentOS 8.

First, Update your system.

dnf -y update

Secondly, Install logrotate using the following command:

yum install -y logrotate
- Advertisement -

Check version of logrotate.

logrotate --version

Logrotate configuration can be checked and edited from its configuration file placed at “/etc/logrotate.conf”.

nano /etc/logrotate.conf

Now, as an example we will use logrotate. We will set log rotation schedule, Number of times log files will rotate, size limit for log files and other parameters.

- Advertisement -

Logrotate file will be found at /etc/logrotate.d/httpd.

/var/log/httpd/*log {
    rotate 3
    size 5M
        /bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true

daily: rotation times.

rotate 3: Log files rotation count times.

size: Rotate Log files only if they grow bigger then size bytes.

missingok: If the log file is missing, go on to the next one without issuing an error message.

notifyempty: Do not rotate the log if it is empty (this overrides the ifempty option).

sharedscripts: this option makes scripts run only once, no matter how many logs match the wildcarded pattern, and whole pattern passes to them.

delaycompress: Postpone compression of the previous log file to the next rotation cycle.

Now, you can test the log rotation feature by running the following command:

logrotate -d /etc/logrotate.d/httpd

You can install Logrotate on CentOS and use it.


Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook