为了分析apache日志,我们需要定时将日志文件分割出来,这样类似webalizer等日志分析程序
才能非常方便的统计数据。apache默认配置的rotatelogs只能是按照一定时间或者一定文件大小来分割,而我们通常需要得到的是一整天或者一个
小时的日志数据,为了解决这个问题,我采用了第三方的一个程序cronolog
在
http://www.cronolog.org下载源码包,在root用户下执行下面的指令
./tar
-xzvf cronolog-1.6.2.tar.gz
cd cronolog-1.6.2
./configure
make
make install
正常编译以后会在默认目录/usr/local/sbin下有一个cronolog文件
在任何目录测试执行cronolog,应该显示出cronolog的帮助内容
usage: cronolog [OPTIONS]
logfile-spec
-H NAME, --hardlink=NAME maintain a hard link from
NAME to current log
-S NAME, --symlink=NAME maintain a symbolic link
from NAME to current log
-P NAME, --prev-symlink=NAME maintain a
symbolic link from NAME to previous log
-l NAME, --link=NAME same
as -S/--symlink
-h, --help print this help, then exit
-p PERIOD, --period=PERIOD set the rotation period explicitly
-d
DELAY, --delay=DELAY set the rotation period delay
-o,
--once-only create single output log from template (not rotated)
-x
FILE, --debug=FILE write debug messages to FILE
( or to standard error if FILE is "-")
-a, --american
American date formats
-e, --european European date
formats (default)
-s, --start-time=TIME starting time
-z TZ,
--time-zone=TZ use TZ for timezone
-V, --version print
version number, then exit
至此,cronolog部分安装完毕,转到apache的配置文件,在原有日志设置的地方修改成下面的样子
CustomLog
"|/usr/local/sbin/cronolog /opt/logs/access_log.%Y-%m-%d"
combined
当然你需要确认这些路径是否符合你的系统设置,上面是按照每天进行日志翻滚,如果需要其他的翻滚设置,可以参考cronolog的帮助文件。
重新启动apache后,可以看到日志已经产生了新的带时间的版本