【问题标题】:Logrotate not compressingLogrotate 不压缩
【发布时间】:2015-12-05 15:16:10
【问题描述】:

我们设置了 syslogd 以将来自几个不同服务器的所有日志发送到一个服务器中,全部发送到一个名为 /var/log/centrallogs 的文件夹中。

我们为此目录使用以下日志轮换配置:

/etc/logrotate.d/centrallogs:

/var/log/centrallogs/*log {
        rotate 5
        compress
        missingok
        notifempty
        sharedscripts
        postrotate
        /etc/init.d/httpd restart > /dev/null 2>/dev/null || true
        endscript
}

在测试中(使用 logrotate -d centrallogs)LR 似乎没有尝试进行任何旋转。

这是输出(注意,我已重命名网站,但这是我所做的唯一更改):

rotating pattern: /var/log/centrallogs/*log  1048576 bytes (5 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/centrallogs/site1_access.log
  log needs rotating
considering log /var/log/centrallogs/site1_error.log
  log does not need rotating
considering log /var/log/centrallogs/site2_access.log
  log needs rotating
considering log /var/log/centrallogs/site2_error.log
  log needs rotating
considering log /var/log/centrallogs/site3_access.log
  log needs rotating
considering log /var/log/centrallogs/site3_error.log
  log needs rotating
rotating log /var/log/centrallogs/site1_access.log, log->rotateCount is 5
dateext suffix '-20150908'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /var/log/centrallogs/site1_access.log.5.gz to /var/log/centrallogs/site1_access.log.6.gz (rotatecount 5, logstart 1, i 5), 
renaming /var/log/centrallogs/site1_access.log.4.gz to /var/log/centrallogs/site1_access.log.5.gz (rotatecount 5, logstart 1, i 4), 
renaming /var/log/centrallogs/site1_access.log.3.gz to /var/log/centrallogs/site1_access.log.4.gz (rotatecount 5, logstart 1, i 3), 
renaming /var/log/centrallogs/site1_access.log.2.gz to /var/log/centrallogs/site1_access.log.3.gz (rotatecount 5, logstart 1, i 2), 
renaming /var/log/centrallogs/site1_access.log.1.gz to /var/log/centrallogs/site1_access.log.2.gz (rotatecount 5, logstart 1, i 1), 
renaming /var/log/centrallogs/site1_access.log.0.gz to /var/log/centrallogs/site1_access.log.1.gz (rotatecount 5, logstart 1, i 0), 
rotating log /var/log/centrallogs/site2_access.log, log->rotateCount is 5
dateext suffix '-20150908'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /var/log/centrallogs/site2_access.log.5.gz to /var/log/centrallogs/site2_access.log.6.gz (rotatecount 5, logstart 1, i 5), 
renaming /var/log/centrallogs/site2_access.log.4.gz to /var/log/centrallogs/site2_access.log.5.gz (rotatecount 5, logstart 1, i 4), 
renaming /var/log/centrallogs/site2_access.log.3.gz to /var/log/centrallogs/site2_access.log.4.gz (rotatecount 5, logstart 1, i 3), 
renaming /var/log/centrallogs/site2_access.log.2.gz to /var/log/centrallogs/site2_access.log.3.gz (rotatecount 5, logstart 1, i 2), 
renaming /var/log/centrallogs/site2_access.log.1.gz to /var/log/centrallogs/site2_access.log.2.gz (rotatecount 5, logstart 1, i 1), 
renaming /var/log/centrallogs/site2_access.log.0.gz to /var/log/centrallogs/site2_access.log.1.gz (rotatecount 5, logstart 1, i 0), 
rotating log /var/log/centrallogs/site2_error.log, log->rotateCount is 5
dateext suffix '-20150908'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /var/log/centrallogs/site2_error.log.5.gz to /var/log/centrallogs/site2_error.log.6.gz (rotatecount 5, logstart 1, i 5), 
renaming /var/log/centrallogs/site2_error.log.4.gz to /var/log/centrallogs/site2_error.log.5.gz (rotatecount 5, logstart 1, i 4), 
renaming /var/log/centrallogs/site2_error.log.3.gz to /var/log/centrallogs/site2_error.log.4.gz (rotatecount 5, logstart 1, i 3), 
renaming /var/log/centrallogs/site2_error.log.2.gz to /var/log/centrallogs/site2_error.log.3.gz (rotatecount 5, logstart 1, i 2), 
renaming /var/log/centrallogs/site2_error.log.1.gz to /var/log/centrallogs/site2_error.log.2.gz (rotatecount 5, logstart 1, i 1), 
renaming /var/log/centrallogs/site2_error.log.0.gz to /var/log/centrallogs/site2_error.log.1.gz (rotatecount 5, logstart 1, i 0), 
rotating log /var/log/centrallogs/site3_access.log, log->rotateCount is 5
dateext suffix '-20150908'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /var/log/centrallogs/site3_access.log.5.gz to /var/log/centrallogs/site3_access.log.6.gz (rotatecount 5, logstart 1, i 5), 
renaming /var/log/centrallogs/site3_access.log.4.gz to /var/log/centrallogs/site3_access.log.5.gz (rotatecount 5, logstart 1, i 4), 
renaming /var/log/centrallogs/site3_access.log.3.gz to /var/log/centrallogs/site3_access.log.4.gz (rotatecount 5, logstart 1, i 3), 
renaming /var/log/centrallogs/site3_access.log.2.gz to /var/log/centrallogs/site3_access.log.3.gz (rotatecount 5, logstart 1, i 2), 
renaming /var/log/centrallogs/site3_access.log.1.gz to /var/log/centrallogs/site3_access.log.2.gz (rotatecount 5, logstart 1, i 1), 
renaming /var/log/centrallogs/site3_access.log.0.gz to /var/log/centrallogs/site3_access.log.1.gz (rotatecount 5, logstart 1, i 0), 
rotating log /var/log/centrallogs/site3_error.log, log->rotateCount is 5
dateext suffix '-20150908'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /var/log/centrallogs/site3_error.log.5.gz to /var/log/centrallogs/site3_error.log.6.gz (rotatecount 5, logstart 1, i 5), 
renaming /var/log/centrallogs/site3_error.log.4.gz to /var/log/centrallogs/site3_error.log.5.gz (rotatecount 5, logstart 1, i 4), 
renaming /var/log/centrallogs/site3_error.log.3.gz to /var/log/centrallogs/site3_error.log.4.gz (rotatecount 5, logstart 1, i 3), 
renaming /var/log/centrallogs/site3_error.log.2.gz to /var/log/centrallogs/site3_error.log.3.gz (rotatecount 5, logstart 1, i 2), 
renaming /var/log/centrallogs/site3_error.log.1.gz to /var/log/centrallogs/site3_error.log.2.gz (rotatecount 5, logstart 1, i 1), 
renaming /var/log/centrallogs/site3_error.log.0.gz to /var/log/centrallogs/site3_error.log.1.gz (rotatecount 5, logstart 1, i 0), 
renaming /var/log/centrallogs/site1_access.log to /var/log/centrallogs/site1_access.log.1
renaming /var/log/centrallogs/site2_access.log to /var/log/centrallogs/site2_access.log.1
renaming /var/log/centrallogs/site2_error.log to /var/log/centrallogs/site2_error.log.1
renaming /var/log/centrallogs/site3_access.log to /var/log/centrallogs/site3_access.log.1
renaming /var/log/centrallogs/site3_error.log to /var/log/centrallogs/site3_error.log.1
running postrotate script
running script with arg /var/log/centrallogs/*log : "
    /etc/init.d/httpd restart > /dev/null 2>/dev/null || true
"
compressing log with: /bin/gzip
removing old log /var/log/centrallogs/site1_access.log.6.gz
error: error opening /var/log/centrallogs/site1_access.log.6.gz: No such file or directory

我也尝试过使用延迟压缩,因为有些人已经成功了。

LR 可以很好地旋转原木,只是根本不对它们执行压缩。

查看该输出中唯一听起来错误的部分:

error: error opening /var/log/centrallogs/site1_access.log.6.gz: No such file or directory

我认为 LR 可能会吓坏了,因为它没有要删除的 .gz 文件,所以我创建了所需的每个日志文件变体,它运行了一夜,清除了 gz,旋转了,但仍然没有压缩。

这让我有点生气,任何帮助将不胜感激。

【问题讨论】:

  • 也许delaycompress 会有所帮助:serverfault.com/a/117009/253150
  • @Samuel 我试过了,不开心:(
  • 嗯,默认应该用gzip压缩。你能检查一下你的gzip 是不是/bin/gzip
  • @Samuel 从外观上看是这样的: whereis gzip gzip: /bin/gzip /usr/bin/gzip /usr/share/man/man1/gzip.1.gz
  • 好的,另一个问题。为什么是/etc/init.d/httpd restart 而不是/sbin/service httpd reload

标签: linux centos6 logrotate


【解决方案1】:
logrotate -fv /etc/logrotate.d/centrallogs

-f 强制旋转,-d 调试模式只显示更多信息,-v 详细模式

【讨论】:

    【解决方案2】:

    专门针对您观察到延迟压缩不起作用 - 请注意,delaycompress 工具仅在下一个轮换周期压缩前一个日志文件。正如man logrotate

    中所述
    delaycompress
          Postpone compression of the previous log file to the next rotation cycle.  
          This only has effect when used in combination with compress.  
    

    【讨论】:

      【解决方案3】:

      根据日志,它看起来像是在运行 /bin/gzip,通常 gzip 会压缩所有列出的文件 - 跳过任何丢失的文件 - 没有问题。请注意,如果结果较大,gzip 不会强制压缩文件,这很容易在非常小的文件上发生。 “error: error [..]” 消息可能不是来自 gzip,它往往会在错误前加上“gzip: :”。

      检查文件大小以查看它们是否很小(或者更具体地说,如果 gzip 认为压缩它们会使它们变大)。

      notifempty 的类似 cmets。

      延迟压缩只是意味着您可以拥有 .1 .2 .3 .4.gz .5.gz 等。 没有需要进行压缩工作,实际上可以跳过压缩最近的几个文件。您可以同时使用两者,或者只是压缩,而不是单独使用延迟压缩。

      奇怪的是你没有频率/大小 { 每天 |每周| ___ } 在您的文件中。我从来没有尝试过在没有它们的情况下使用它们。

      【讨论】:

      • 来自 gzip-1.5-10.el7.x86_64 的手册页:Compression is always performed, even if the compressed file is slightly larger than the original. The worst case expansion is a few bytes for the gzip file header, plus 5 bytes every 32K block, or an expansion ratio of 0.015% for large files. Note that the actual number of used disk blocks almost never increases. gzip preserves the mode, ownership and timestamps of files when compressing or decompressing.
      猜你喜欢
      • 2017-11-24
      • 2011-05-28
      • 2015-03-25
      • 2011-11-08
      • 2019-06-24
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      • 2013-03-24
      相关资源
      最近更新 更多