Cent OS的logrotate不会轮转httpd日志

我的/etc/logrotate.d/httpd文件的内容是

 /var/log/httpd/access.log { size=50M dateext maxage 90 postrotate /usr/bin/killall -HUP httpd ls -ltr /var/log/httpd/ | mail -s "$HOSTNAME: Apache restarted and log files rotated" [email protected] endscript } 

而我的/etc/logrotate.conf

 # see "man logrotate" for details # rotate log files weekly weekly # keep 4 weeks worth of backlogs rotate 4 # create new (empty) log files after rotating old ones create # use date as a suffix of the rotated file dateext # uncomment this if you want your log files compressed #compress # RPM packages drop log rotation information into this directory include /etc/logrotate.d # no packages own wtmp and btmp -- we'll rotate them here /var/log/wtmp { monthly create 0664 root utmp minsize 1M rotate 1 } /var/log/btmp { missingok monthly create 0600 root utmp rotate 1 } 

但是在周末,当日志预计将被旋转,它不是。 新的空文件被创build,但保持空,而最后一个旋转的文件不断增长。 然后,我必须重新启动httpd服务后,再次开始logging。

有什么问题?

你的日志没有被旋转,因为他们还没有达到50 MB的大小。

由于您指定了size ,所以正常的基于date的日志循环不会生效。 相反,日志在超过指定大小时会进行旋转,即使该时间超过一周或一个月,或者指定了其他时间段。

如手册页所示:

 size size Log files are rotated only if they grow bigger than size bytes. 

如果您希望每周轮换日志,但是如果超过50 MB,则希望快速轮换,然后使用maxsize 50M

 maxsize size Log files are rotated when they grow bigger than size bytes even before the additionally specified time interval (daily, weekly, monthly, or yearly). The related size option is similar except that it is mutually exclusive with the time interval options, and it causes log files to be rotated without regard for the last rotation time. When maxsize is used, both the size and timestamp of a log file are considered.