Thursday, November 18, 2010

Apache daily Logrotate in linux

Apache log rotation : access_logs etc...etc...

In Linux kernel, program daemons, firewalls, etc, generate their respective log files and they are everywhere. In fact, there are so many log files of various levels that sometimes, it can be a nightmare to maintain them.

Log files are one of the most important files where almost all precious and sometimes unnecessary information are stored in regard to your server’s running state.

tail -f /var/log/messages ” is the command if you want to get feel and see the actual current logs generated by various daemons running on your system.

Now if your server also has a Apache Web server running and you want to manage their respective logs in your own fashion, then the following information might help you out.

How to see them

tail -f /var/log/httpd/access_log

First of all, you will need the program called “logrotate”. Logrotate is very useful utility which can rotate log files and archive them in a location that you specify. We will be using “logrotate” in conjunction with “cron“.

By Default the logrotate.conf file have weekly rotation of logs and logs are kept for 4 weeks.

cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files daily
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
minsize 1M
create 0664 root utmp
rotate 1
}


if you want to change them then you have to change the
weekly ---->daily
rotation
4---->2
like below.....

cat /etc/logrotate.conf
# see "man logrotate" for details
# rotate log files daily
daily

# keep 4 weeks worth of backlogs
rotate 2

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp -- we'll rotate them here
/var/log/wtmp {
monthly
minsize 1M
create 0664 root utmp
rotate 1
}

# system-specific logs may be also be configured here.


or you can use command to do the same

perl -pi -e 's/weekly/daily/' /etc/logrotate.conf
perl -pi -e 's/rotate 4/rotate 2/' /etc/logrotate.conf

To cross check
logrotate -dv /etc/logrotate.d/httpd

No comments:

Post a Comment