Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Feb 2007 13:24:18 -0500
From:      "David Robillard" <david.robillard@gmail.com>
To:        "FreeBSD Questions" <freebsd-questions@freebsd.org>
Cc:        Peter Pluta <peter@placidpublishing.net>
Subject:   Re: Apache Rotate Logs and Log Rotate.
Message-ID:  <226ae0c60702151024u6c71d50bn72d54631c33ed32@mail.gmail.com>

next in thread | raw e-mail | index | archive | help
> I have Apache making separate log files for each of my virtual hosts and
> putting them in /home/vhostname/log. Rotate logs makes a new log every
> 24 hours, but the logs quickly add up and since the sites are fairly
> busy the logs are at times over 5gigs. Is there any way to make rotate
> logs delete the log files after two days? Someone recommended me Log
> Rotate (from the ports tree), but this program does basically what
> Rotate logs does; except it makes things more complicated because it
> needs to restart apache and such. Is there a easy way to just have
> Apache's rotatelogs rotate the logs and then delete them after two days?
>
> Any feedback, suggestions, or comments would be greatly appreciated.

Hi Peter,

I personaly don't use neither Log Rotate nor Rotate Logs, but
configure newsyslog.conf(5) to handle the job of Apache log rotation
and clean-up.

The newsyslog software is part of FreeBSD's base system, so you don't
need to install anything. Just configure /etc/newsyslog.conf and
that's it. No need to restart anything because newsyslog is already
active in FreeBSD's base system via /etc/crontab. It can rotate the
logs, compress them with either gzip(1) or bzip2(1) and remove the old
ones to preserve disk space.

For example, let's say you have two virtual host's logs into
/home/vhostname1/log and /home/vhostname2/log, you can configure
newsyslog to:

a) Keep only 10 log files. Remove the older ones as they grow. (i.e.
10 in the config below)
b) Create files with chmod 640 and owner root:www (i.e. root:www and 640)
c) Rotate the files when they reach 1Mb in size. (i.e. 1048576)
d) Compress the files with gzip(1) to preserve compatibility with
webalizer. (i.e. Z)

# logfilename          [owner:group]    mode count size when  flags
[/pid_file] [sig_num]

# Host vhostname1.
#
/home/vhostname1/log/access.log  root:www    640 10 1048576 * Z
/var/run/httpd.pid
/home/vhostname1/log/error.log      root:www    640 10 1048576 * Z
/var/run/httpd.pid

# Host vhostname2.
#
/home/vhostname2/log/access.log  root:www    640 10 1048576 * Z
/var/run/httpd.pid
/home/vhostname2/log/error.log      root:www    640 10 1048576 * Z
/var/run/httpd.pid

Check the man pages for newsyslog(8) and newsyslog.conf(8) for more information.

I've been using this for more then two years now and it works like a charm.

HTH,

David
-- 
David Robillard
UNIX systems administrator & Oracle DBA
CISSP, RHCE & Sun Certified Security Administrator
Montreal: +1 514 966 0122



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?226ae0c60702151024u6c71d50bn72d54631c33ed32>