【问题标题】:Apache httpd rotatelogs: is it possible to create a new file every day?Apache httpd rotatelogs:是否可以每天创建一个新文件?
【发布时间】:2012-03-30 22:17:12
【问题描述】:

我想每隔 00:00:01(= 每个新的一天)为我的网站创建一个新日志。

rotatelogs 的问题在于,您可以在创建新日志之前精确地确定日志的最大大小,或者以秒为单位精确地旋转时间。不可能精确一个小时的旋转。

他们谈论“cronjobs”,但我不明白。有人可以解释一下是否可以,如果可以,请举个例子?

非常感谢

以下是rotatelogs 实用程序的帮助:

/ # /opt/httpd/bin/rotatelogs --help 参数数量不正确 用法:/opt/httpd/bin/rotatelogs [-l] [-f] {|} [与 UTC 的偏移分钟数]

添加这个:

TransferLog "|/opt/httpd/bin/rotatelogs /some/where 86400"

TransferLog "|/opt/httpd/bin/rotatelogs /some/where 5M"

到 httpd.conf。生成的名称将是 /some/where.nnnn where nnnn 是日志名义上开始的系统时间(注意,如果使用 旋转时间,时间总是旋转的倍数 时间,因此您可以与它同步 cron 脚本)。在每个结束时 旋转时间或达到文件大小时启动新日志。 / #

【问题讨论】:

    标签: apache logrotate


    【解决方案1】:

    根据manual page for rotatelogs这一段:

       rotationtime
              The time between log file rotations  in  seconds.  The  rotation
              occurs  at  the  beginning of this interval. For example, if the
              rotation time is 3600, the log  file  will  be  rotated  at  the
              beginning  of every hour; if the rotation time is 86400, the log
              file will be rotated every night at midnight.
    

    将 86400 设置为期间会做你想做的事(每天午夜开始的新文件)。

    如果您希望“午夜”位于您的本地时区而不是 UTC,也可以使用 -l 选项。

    需要 cronjob 的情况是,如果您想要一天的时间段,但时间段与午夜不同。更通用的工具,如 logrotate(在 apache 之外)通常用于此目的。

    【讨论】:

    • 从我的角度来看,如果你精确到3600 并且你从18:30 开始,那么下一个日志应该从19:30 开始。我不明白的是:at the beginning of this interval。他们给出的例子并没有帮助:864003600... 如果你精确到 366086401??
    • 我认为服务器的启动时间没有任何作用。如果给定 3600 作为旋转时间,服务器会将 unix 纪元(自 70 年 1 月 1 日 00:00 以来的秒数)除以 3600,并在该除法的余数为零时切换到新的日志文件(这发生在开头每小时)。如果给定 3660,则自 70 年 1 月 1 日 00:00 起每 7000 万次发生一次
    • 如果你说的是对的(很可能是这样),那么文档就是错误的。我会看一下,写一些测试用例,然后在我的博客上写一篇文章来解释这一点。非常感谢您的回答! =)
    • @user292916 我也在想同样的事情。你有没有开始写那篇博文?
    猜你喜欢
    • 1970-01-01
    • 2011-02-23
    • 2015-03-21
    • 2022-09-23
    • 1970-01-01
    • 2010-11-29
    • 1970-01-01
    • 2016-06-26
    • 2018-08-22
    相关资源
    最近更新 更多