1

看来我的轮换不起作用。如果我手动执行 logrotate,它会正常工作。运行 logrotate 是因为我可以在日志中看到它。这是我所拥有的:

# 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

/home/www/logs/access_log {
    sharedscripts
    delaycompress
    size 2G
    compress
    dateext
    maxage 30
    postrotate
    /usr/local/bin/apachectl -k graceful
    endscript
}

有什么线索吗?

4

1 回答 1

3

这是一个老问题,但有人可能会觉得这很有帮助。

默认轮换设置表示每周轮换,但您的以下访问日志配置指定按大小轮换。

这些设置不会同时起作用。要么是时间,要么是规模。对于访问日志,我建议每天轮换。

如果您的日志在白天增长超过 2GB,那么您将需要每小时运行一次 logrotate。这可确保 logrotate 将检查日志的大小并相应地进行轮换。

但是,这意味着您必须在日志中添加时间戳,因为您希望在同一天拥有多个日志,对吗?

logrotate 还有一个 maxsize 参数,它应该与基于时间的轮换(每天、每周等)一起使用,但我不确定它是否有效。您将需要进行实验。

于 2018-09-26T09:34:54.883 回答