• Categories
    Category
  • Categories
    Category
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial 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
6235

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

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

Related Tutorials in How to Setup and Manage Logrotate in centos7.6

Related Tutorials in How to Setup and Manage Logrotate in centos7.6

How To Install AnyDesk on Centos 7
How To Install AnyDesk on Centos 7
Apr 2, 2018
How to install Tiki Wiki CMS Groupware on CentOS 7
How to install Tiki Wiki CMS Groupware on CentOS 7
May 31, 2018
How to install PHP ImageMagick on CentOS 7
How to install PHP ImageMagick on CentOS 7
Nov 4, 2017
How to Upgrade and Downgrade the PHP Versions on CentOS 7.6
How to Upgrade and Downgrade the PHP Versions on CentOS 7.6
Jun 4, 2019
How to install Apache from Source Code on CentOS 7
How to install Apache from Source Code on CentOS 7
Oct 21, 2017
How to enable or disable repositories in CentOS
How to enable or disable repositories in CentOS
Mar 28, 2018
How to install AWStats on CentOS 7
How to install AWStats on CentOS 7
Dec 8, 2017
How to install Apache JMeter in CentOS 7
How to install Apache JMeter in CentOS 7
Mar 24, 2017

Related Forums in How to Setup and Manage Logrotate in centos7.6

Related Forums in How to Setup and Manage Logrotate in centos7.6

CentOS
connor class=
How To Completely Remove Apache package On CentOS 7.6
May 14, 2019
CentOS
ceriaimmaculate class=
setfacl : command not found
Jan 3, 2018
CentOS
mason class=
Error getting authority: Error initializing authority: Could not connect: No such file or directory (g-io-error-quark, 1)
Nov 20, 2018
CentOS
landon class=
Command to find SNMP Version
May 28, 2018
CentOS
arjitharon class=
cannot start minio service help
Mar 10, 2018
Apache tomcat
AadrikaAnshu class=
Cannot find ./catalina.sh The file is absent or does not have execute permission This file is needed to run this program
Jun 17, 2019
gitlab
caden class=
Insufficient space in download directory /var/cache/yum/x86_64/6/base/packages
Jul 22, 2019
OpenVAS
frank class=
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"
Dec 20, 2018
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 Luke ?
workbench for debian

I am using workbench in CentOS whereas now I need to use Debian Operating system so could you please help to install and use in Debian?

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.