Logrotate不会自动工作(使用大小限制)

问题描述 投票:1回答: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
}

任何线索?

logrotate
1个回答
3
投票

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

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

这些设置无法同时运行。无论是时间还是大小。对于访问日志,我建议每日轮换。

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

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

logrotate还有maxsize参数,它应该与基于时间的旋转一起工作(每天,每周等),但我不确定它是否有效。你需要做实验。

© www.soinside.com 2019 - 2024. All rights reserved.