2

# vim /etc/logrotate.d/syslog

----------------------------

/var/log/cron

/var/log/maillog

/var/log/messages

/var/log/secure

/var/log/spooler                            

{                                                   #-> Original File

    missingok

    sharedscripts

    postrotate

        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true

    endscript

}

---Edit-------Monthly  - 12 File ---------------------------

/var/log/cron /var/log/maillog /var/log/messages /var/log/secure /var/log/spooler {

        missingok

        sharedscripts

        postrotate

        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true

        endscript

        monthly

        rotate 12

}

------------------------------------

HOW TO CUSTOMIZE LOG ROTATE TIME DURATION

In this example case /var/log/maillog.log will be rotated yearly

1. By default system rotates all major OS logs by checking syslog file located in /etc/logrotate.d/

# vim /etc/logrotate.d/syslog

 

/var/log/cron

#/var/log/maillog

/var/log/messages

/var/log/secure

/var/log/spooler

{

sharedscripts

postrotate

/bin/kill -HUP 'cat /var/run/syslogd.pid 2> /dev/null' 2> /dev/null || true

endscript

}

 

2. To add separate log rotation policy for /var/log/maillog simply hash the entry in above syslog file and create separate file in /etc/logrotate.d/maillog

# cd /etc/logrotate.d/

# touch maillog

# chmod 644 maillog; chown root:root maillog

# vim maillog

 

/var/log/maillog {

yearly

rotate 2

}

 

 

Let’s execute a dry-run to see what logrotate would do if it was actually executed now. Use the -d option followed by the configuration file (you can actually run logrotate by omitting this option):

# logrotate -d /etc/logrotate.d/maillog

-------

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

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

===