ApacheI’ve been using Apache for quite some time, having many custom scripts that do chores for me. Recently I was asked to install Apache on a machine, a few yum installs and some editing of the Apache vhost files later I was all set.

Because the site being served by Apache started to grow I noticed that the log files got big, I had completely forgotten to have a script rotate the log files!

At the office we simply have a script that has been doing just that since Apache 1.x, this script also runs fine with Apache 2.x. Because I never use office related scripts anywhere outside the office, I decided to look around and encountered rotatelogs which is included with Apache 2.x.

The use of rotatelogs is actually quite simple. I currently have a CustomLog entry for a vhost I use that enables some extra information per client. This is mostly needed for AWStats.

I change the line:

CustomLog /var/logs/apache/www.labcoding.com/access_log combined

To

CustomLog “|/usr/sbin/rotatelogs /var/logs/apache/www.labcoding.com/access_log.%Y-%m-%d 86400″ combined

That is all! This will rotate my apache logs daily :)

Now check if the syntax is OK and give Apache a graceful.

[CaliMonk@DYV001 vhosts]$ /usr/sbin/apachectl configtest
Syntax OK
[CaliMonk@DYV001 vhosts]$ sudo /usr/sbin/apachectl graceful

The changes become active immediately, be sure to check:

[CaliMonk@DYV001 vhosts]$ cd /var/logs/apache/www.labcoding.com
[CaliMonk@DYV001 www.labcoding.com]$ ls -alh
total 552M
drwxr-xr-x 2 apache apache 4.0K Jan 29 00:09 .
drwxr-xr-x 4 apache apache 4.0K Jan 17 23:42 ..
-rw-r–r– 1 root root 551M Jan 29 00:09 access_log
-rw-r–r– 1 root root 7.0K Jan 29 00:10 access_log.2008-01-28
-rw-r–r– 1 root root 1.1M Jan 29 00:09 error_log

Nice addition to Apache 2.0!

- Ivo

Share and Enjoy:
  • Digg
  • del.icio.us
  • Furl
  • Slashdot
  • Spurl
  • StumbleUpon
  • Technorati