Logrotation 不适用于 nginx

Logrotation 不适用于 nginx

我正在尝试使用 Logrotate 轮换 nginx 日志。它将日志附加到同一个文件(error.log 和 access.log),但不是每天轮换。以下是相同的配置文件。如果我遗漏了什么,请告诉我。

/var/log/nginx/*.log {
        daily
        missingok
        rotate 52
        compress
        delaycompress
        notifempty
        create 640 nginx adm
        sharedscripts
        postrotate
                [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
        endscript
}

$ 更多 /etc/cron.daily/logrotate

#!/bin/sh

/usr/sbin/logrotate  /etc/logrotate.conf >/dev/null 2>&1
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0

SELinux 状态

# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /selinux
Current mode:                   enforcing
Mode from config file:          enforcing
Policy version:                 24
Policy from config file:        targeted

答案1

你确定你没有遗漏 cat 命令周围的“`”吗?根据:http://drumcoder.co.uk/blog/2012/feb/03/nginx-and-logrotate/

您还可以查看 /var/log/audit/audit.log 中有关“nginx”的信息,默认情况下会启动审计系统 auditd。如果 auditd 守护进程未运行,则消息将写入 /var/log/messages,因此也请检查那里。

还要检查 nginx.pid 的路径是否正确。你可能在 /usr/local/nginx 或 /opt 或类似位置有 nginx。

答案2

还要检查磁盘空间。我有时会遇到虚拟机上的日志轮换无法正常工作的情况,我在 /var/log/messages 中看到的唯一错误是“ALERT 正常退出,错误代码为 [1]”。问题是我剩余的磁盘空间很少,它可能无法压缩我的日志文件。我清理了一下,它又开始工作了。

相关内容