logrotate daily+maxsize 不轮转

logrotate daily+maxsize 不轮转

我已经安装了 CentOS 7.4 和 logrotate 3.8.6。我有一个自定义的 logrotate 文件,/etc/logrotate.d/用于轮换安装在同一台计算机上的 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

根据logrotate 联机帮助页:

maxsize size
    Log files are rotated when they grow bigger than size bytes even before the additionally specified time interval ( daily, weekly, monthly, or yearly). The related size option is similar except that it is mutually exclusive with the time interval options, and it causes log files to be rotated without regard for the last rotation time. When maxsize is used, both the size and timestamp of a log file are considered. 

我注意到到目前为止日志还没有达到 50MB,而且已经好几天没有任何轮换了。

我请求您指导如何正确配置它。

答案1

该问题与日志文件的 SELinux 文件类型有关,这些文件位于与 /var/log 不同的目录中,这意味着 logrotate 进程无权执行其任务。我找到了另一个所以线程还有这个红帽页面这有助于解决问题。我发现 Redhat 文档非常有帮助,因此我在这里提供了 2 个链接:

相关内容