【问题标题】:Logrotate doesn't work automatically (using size limit)Logrotate 不能自动工作(使用大小限制)
【发布时间】:2013-11-06 15:02:32
【问题描述】:

我的轮换似乎不起作用。如果我手动执行 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
}

有什么线索吗?

【问题讨论】:

  • 您是否有定期运行logrotatecron 作业(或其他调度程序)?它不会自己神奇地运行......
  • 是的...它每次运行都会写一个日志。
  • 它还在同一个文件中运行其他旋转,所以不用担心它不是靠魔法运行的。

标签: logrotate


【解决方案1】:

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

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

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

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

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

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

【讨论】:

    猜你喜欢
    • 2018-06-01
    • 2020-09-04
    • 2018-07-29
    • 2011-09-26
    • 2013-12-28
    • 2015-05-02
    • 2017-09-13
    • 2020-04-20
    • 1970-01-01
    相关资源
    最近更新 更多