Log rotate in Redhat Linux

 Rotating Log

A list of log files maintained by rsyslogd can be found in the /etc/rsyslog.conf configuration file. Most log files are located in the /var/log/ directory. Some applications such as httpd and samba have a directory within /var/log/ for their log files.

You may notice multiple files in the /var/log/ directory with numbers after them (for example, cron-20100906). These numbers represent a time stamp that has been added to a rotated log file. Log files are rotated so their file sizes do not become too large. The logrotate package contains a cron task that automatically rotates log files according to the /etc/logrotate.conf configuration file and the configuration files in the /etc/logrotate.d/ directory.

you could see cron executaions 

# cat /etc/cron

cron.d/       cron.daily/   cron.deny     cron.hourly/  cron.monthly/ crontab       cron.weekly/

# ls /etc/cron.daily/

logrotate  man-db.cron  mlocate  prelink  readahead.cron  rhsmd


# cat /etc/cron.daily/logrotate
#!/bin/sh

/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0

important link https://www.redhat.com/sysadmin/setting-logrotate


#vi /etc/logrotate.conf
//here the log rotate and compress and backlog period everything configured

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

//include new log file on this rotation
//logrotate.conf file has been included /etc/logroate.d/ directory
//whatever the config written in /etc/lograte.d directory that would be taken cate of the rotate option
//hence i'm creating new log file config

//here I'm making a new log on the server, hence i put below config on rsyslog.con

#vi /etc/rsyslog.conf
#Newly created log that fetch all user SYSLOG
user.info /var/log/user.log


#vi /etc/logrotate.d/user
/var/log/user.log {
    create 0666 root root    
    weekly     
    missingok
    rotate 8
    compress
    notifempty
    sharedscripts
    dateext
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}

//now validate this config or exute

#logrotate -s /var/log/logstatus /etc/logrotate.conf
//execute specific file

#logrotate -f /etc/logrotate.conf
//execute all the file under logroate.d



Post a Comment

0 Comments