日志轮换:日志不需要轮换

7

logrotate没有对我的日志进行轮换

为了验证日志文件不为空:

# ls -laFh /var/log/cisco-meraki.log
-rw-r----- 1 root adm 2.8G Sep  5 13:23 /var/log/cisco-meraki.log

配置文件(/etc/logrotate.d/zzzzz_default):


"/var/log/cisco-meraki.log" {
    daily
    rotate 10
    compress
    missingok
    notifempty
    create
}

全局配置(logrotate.conf):

daily
rotate 10
create
include /etc/logrotate.d
/var/log/wtmp {
    missingok
    monthly
    create 0664 root utmp
    rotate 1
}
/var/log/btmp {
    missingok
    monthly
    create 0660 root utmp
    rotate 1
}

尝试手动运行:

# logrotate --verbose -d zzzzz_default
reading config file zzzzz_default

Handling 1 logs

rotating pattern: "/var/log/cisco-meraki.log"  after 1 days (10 rotations)
empty log files are not rotated, old logs are removed
considering log /var/log/cisco-meraki.log
  log does not need rotating

为了确认问题不是“已经旋转过”的,我进行了以下检查:
# cat /var/lib/logrotate/status|grep cisco
"/var/log/cisco-ace.log" 2016-1-19-16:0:0
"/var/log/cisco-pix.log" 2016-1-19-16:0:0
"/var/log/cisco-acs.log" 2016-1-19-16:0:0
"/var/log/cisco-asa.log" 2016-1-19-16:0:0
"/var/log/cisco-router.log" 2016-9-6-0:1:1
"/var/log/cisco-ips.log" 2016-1-19-16:0:0

..但没有 cisco-meraki.log 文件

3个回答

4
请查看https://unix.stackexchange.com/a/96947 假设您今天创建了zzzzz_default文件。logrotate将在/var/lib/logrotate/status中创建一个条目,好像今天已经旋转了日志
当您运行logrotate --verbose -d zzzzz_default今天时,logrotate会检查上次旋转日志的时间,并读取/var/lib/logrotate/status。它将找到之前创建的条目,因此它将说log does not need rotating 如果您明天运行logrotate --verbose -d zzzzz_default,logrotate将检查上次旋转日志的时间,并读取/var/lib/logrotate/status。它将找不到之前创建的条目,因此它将旋转日志文件。

4

来自logrotate手册:

      -d, --debug
           Turns on debug mode and implies -v.  In debug mode, no
           changes will be made to the logs or to the logrotate
           state file.

我也遇到了完全相同的问题!

N。


0
我遇到了同样的问题,最后发现这是一个文件权限问题,配置文件必须设置为root,然后在配置文件中使用su命令。
sudo chown root:root /etc/logrotate.d/xxx

/var/log/xxx.log {
    su ec2-user ec2-user
    daily
    rotate 10
    compress
    missingok
    notifempty
    create 644 ec2-user ec2-user
}

如果/etc/logrotate.d/xxx的所有者是ec2-user:ec2-user,执行sudo logrotate -f /etc/logrotate.d/xxx没有发生任何事情。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接