今天妄图使用apache的rotatelogs来回卷Apache日志,翻看手册,很简单。
PS:我手上有APACHE2.2的英文手册。不过现在网络太方便了 还是在网站上看的 Apache2.2中文手册
1. 修改httpd.conf 文件
把原来的:
CustomLog logs/access_log common
修改为:
CustomLog “|/usr/local/httpd/bin/rotatelogs /var/logs/%Y%m%d%H_access_log 7200 480 5M″ common2
2. 测试下httpd.conf 文件的错误
httpd -t
显示:
Syntax OK!
3. 重启后收工
附:Apache中rotatelogs的使用方法
English原文:
rotatelogs [-l] <logfile> {<rotation time in seconds>|<rotation size in megabytes>} [offset minutes from UTC]
Add this:
TransferLog "|D:\httpd\apache\bin\rotatelogs /some/where 86400"
or
TransferLog "|D:\httpd\apache\bin\rotatelogs /some/where 5M"
to httpd.conf. The generated name will be /some/where.nnnn where nnnn is the
system time at which the log nominally starts (N.B. if using a rotation time,
the time will always be a multiple of the rotation time, so you can synchronize
cron scripts with it). At the end of each rotation time or when the file size
is reached a new log is started.
中文翻译:
rotatelogs [-l] <logfile> {<rotation time in seconds>|<rotation size in megabytes>} [offset minutes from UTC]
选项
logfile
它加上基准名就是日志文件名。如果logfile中包含’%',则它会被视为用于的strftime(3)的格式字串;否则,它会被自动加上以秒为单位的.nnnnnnnnnn后缀。这两种格式都表示新的日志开始使用的时间。
rotationtime
日志文件回卷的以秒为单位的间隔时间
offset
相对于UTC的时差的分钟数。如果省略,则假定为0,并使用UTC时间。比如,相对于UTC的时差分钟数,中国是第八时区,相差480分钟。
filesizeM
指定回卷时以兆字节为单位的后缀字母M的文件大小,而不是指定回卷时间或时差。
参考网址:
http://manual.phpv.net/apache22/programs/rotatelogs.html