【问题标题】:messages log is not rotated via logrotate config消息日志不通过 logrotate 配置轮换
【发布时间】:2021-05-25 06:16:05
【问题描述】:

我按照我在网上找到的一些说明通过旋转 aws ec2 实例来应用日志轮换,我发现在 /var/log/messages 上应用它的最简单方法是通过以下格式:

[root@ip-192-168-1-69 ~]# cat /etc/logrotate.d/messages 
/var/log/messages {
    daily
    create 0600 root root
    rotate 3
    size=1M
    compress
    delaycompress
    notifempty
}

我还不知道 logrotate 什么时候会发生,所以我只是在第二天检查它并看到了这个结果

[root@ip-192-168-1-69 ~]# ls -ltrh /var/log/messages*
-rw------- 1 root root   0 May 24 13:25 /var/log/messages
-rw------- 1 root root 16M May 25 06:09 /var/log/messages-20210510

它确实轮换了,但是我注意到新日志现在转到 /var/log/messages-20210510 而不是 /var/log/messages,并且还在第 2 天和第 3 天检查没有发生 tgz 日志轮换。 /var/log/messages-20210510 仍然使用新日志进行更新。

我从 /etc/logrotate.d 看到了这个配置,但我不确定这是否与我创建的配置冲突

[root@ip-192-168-1-69 ~]# cat /etc/logrotate.d/syslog 
/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
    sharedscripts
    postrotate
        /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
    endscript
}

请分享并告知我在这里错过了什么,提前谢谢

【问题讨论】:

标签: logging amazon-ec2 logrotate


【解决方案1】:

似乎从全局配置中添加了一些不需要的指令。我建议您使用您提到的配置手动轮换日志(使用以下命令)。它会清楚地告诉您配置是否按预期工作以进一步调试问题。

$ sudo logrotate /etc/logrotate.d/messages

如果此命令也没有给您预期的输出,请尝试在底部的/etc/logrotate.d/rsyslog 文件中添加以下配置。

/var/log/messages {
    daily
    create 0600 root root
    rotate 3
    size 1M
    compress
    delaycompress
    notifempty
}

现在再次尝试使用logrotate 命令手动轮换日志。我觉得应该可以。

注意:不要忘记从 rsyslog 文件中的常用配置中删除现有行 /var/log/messages

【讨论】:

    猜你喜欢
    • 2017-03-29
    • 1970-01-01
    • 2018-10-12
    • 2010-11-16
    • 2011-09-26
    • 1970-01-01
    • 2019-02-20
    • 1970-01-01
    • 2012-12-18
    相关资源
    最近更新 更多