大家论坛-大家学习网论坛计算机专区Linux论坛Linux高级应用 → Apache日志分割工具cronolog

意见反馈-google提供的广告

  共有938人关注过本帖树形打印

主题:Apache日志分割工具cronolog

帅哥哟,离线,有人找我吗?
Kernel
  1楼 个性首页 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:大家网初中一年级 贴子:202 金钱:914 金币:0 积分:77 魅力:50 精华:4 注册:2008-4-16 20:49:00
Apache日志分割工具cronolog  发贴心情 Post By:2008-7-2 14:55:00

为了分析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后,可以看到日志已经产生了新的带时间的版本

0  回到顶部