logrotate日志轮换
时间:2019-04-29 03:17:36 来源:igfitidea点击:
使用Linux logrotate管理日志文件
自动日志文件轮换 logrotate
日志文件的自动内务处理由称为logrotate
的例程处理。此过程大大降低了日志文件过大的风险。日志文件旋转过程通常由cron条目处理,该条目调用logrotate实用程序。
通常将需要管理的日志文件添加到名为/etc/logrotate.conf
的配置文件中。rpm
软件包日志在目录/etc/logrotate.d
中处理。在这些文件中,我们可以指定保留期和大小期,也可以指定要使用的压缩率。
/etc/logrotate.conf
文件示例
sles01:/ # cat /etc/logrotate.conf # see "man logrotate" for details # rotate log files weekly weekly # keep 4 weeks worth of backlogs rotate 4 # create new (empty) log files after rotating old ones create # use date as a suffix of the rotated file dateext # uncomment this if you want your log files compressed #compress # comment these to switch compression to use gzip or another # compression scheme compresscmd /usr/bin/bzip2 uncompresscmd /usr/bin/bunzip2 # former versions had to have the compressext set accordingly #compressext .bz2 # RPM packages drop log rotation information into this directory include /etc/logrotate.d # no packages own wtmp and btmp -- we'll rotate them here #/var/log/wtmp { # monthly # create 0664 root utmp # minsize 1M # rotate 1 #} # # /var/log/btmp { # missingok # monthly # create 0600 root utmp # rotate 1 #} # system-specific logs may be also be configured here.