关于c#:Cent OS logrotate不旋转httpd日志

关于c#: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
}

但在周末,当日志需要轮换时,却没有轮换。新的空文件创建了,但仍然是空的,而最后一个轮换的文件却不断增长。然后我必须重新启动httpd服务才能再次开始记录。

问题是什么?

答案1

您的日志未被轮换,因为它们的大小尚未达到 50 MB。

由于您指定了size,因此基于日期的常规日志轮换不会生效。相反,当日志超过指定大小时,即使该时间超过一周或一个月或其他指定的任何时间段,也会轮换日志。

如手册页所示:

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.

相关内容