每日Logrotate + maxsize不旋转

时间:2017-12-15 18:42:11

标签: linux centos logrotate

我安装了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

我向您提供有关正确配置的指导。

2 个答案:

答案 0 :(得分:0)

问题与日志文件的SELinux文件类型有关,日志文件位于与/ var / log不同的目录中,这意味着logrotate进程无权执行其任务。我发现了其他SO thread以及有助于解决问题的Redhat page。我发现Redhat文档非常有用,所以我在这里提供了2个链接:

答案 1 :(得分:0)

要回答有关拥有dailymaxsize的问题(如标题中所示),请注意,默认情况下,logrotate每天都会运行一次,这意味着maxsize是在那种情况下几乎没有用。该文件仍然会旋转(当然,假设您没有SELinux)。

maxsize对于每周和每月都很有用,因为logrotate仍每天检查文件。