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

Ang*_*ngs 12 logs

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

x.log
x.log.1
x.log.2.gz
...
Run Code Online (Sandbox Code Playgroud)

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

我看到随着日志信息的增加,它们通过拆分成更小的文件来存储(而不是将所有文件都保存在一个文件中)。我想知道为什么第二个文件 ( x.log.1) 没有被压缩?是否与更容易访问最近的日志有关?

小智 13

我同意您的看法,这只会让您更轻松地访问最近的文件。无论如何,实际行为是通过 logrotatedelaycompress指令决定的,它说:

不要在旋转时压缩文件,而是在下次压缩它

历史原因可以在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.
Run Code Online (Sandbox Code Playgroud)

  • “(...)当某些程序无法被告知**立即**关闭其日志文件时,因此(...)”。在 [关于服务器故障的帖子](http://serverfault.com/q/292513/77502) 中发现了这种精度。 (2认同)

jor*_*anm 6

是的,这样做是为了更容易访问最近的日志文件。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.
Run Code Online (Sandbox Code Playgroud)

  • 这些选项在`/etc/logrotate.conf` 和`/etc/logrotate.d/*` 下的文件中使用。 (5认同)