我有安装了logrotate 3.8.6的CentOS 7.4。我在/etc/logrotate.d/
下有一个自定义的logrotate文件,用于在安装在同一台机器上的Tomcat (例如,catalina.out)上轮换一些日志。
/opt/test/apache-tomcat-8.5.15-client/logs/catalina.out {
copytruncate
daily
rotate 30
olddir /opt/test/apache-tomcat-8.5.15-client/logs/backup
compress
missingok
maxsize 50M
dateext
dateformat .%Y-%m-%d
}
我希望日志每天轮换,或者如果大小达到50MB。发生这种情况时,日志文件将被压缩并复制到备份文件夹中,并在删除之前保留30天。
我已经在调试模式下使用以下命令手动运行logrotate,没有显示任何错误(并且创建了预期的压缩日志文件):
/usr/sbin/logrotate -d /etc/logrotate.d/openncp-tomcat-backoffice 2> /tmp/logrotate.debug
在/var/lib/logrotate/logrotate.status
中没有问题,文件显示为旋转,但实际上并非如此:
"/var/log/yum.log" 2017-11-27-19:0:0
"/opt/test/apache-tomcat-8.5.15-server/logs/catalina.out" 2017-12-15-3:41:1
"/var/log/boot.log" 2017-12-15-3:41:1
"/var/log/up2date" 2017-11-27-19:0:0
我有默认的/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
# 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.
我也有默认的/etc/cron.daily/logrotate
#!/bin/sh
/usr/sbin/logrotate -s /var/lib/logrotate/logrotate.status /etc/logrotate.conf
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
我请求您对此进行适当配置的指导。
发布于 2018-07-30 05:33:55
要回答您关于使用daily
和maxsize
的问题(如标题中所示),请注意,在默认情况下,logrotate
每天运行一次,因此这意味着maxsize
在这种情况下几乎没有用。该文件无论如何都会被旋转(当然,假设您没有使用SELinux )。
当然,因为logrotate
仍然每天检查文件,所以maxsize
对于每周和每月都很有用。
https://stackoverflow.com/questions/47838164
复制相似问题