logrotate 不压缩
Logrotate not compressing
我们将 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
我也尝试过使用 delaycompress,因为有些人已经成功了。
LR 可以很好地轮换日志,只是根本不对它们执行压缩。
查看该输出中唯一听起来有误的部分:
error: error opening /var/log/centrallogs/site1_access.log.6.gz: No such file or directory
我认为 LR 可能会被吓坏,因为它没有要删除的 .gz 文件,所以我创建了所需的日志文件的每个变体,它 运行 一夜之间,清除了 gz,旋转, 但还是没有压缩。
这让我有点抓狂,如有任何帮助,我们将不胜感激。
根据日志,它看起来像是 运行 /bin/gzip,通常 gzip 会压缩所有列出的文件 - 跳过任何丢失的文件 - 没有问题。请注意,如果结果较大,gzip 不会强制压缩文件,这很容易发生在非常小的文件上。 "error: error [..]" 消息可能不是来自 gzip,它倾向于在错误前加上 "gzip: :".
检查文件大小以查看它们是否很小(或者更具体地说,如果 gzip 认为压缩它们会使它们变大)。
notifempty 的类似评论。
delaycompress 只是意味着你可以有 .1 .2 .3 .4.gz .5.gz 等等。它 不是 压缩工作所必需的,实际上它会跳过压缩最近的几个文件。您可以同时使用两者,或者只是压缩,而不是单独使用 delaycompress。
很奇怪你没有 frequency/size { daily |每周 | size ___ } 在你的文件中。我从来没有尝试过在没有它们的情况下使用它们。
特别回应您的观察,延迟压缩不起作用 - 请注意,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.
logrotate -fv /etc/logrotate.d/centrallogs
-f
强制旋转,-d
调试模式只显示更多信息,-v
详细模式
我们将 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
我也尝试过使用 delaycompress,因为有些人已经成功了。
LR 可以很好地轮换日志,只是根本不对它们执行压缩。
查看该输出中唯一听起来有误的部分:
error: error opening /var/log/centrallogs/site1_access.log.6.gz: No such file or directory
我认为 LR 可能会被吓坏,因为它没有要删除的 .gz 文件,所以我创建了所需的日志文件的每个变体,它 运行 一夜之间,清除了 gz,旋转, 但还是没有压缩。
这让我有点抓狂,如有任何帮助,我们将不胜感激。
根据日志,它看起来像是 运行 /bin/gzip,通常 gzip 会压缩所有列出的文件 - 跳过任何丢失的文件 - 没有问题。请注意,如果结果较大,gzip 不会强制压缩文件,这很容易发生在非常小的文件上。 "error: error [..]" 消息可能不是来自 gzip,它倾向于在错误前加上 "gzip: :".
检查文件大小以查看它们是否很小(或者更具体地说,如果 gzip 认为压缩它们会使它们变大)。
notifempty 的类似评论。
delaycompress 只是意味着你可以有 .1 .2 .3 .4.gz .5.gz 等等。它 不是 压缩工作所必需的,实际上它会跳过压缩最近的几个文件。您可以同时使用两者,或者只是压缩,而不是单独使用 delaycompress。
很奇怪你没有 frequency/size { daily |每周 | size ___ } 在你的文件中。我从来没有尝试过在没有它们的情况下使用它们。
特别回应您的观察,延迟压缩不起作用 - 请注意,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.
logrotate -fv /etc/logrotate.d/centrallogs
-f
强制旋转,-d
调试模式只显示更多信息,-v
详细模式