随着时间的推移,我注意到一些日志,/var/log
例如auth
,kern
并且messages
变得越来越大。我logrotate
为他们做了条目:
$ cat /etc/logrotate.d/auth.log
/var/log/kern.log {
rotate 5
daily
}
$ cat /etc/logrotate.d/kern.log
/var/log/kern.log {
rotate 5
daily
}
$ cat /etc/logrotate.d/messages
/var/log/messages {
rotate 5
daily
postrotate
/bin/killall -HUP syslogd
endscript
}
Run Code Online (Sandbox Code Playgroud)
我也compress
启用了该选项:
$ grep compress /etc/logrotate.conf
# uncomment this if you want your log files compressed
compress
Run Code Online (Sandbox Code Playgroud)
这个伟大工程auth.log
,kern.log
和其他人,这意味着每个这些日志被gzip压缩和旋转,用日志的最近5天保留。/var/log/messages
但是没有被压缩,导致日志超过 5 天:
$ ls /var/log/messages*
/var/log/messages /var/log/messages-20100213
/var/log/messages-20100201 /var/log/messages-20100214
/var/log/messages-20100202 …
Run Code Online (Sandbox Code Playgroud)