How to Install and Configure logrotate on Linux

Windows Articles

How to install OpenLiteSpeed on Ubuntu 20.04?

There are several web servers for Linux but other alternatives are always welcome. In this case, I will show you how to...

Linux 5.7 available

Time passes very quickly and we already have a new version of the Linux kernel that as always we are happy because...

How to install RStudio on Ubuntu 20.04 / 18.04

No matter how complete and robust a programming language is, the programmer will always need a tool to write the code. These programs have...

How to install Arduino IDE on Ubuntu 20.04 / 18.04 / Linux Mint 19.X?

Hi, folks. In this post, we will show you how to install Arduino IDE on Ubuntu 20.04/ 18.04 and Linux mint 19.x. You probably already...

How To Install Icinga 2 on Ubuntu 20.04

Today we are going to learn that how to Install Icinga 2 on Ubuntu 20.04. Before going to the installation process let's...
Muhammad Nabeel
Muhammad Nabeel
Network and System Administrator

Logrotate utility is designed to used in system administration in which dated log files are archived. Servers which run large applications such as LAMP stacks, often log every activity and request in the face of bulky logs which may use high disk space on the server. Log rotation provides a way to limit the total size of the logs retained while still allowing analysis of recent events.

The primary configuration file for logrotate is /etc/logrotate.conf and it has the default settings. So, if you want additional application-specific configuration then you have to create a separate file for that application in /etc/logrotate.d directory.

In this article you will learn that how to configure logrotate in Linux

Step 1: Install logrotate on Linux

Install logrotate on Ubuntu and Debian

apt install logrotate 

Install logrotate on CentOS, RHEL and Fedora

yum install  -y logrotate


OR

dnf install  -y logrotate

Step 2: Configure logrotate

We will configure logrotate for Apache web server in CentOS server. Let’s say we want to rotate the logs of a service “apache” that is creating logfiles under /var/log/httpd directory. So we will create a file “apache” under /etc/logrotate.d directory and make appropriate configuration in this file to rorate all the logs of apache service.

Run following command and add below lines in that file.

vi /etc/logrotate.d/apache
/var/log/httpd/* {
daily
rotate 50
size 2M
compress
delaycompress
}


/var/log/httpd It means rotating all logs from httpd directory.
daily means rotate the logs on a daily basis. you can also use weekly or monthly.
rotate 50 It means last 50 rotated logs should be kept.
size=2M means log will not be rotated until it reaches 2MB. sets the minimum size for the logs rotation.
compress It compress the old log files to save disk space.
delaycompress so it means rotated logs with the exception of the most recent one should be compressed.

now save changes to file and exit

You can also set many other options, for details run following command.

man logrotate

By default, logrotate automatically configures a cron job scheduled to run daily. but we want also run our desired log rotation file, Tells logrotate to force the rotation.

logrotate -f /etc/logrotate.d/httpd

Now run below command to see that what will logrotate do reading /etc/logrotate.d/httpd file.

logrotate -d /etc/logrotate.d/httpd

That’s it, so you can use logrotate and configure it for your desired service logs like it do for Apache web server.

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

How to install OpenLiteSpeed on Ubuntu 20.04?

There are several web servers for Linux but other alternatives are always welcome. In this case, I will show you how to...

Linux 5.7 available

Time passes very quickly and we already have a new version of the Linux kernel that as always we are happy because...

How to install RStudio on Ubuntu 20.04 / 18.04

No matter how complete and robust a programming language is, the programmer will always need a tool to write the code. These programs have...

How to install Arduino IDE on Ubuntu 20.04 / 18.04 / Linux Mint 19.X?

Hi, folks. In this post, we will show you how to install Arduino IDE on Ubuntu 20.04/ 18.04 and Linux mint 19.x. You probably already...

How To Install Icinga 2 on Ubuntu 20.04

Today we are going to learn that how to Install Icinga 2 on Ubuntu 20.04. Before going to the installation process let's...