gpt4 book ai didi

linux - Logrotate daily+maxsize不旋转

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:18:16 24 4
gpt4 key购买 nike

我的 CentOS 7.4 安装了 logrotate 3.8.6。我在 /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 天。

我已经使用以下命令在 Debug模式下手动运行了 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

我请求您提供适当配置的指导。

最佳答案

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

关于linux - Logrotate daily+maxsize不旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47838164/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com