logrotate 无法轮换日志,出现“没有这样的文件错误”

logrotate 无法轮换日志,出现“没有这样的文件错误”

logrotate 无法轮转我的日志。我检查了文件权限,没有问题。

我甚至尝试在配置文件中输入“su root root”,但仍然面临同样的问题。

相关详细信息如下:

logrotate.conf 文件:

/var/log/testlog {
    compress
    delaycompress
    dateext
    maxage 180
    rotate 15
    size 1024M
    start 1
    rotate 15
    missingok
}

调试日志:[使用“-d”选项]

rotating pattern: /var/log/testlog  1073741824 bytes (15 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/testlog
  log needs rotating
rotating log /var/log/testlog, log->rotateCount is 15
dateext suffix '-20140708'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
compressing log with: /bin/gzip
renaming /var/log/testlog.15.gz to /var/log/testlog.16.gz (rotatecount 15, logstart 1, i 15), 
renaming /var/log/testlog.14.gz to /var/log/testlog.15.gz (rotatecount 15, logstart 1, i 14), 
renaming /var/log/testlog.13.gz to /var/log/testlog.14.gz (rotatecount 15, logstart 1, i 13), 
renaming /var/log/testlog.12.gz to /var/log/testlog.13.gz (rotatecount 15, logstart 1, i 12), 
renaming /var/log/testlog.11.gz to /var/log/testlog.12.gz (rotatecount 15, logstart 1, i 11), 
renaming /var/log/testlog.10.gz to /var/log/testlog.11.gz (rotatecount 15, logstart 1, i 10), 
renaming /var/log/testlog.9.gz to /var/log/testlog.10.gz (rotatecount 15, logstart 1, i 9), 
renaming /var/log/testlog.8.gz to /var/log/testlog.9.gz (rotatecount 15, logstart 1, i 8), 
renaming /var/log/testlog.7.gz to /var/log/testlog.8.gz (rotatecount 15, logstart 1, i 7), 
renaming /var/log/testlog.6.gz to /var/log/testlog.7.gz (rotatecount 15, logstart 1, i 6), 
renaming /var/log/testlog.5.gz to /var/log/testlog.6.gz (rotatecount 15, logstart 1, i 5), 
renaming /var/log/testlog.4.gz to /var/log/testlog.5.gz (rotatecount 15, logstart 1, i 4), 
renaming /var/log/testlog.3.gz to /var/log/testlog.4.gz (rotatecount 15, logstart 1, i 3), 
renaming /var/log/testlog.2.gz to /var/log/testlog.3.gz (rotatecount 15, logstart 1, i 2), 
renaming /var/log/testlog.1.gz to /var/log/testlog.2.gz (rotatecount 15, logstart 1, i 1), 
renaming /var/log/testlog.0.gz to /var/log/testlog.1.gz (rotatecount 15, logstart 1, i 0), 
renaming /var/log/testlog to /var/log/testlog.1
removing old log /var/log/testlog.16.gz
error: error opening /var/log/testlog.16.gz: No such file or directory

详细输出:

rotating pattern: /var/log/testlog  1073741824 bytes (15 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/testlog
  log needs rotating
rotating log /var/log/testlog, log->rotateCount is 15
dateext suffix '-20140625'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
compressing log with: /bin/gzip
renaming /var/log/testlog.15.gz to /var/log/testlog.16.gz (rotatecount 15, logstart 1, i 15), 
old log /var/log/testlog.15.gz does not exist
renaming /var/log/testlog.14.gz to /var/log/testlog.15.gz (rotatecount 15, logstart 1, i 14), 
old log /var/log/testlog.14.gz does not exist
renaming /var/log/testlog.13.gz to /var/log/testlog.14.gz (rotatecount 15, logstart 1, i 13), 
old log /var/log/testlog.13.gz does not exist
renaming /var/log/testlog.12.gz to /var/log/testlog.13.gz (rotatecount 15, logstart 1, i 12), 
old log /var/log/testlog.12.gz does not exist
renaming /var/log/testlog.11.gz to /var/log/testlog.12.gz (rotatecount 15, logstart 1, i 11), 
old log /var/log/testlog.11.gz does not exist
renaming /var/log/testlog.10.gz to /var/log/testlog.11.gz (rotatecount 15, logstart 1, i 10), 
old log /var/log/testlog.10.gz does not exist
renaming /var/log/testlog.9.gz to /var/log/testlog.10.gz (rotatecount 15, logstart 1, i 9), 
old log /var/log/testlog.9.gz does not exist
renaming /var/log/testlog.8.gz to /var/log/testlog.9.gz (rotatecount 15, logstart 1, i 8), 
old log /var/log/testlog.8.gz does not exist
renaming /var/log/testlog.7.gz to /var/log/testlog.8.gz (rotatecount 15, logstart 1, i 7), 
old log /var/log/testlog.7.gz does not exist
renaming /var/log/testlog.6.gz to /var/log/testlog.7.gz (rotatecount 15, logstart 1, i 6), 
old log /var/log/testlog.6.gz does not exist
renaming /var/log/testlog.5.gz to /var/log/testlog.6.gz (rotatecount 15, logstart 1, i 5), 
old log /var/log/testlog.5.gz does not exist
renaming /var/log/testlog.4.gz to /var/log/testlog.5.gz (rotatecount 15, logstart 1, i 4), 
old log /var/log/testlog.4.gz does not exist
renaming /var/log/testlog.3.gz to /var/log/testlog.4.gz (rotatecount 15, logstart 1, i 3), 
old log /var/log/testlog.3.gz does not exist
renaming /var/log/testlog.2.gz to /var/log/testlog.3.gz (rotatecount 15, logstart 1, i 2), 
old log /var/log/testlog.2.gz does not exist
renaming /var/log/testlog.1.gz to /var/log/testlog.2.gz (rotatecount 15, logstart 1, i 1), 
renaming /var/log/testlog.0.gz to /var/log/testlog.1.gz (rotatecount 15, logstart 1, i 0), 
old log /var/log/testlog.0.gz does not exist
log /var/log/testlog.16.gz doesn't exist -- won't try to dispose of it
renaming /var/log/testlog to /var/log/testlog.1

ls /var/log/testlog* 的输出:

/var/log/testlog  
/var/log/testlog.1  
/var/log/testlog.2.gz
  • 'testlog' 是位于 /var/log/ 的日志文件的名称。我直接从命令行调用 'logrotate',如下所示:

    logrotate logrotate.conf [我自己的conf文件,内容复制自上面]

有人可以给我一些提示来解决这个问题吗?

谢谢

答案1

它报告一个错误,因为找不到尚未创建的最早的轮换日志文件。所以在我看来这是一个错误。它不应该因此而失败。

因此,当您收集了最大数量的轮换日志(15)时,错误消息将消失。在此期间,您可以放心地忽略该消息。

看起来有一个关于此的错误报告这里

答案2

您需要使用 -v 运行才能真正看到任何变化:

-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.

答案3

我创建了一个与 logrotate 需要的同名文件,

例如

/var/log/testlog.16.gz

然后重新运行 logrotate -d xx.conf错误已经消失。

这对我有用。

答案4

我的一个系统实际上遇到了一个问题,其中缺少一个日志文件:

mail.log
mail.log.5.gz
mail.log.6.gz

这意味着它将休息尝试重命名mail.log.4.gz并停止处理该文件夹。不用说,mail.log 文件变得越来越大(250Mb,而限制应该是 10Mb)。

我通过将文件重命名为 1 和 2 而不是 5 和 6 来解决了该问题并重新运行,logrotate并且它按预期工作。

mail.log
mail.log.1.gz
mail.log.2.gz

那么该错误还没有完全修复,是吗?

相关内容