您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

apache 的日志轮询

2024/6/21 11:55:08发布22次查看
【疑问】 将httpd.conf 配置文件中的customlog 参数改为下面的,就可以将 日志 按每天生成一个 日志 文件. customlog |bin/rotatelogs.exe logs/access_%y%m%d.log 86400 480 common rotatelogs.exe 就是apache提供用来做多 日志 文件的处理程序,从上面配
【疑问】
将httpd.conf 配置文件中的customlog 参数改为下面的,就可以将日志按每天生成一个日志文件.
customlog |bin/rotatelogs.exe logs/access_%y%m%d.log 86400 480 common
rotatelogs.exe 就是apache提供用来做多日志文件的处理程序,从上面配置来看,apache实际上是通过“管道”(由命令前的竖线|判断)将要输出的日志信息传给rotatelogs.exe程序,由该程序负责日志的分割。
86400 是指每 86400 ( 一天的秒数 ) 86400为轮转的时间,单位为秒。86400s=24h=1天
, 480 指 gmt + 8 ( 以分钟计 , gmt -1 下 -60 ) .这样 apache 就会自动在该换日时换一个档案名称.480为时差,文件的时间为美国时间,中国的时差要比美国多8个小时也就是480分钟,所以要加上480分钟。
rotatelogs说明
rotatelogs logfile [ rotationtime [ offset ]] | [ filesizem ]
选项
logfile
它加上基准名就是日志文件名。如果logfile中包含’%',则它会被视为用于的strftime(3)的格式字串;否则,它会被自动加上以秒为单位的.nnnnnnnnnn后缀。这两种格式都表示新的日志开始使用的时间。
rotationtime
日志文件回卷的以秒为单位的间隔时间
offset
相对于utc的时差的分钟数。如果省略,则假定为0,并使用utc时间。比如,要指定utc时差为-5小时的地区的当地时间,则此参数应为-300。
filesizem
指定回卷时以兆字节为单位的后缀字母m的文件大小,而不是指定回卷时间或时差。
【实例讲解】
customlog |/application/apache/bin/rotatelogs /app/logs/access_%y-%m-%d-%h_%m_%s 2m +480 combined
详解:
access_%y-%m-%d-%h_%m_%s为生成日志的格式,类似于这样:access_2010-04-15-11_32_30,以年月日时分秒为单位。
2m 为日志的大小,即为日志达到多大后生成新的日志文件,支持的单位为k,m,g,本处为2m。
【疑问】
customlog |/application/apache/bin/rotatelogs /app/logs/access_%y-%m-%d-%h_%m_%s 2m +480 combined
+480 前面有加号和没有加号有什么区别?如果是减号是什么意思?
测试如下:
[root@wanqiu extra]# date
2012年 01月 29日 星期日 16:29:45 cst
格式1:【不加480】
customlog |/application/apache/bin/rotatelogs /app/logs/access_%y-%m-%d-%h_%m_%s 2m combined
重启apache后查看日志,显示如下:
[root@wanqiu extra]# ll /app/logs/
总计 8
-rw-r--r-- 1 root root 172 01-29 16:29 access_2012-01-29-08_29_45
格式2:【加480,前面没有+号】
customlog |/application/apache/bin/rotatelogs /app/logs/access_%y-%m-%d-%h_%m_%s 2m 480 combined
重启apache后查看日志,显示如下:
[root@wanqiu extra]# ll /app/logs/
总计 16
-rw-r--r-- 1 root root 172 01-29 16:29 access_2012-01-29-08_29_45
-rw-r--r-- 1 root root 172 01-29 16:32 access_2012-01-29-16_32_52
格式3:【加480,前面有+号】
    customlog |/application/apache/bin/rotatelogs /app/logs/access_%y-%m-%d-%h_%m_%s 2m +480 combined
重启apache后查看日志,显示如下:
[root@wanqiu extra]# ll /app/logs/
总计 24
-rw-r--r-- 1 root root 172 01-29 16:29 access_2012-01-29-08_29_45
-rw-r--r-- 1 root root 172 01-29 16:32 access_2012-01-29-16_32_52
-rw-r--r-- 1 root root 172 01-29 16:37 access_2012-01-29-16_37_39
格式4:【加480,前面有-号】
    customlog |/application/apache/bin/rotatelogs /app/logs/access_%y-%m-%d-%h_%m_%s 2m -480 combined
重启apache后查看日志,显示如下:
[root@wanqiu extra]# ll /app/logs/
总计 32
-rw-r--r-- 1 root root 172 01-29 16:41 access_2012-01-29-00_41_48
-rw-r--r-- 1 root root 172 01-29 16:29 access_2012-01-29-08_29_45
-rw-r--r-- 1 root root 172 01-29 16:32 access_2012-01-29-16_32_52
-rw-r--r-- 1 root root 172 01-29 16:37 access_2012-01-29-16_37_39
初秋
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product