我有一个CentOS 6.7盒,由于某种原因,无法每天旋转日志。 我每天在/ var / mail / root下收到一封类似于这个邮件的电子邮件:
To: [email protected] Content-Type: text/plain; charset="ANSI_X3.4-1968" Subject: Anacron job 'cron.daily' on server.nl Message-Id: <[email protected]> Date: Wed, 9 Mar 2016 03:42:02 +0100 (CET) /etc/cron.daily/logrotate: error: error creating unique temp file: Permission denied
运行logrotate -vf /etc/logrotate.conf按预期旋转日志,不会出现错误或警告。 SELinux已启用,所以我怀疑这可能是拒绝权限错误的原因,但/var/log/audit/audit.log在过去几周内没有任何内容。
我不知道如何解决什么是导致logrotate在夜间失败,而白天工作正常,如果我手动运行它。
另外3月10日:谢谢伊恩我已经能够得到什么( /tmp/logrotate.out在夜间做的日志输出,在/tmp/logrotate.out结束是以下行:
@rotating pattern: /var/log/btmp monthly (1 rotations) empty log files are rotated, old logs are removed considering log /var/log/btmp log does not need rotating set default create context error: error creating unique temp file: Permission denied
这不是我所期待的,因为它不是与我试图排除故障的Rails应用程序日志相关的错误。 通过不专注于错误信息本身(在韩国和俄罗斯只产生几个点击谷歌),但更多的是我遇到的实际问题,我发现logrotate cron作业不旋转某些日志 ,这是非常类似于问题我试图解决(我的nginx日志做旋转,它跳过了Rails日志)。 所以毕竟它可能是SELinux相关的,即使它没有出现在audit.log 。 我正在尝试在那里发布解决scheme。
我要做的第一件事情就是修改cron运行的logrotate脚本,并以详细模式运行logrotate。
我的脚本在/etc/cron.daily/logrotate中有这一行
/usr/sbin/logrotate /etc/logrotate.conf
我会改变它
/usr/sbin/logrotate -v /etc/logrotate.conf >>/tmp/logrotate.out 2>&1
您应该添加-s选项以logrotate指定(可写入)临时文件的path。