Tutorial Install LogRotate On CentOS 7

Tutorial Install LogRotate On CentOS 7

Log files are files that are produced by services or programs to inform about their performance for the monitoring and control of network administrators or programmers. If the size of log files becomes very large, also var/log/ may become very large. In Linux, there are tools for rotating log files. The most common tool for rotating is called LogRotate. This article with teaches you How to Install LogRotate on CentOS 7. If you intend to buy a CentOS VPS server, you can check out the packages offered on the Eldernode website.

Recommended Article: How To Install ApisCP Control Panel On Centos 7

What is LogRotate?

LogRotate is a service in Linux that is often run once a day and system log files for which the archive date is defined are archived or deleted. In terms of functionality, Logrotate has full control over all log files that are specified by the user or the software itself in Logrotate’s configuration files. It allows you to easily manage systems that generate large numbers of log files. This service also allows automatic rotation, compression, removal, and mailing of log files.

Installing LogRotate on CentOS 7

In this section, we will explain the installation process of LogRotate on CentOS 7. First of all, update the system packages with the following command:

yum update

install the LogRotate on CentOS 7 using the following command:

yum install logrotate

The /etc/logrotate.conf configuration file indicates that other more specific settings may be placed separate .conf files within /etc/logrotate.d.

If the below line is present and is not uncommented, this will happen:

include /etc/logrotate.d

Configuring LogRotate on CentOS 7

Now you will learn how to configure LogRotate on CentOS 7.

First, you need to insert the following contents in /etc/logrotate.d/apache2.conf and check each line to indicate its purpose:

/var/log/apache2/* {      weekly      rotate 3      size 10M      compress      delaycompress  }

Note: You may need to create that file.

The directories inside the block available in the first line, apply to all logs inside /var/log/apache2:

–> Weekly: It means that the tool will attempt to rotate the logs on a weekly basis.

–> Rotate 3: It means that only 3 rotated logs will keep and the oldest file will remove on the fourth subsequent run.

–> Size=10M: It sets the minimum size for the rotation to take place to 10M.

–> Delaycompress/compress: It used to tell that all rotated logs, with the exception of the most recent one should be compressed.

You should execute a dry run using the -d option followed by the configuration file. Here’s what LogRotate would do if it actually ran now:

logrotate -d /etc/logrotate.d/apache2.conf

You can rename the logs after the date when they were rotate with the command below:


Also, use the following command to prevent the rotation from happening:


You can use /etc/logrotate.d/squid.conf to rotate /var/log/squid/access.log:

squid.conf  /var/log/squid/access.log {      monthly      create 0644 root root      rotate 5      size=1M      dateext      dateformat -%d%m%Y      notifempty      mail [email protected]  }

If you want to run a custom command when the rotation takes place, you should place the command between the post-rotate and end script directives.

That’s it!

Recommended Article: Tutorial Install LogRotate On CentOS 7


LogRotate is the most common tool in Linux for rotating log files. In this article, we taught you how to Install and configure LogRotate on CentOS 7. I hope this tutorial helps you to install and configure LogRotate on CentOS 7. If you have any questions or suggestions, you can contact us in the Comments section.

How useful was this post?

Click on a star to rate it!

Average rating 2.3 / 5. Vote count: 3

No votes so far! Be the first to rate this post.

View More Posts
Marilyn Bisson
Content Writer
Eldernode Writer
We Are Waiting for your valuable comments and you can be sure that it will be answered in the shortest possible time.

Leave a Reply

Your email address will not be published. Required fields are marked *

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way


7 days a week, 24 hours a day