我已经安装了 logrotate 3.8.6 的 CentOS 7.4。我有一个自定义 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
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,而且几天过去了,没有任何轮换。
我要求您指导如何适当地配置它。
该问题与日志文件的 SELinux 文件类型有关,这些文件位于与 /var/log 不同的目录中,这意味着 logrotate 进程无权执行其任务。我发现this other SO thread以及this Redhat page帮助解决了这个问题。我发现 Redhat 文档很有帮助,所以我在这里提供了 2 个链接: