2

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

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

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

非常感谢

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

/ # /opt/httpd/bin/rotatelogs --help 参数数量不正确 用法:/opt/httpd/bin/rotatelogs [-l] [-f] {|} [offset minutes from UTC]

添加这个:

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

或者

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

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

4

1 回答 1

1

根据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 之外)。

于 2012-03-14T16:16:38.083 回答