我们设置了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的,旋转,但仍然没有压缩。
这让我有点抓狂,任何帮助都将受到感激。
3条答案
按热度按时间kgsdhlau1#
根据日志,它看起来像是在运行/bin/gzip,通常gzip会压缩所有列出的文件--跳过任何丢失的文件--没有任何问题。请注意,如果结果较大,gzip不会强制压缩文件,这很容易发生在非常小的文件上。“错误:error [..]”消息可能不是来自gzip,它倾向于在错误前面加上“gzip::“.
检查文件大小,看看它们是否很小(或者更具体地说,如果gzip认为压缩它们会使它们更大)。
类似的注解为notifempty。
delaycompress只是意味着你可以有.1.2.3.4.gz.5.gz等。这是 * 没有 * 必要使压缩工作,实际上使它跳过压缩最近的几个文件。您可以同时使用这两个函数,或者只使用compress函数,而不是delaycompress函数本身。
奇怪的是,你没有频率/大小{每天|周刊|size ___ }。我从来没有试过不戴眼镜就用。
vxqlmq5t2#
针对您观察到的延迟压缩不起作用的问题,请注意,delaycompress功能仅在下一个循环周期中压缩前一个日志文件。如
man logrotate
中所述yrwegjxp3#
-f
强制旋转,-d
调试模式仅显示更多信息,-v
详细模式