• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to Setup and Manage Logrotate in centos7.6

  • 00:26 cd /etc/logrotate.d/
  • 00:36 vim apache
  • 01:54 vim /var/log/httpd/access_log
  • 02:08 vim /var/log/httpd/error_log
  • 02:21 cd /mnt
  • 02:26 mkdir test
  • 02:32 logrotate -f /etc/logrotate.d/apache
  • 02:33 cd test
  • 02:50 gunzip access_log.1.gz
  • 02:58 gunzip error_log.1.gz
  • 03:09 vim access_log.1
{{postValue.id}}

How to setup and Manage logrotate in Centos

Process

Change Directory to default logrotate directory

[root@linuxhelp ~]# cd /etc/logrotate.d/
 [root@linuxhelp logrotate.d]# ls -la
total 80
drwxr-xr-x.   2 root root  258 Jun 17 15:21 .
drwxr-xr-x. 146 root root 8192 Dec  3 10:42 ..
-rw-r--r--.   1 root root   91 Apr 11  2018 bootlog
-rw-r--r--.   1 root root  160 Sep 15  2017 chrony
-rw-r--r--.   1 root root   71 Apr 11  2018 cups
-rw-r--r--.   1 root root  626 Oct 13  2017 glusterfs
-rw-r--r--    1 root root  194 Apr 24  2019 httpd
-rw-r--r--.   1 root root  172 Sep 30  2016 iscsiuiolog
-rw-r--r--.   1 root root  165 Oct 31  2018 libvirtd
-rw-r--r--.   1 root root  142 Oct 31  2018 libvirtd.qemu
-rw-r--r--    1 root root  893 Aug 16  2018 mariadb
-rw-r--r--.   1 root root  106 Apr 11  2018 numad
-rw-r--r--.   1 root root  136 Jun 10  2014 ppp
-rw-r--r--.   1 root root  408 Aug  3  2017 psacct
-rw-r--r--.   1 root root  115 Oct 31  2018 samba
-rw-r--r--.   1 root root  237 Oct 31  2018 sssd
-rw-r--r--.   1 root root  224 Oct 30  2018 syslog
-rw-r--r--.   1 root root  100 Oct 31  2018 wpa_supplicant
-rw-r--r--.   1 root root  103 Nov  5  2018 yum

Create a your custom logrotate configuration file

[root@linuxhelp logrotate.d]# vim apache
/var/log/httpd/* {
weekly
create 0644 root root
rotate 5
size 100M
dateext
dateformat -%d%m%y
compress
olddir /mnt/test/
notifempty
}

To check the Existing apache’s access log

 [root@linuxhelp logrotate.d]# vim /var/log/httpd/access_log 

To check the Existing apache’s error log

[root@linuxhelp logrotate.d]# vim /var/log/httpd/error_log 

Change directory

[root@linuxhelp logrotate.d]# cd /mnt

create Directory

[root@linuxhelp mnt]# mkdir test

Run logrotate forcely by executing the following command

[root@linuxhelp mnt]# logrotate -f /etc/logrotate.d/apache 

Then change directory to test

[root@linuxhelp mnt]# cd test
[root@linuxhelp test]# ls -la
total 8
drwxr-xr-x  2 root root  51 Dec  3 10:59 .
drwxr-xr-x. 3 root root  18 Dec  3 10:58 ..
-rw-r--r--  1 root root 255 Jun 17 15:30 access_log.1.gz
-rw-r--r--  1 root root 958 Dec  3 10:42 error_log.1.gz

Unzip the rotated log file

[root@linuxhelp test]# gunzip access_log.1.gz 
 [root@linuxhelp test]# gunzip error_log.1.gz 

Check the rotated log file and original log file

[root@linuxhelp test]# vim access_log.1 

1

Log file become empty when the logrotate has done

 [root@linuxhelp test]# vim /var/log/httpd/access_log 

With this, the method to setup and Manage logrotate in Centos comes to end

Tags:
mason
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

What is logrotate?

A

logrotate is designed to easy administration of systems.It allows automatic rotation, compression, removal and mailing of log files.
Log Rotation depends on weekly, monthly and year, or size

Q

How to specify date in rotated log file?

A

To specify date in rotated log file use the below option in configuration file
dateext

Q

How to mail the rotated log to the Administrator?

A

To mail the rotated log to the Administrator use the below option in the configuration
mail abc@mydomain.com

Q

How to store the rotated log in a specific location?

A

To store the rotated log in specific location use the below option in the configuration
olddir

Q

What is the use of notifempty option in configuration?

A

The use of notifempty option in the configuration is skip logrotate if the file is empty

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Isaiah ?
What is the use of SUID & SGID commands

How to set the special permissions to the files and folders using SUID and SGID commands...

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.