logrotate 不根据大小旋转日志

logrotate not rotating logs based on size

我正在使用 logrotate 旋转目录 /var/test/log 中可用的 test.log 日志文件。下面是 logrotate 配置文件的片段

DO NOT MODIFY THIS FILE.

/var/test/log/test.log { daily nocompress copytruncate missingok rotate 10 size 2M }

如配置所示,文件的大小应为 2Mb,如果文件超过此大小,则应进行轮换,但当我尝试执行以下命令时并没有发生这种情况

/usr/sbin/logrotate -d /var/test/testlogrotate reading config file /var/test/testlogrotate reading config info for /var/test/log/test.log

Handling 1 logs

rotating pattern: /var/test/log/test.log 2097152 bytes (10 rotations) empty log files are rotated, old logs are removed considering log /var/test/log/test.log log needs rotating rotating log /var/test/log/test.log, log->rotateCount is 10 renaming /var/test/log/test.log.10 to /var/test/log/test.log.11 (rotatecount 10, logstart 1, i 10), renaming /var/test/log/test.log.9 to /var/test/log/test.log.10 (rotatecount 10, logstart 1, i 9), renaming /var/test/log/test.log.8 to /var/test/log/test.log.9 (rotatecount 10, logstart 1, i 8), renaming /var/test/log/test.log.7 to /var/test/log/test.log.8 (rotatecount 10, logstart 1, i 7), renaming /var/test/log/test.log.6 to /var/test/log/test.log.7 (rotatecount 10, logstart 1, i 6), renaming /var/test/log/test.log.5 to /var/test/log/test.log.6 (rotatecount 10, logstart 1, i 5), renaming /var/test/log/test.log.4 to /var/test/log/test.log.5 (rotatecount 10, logstart 1, i 4), renaming /var/test/log/test.log.3 to /var/test/log/test.log.4 (rotatecount 10, logstart 1, i 3), renaming /var/test/log/test.log.2 to /var/test/log/test.log.3 (rotatecount 10, logstart 1, i 2), renaming /var/test/log/test.log.1 to /var/test/log/test.log.2 (rotatecount 10, logstart 1, i 1), renaming /var/test/log/test.log.0 to /var/test/log/test.log.1 (rotatecount 10, logstart 1, i 0), copying /var/test/log/test.log to /var/test/log/test.log.1 truncating /var/test/log/test.log removing old log /var/test/log/test.log.11

但是我在 /var/test/log 目录中没有看到任何像 test.log.1 这样的文件。我还可以看到 test.log 文件的大小为 2.3Mb。

帮我解决这个问题。

您正在使用 -d,这意味着 logrotate 的调试模式。在调试模式下,logrotate 仅模拟其操作。没有采取任何实际行动。来自 man page:

-d, --debug

Turns on debug mode and implies -v. In debug mode, no changes will be made to the logs or to the logrotate state file.