Gentoo,Linux上Apache的日志滚动和自动化清理


发布日期 : 2013-09-24 05:20:00 UTC

访问量: 132 次浏览

By admin on 2010年07月15日

我的机器是gentoo有良好的配置文件结构

首先制定apache的滚动策略,编辑apache的配置文件,在我的gentoo上如下:

1 emacs /etc/apache2/modules.d/00_ mod _ log _ config.conf 

修改CustomLog 为如下格式:

1 CustomLog"|/usr/sbin/rotatelogs /var/log/apache2/access_log 86400" common

重启apache,然后我自己写了个脚本用来删除过期的日志文件,并放到系统的crontab里。判断日志数量,如果大于5,就找出最早的一个并删除 1 2 3 4 5 6 7

! /bin/bash let num=`ls -al /var/log/apache2 |grep access_log. | wc -l` if [
$num -gt 5 ] ; then logfile=`ls -lt /var/log/apache2 | awk '/access_log./ {
f=$NF };END{ print f }'` rm -rf /var/log/apache2/"$logfile" fi copy

到每天执行一次的目录里

1 cp ~/scripts/cleanapachelog.sh /etc/cron.daily/

重启

cron 1 /etc/init.d/vixie-cron restart 

参考文章 http://www.gentoo.org/doc/zh_tw/cron-guide.xml http://httpd.apache.org/docs/2.2/logs.html