为什么不压缩/ var / log上的第二个日志文件


12

/var/log/(Debian / Ubuntu)上的日志存储为

x.log
x.log.1
x.log.2.gz
...

如内核日志,系统日志等。

我看到随着日志信息的增加,它们通过拆分成较小的文件(而不是全部保存在一个文件中)进行存储。我想知道为什么第二个文件(x.log.1)没有压缩?与更轻松地访问最新日志有关吗?

Answers:


12

我同意您的观点,那只能使您更轻松地访问最新文件。无论如何,实际行为是由logrotate'delaycompress'指令决定的,该指令表示'不要在旋转时压缩文件,而是在下次压缩它'。

历史原因可以在logrotate手册中找到:

Postpone  compression of the previous log file to the next rotation 
cycle.  This has only effect when used in combination  with compress. 
It can be used when some program can not be told to close its logfile and 
thus might continue writing to the  previous log file for some time.

1
“(...)无法通知某些程序立即关闭其日志文件,从而关闭(...)”。在Server Fault一文中发现了这种精度。
Ludovic Kuty '16

5

是的,这样做是为了使更容易访问更多最新的日志文件。logrotate选项delaycompress对此进行控制。从logrotate联机帮助页:

延迟压缩

Postpone compression of the previous log file to the next rotation cycle.  
This only has effect when used in combination with
compress.  It can be  used  when  some  program
cannot be told to close its logfile and thus might 
continue writing to the previous log file for some time.

4
这些选项在/etc/logrotate.conf和下的文件中使用/etc/logrotate.d/*
slm
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.