目前我正在查看我的Apache日志文件的大小,因为它们变得巨大。 在我的logrotateconfiguration中,我启用了delaycompress 。 Apache是否真的需delaycompress (因为logrotate文档说有些程序仍然在旧文件中写入)还是禁用delaycompress是安全的?
这是我的logrotateconfiguration:
/var/log/apache2/*.log { weekly missingok rotate 26 compress delaycompress notifempty create 640 root adm sharedscripts postrotate if [ -f /var/run/apache2.pid ]; then /etc/init.d/apache2 restart > /dev/null fi endscript }
如果你正在做一个Apache重启(甚至是“优雅”),它将closures打开的文件句柄并再次打开它们。 您不应该需要延迟压缩,因为文件将被closures并重新打开,作为重新启动的一部分。
rotate access_log -> access_log.1 (rename action, no INODE change) apache still writing to access_log.1 (same open FD on same INODE) apache restart (close FD, release INODE writing) apache writing to access_log (new FD to a new INODE)
重新启动是一个坏主意 – 如果configuration文件意外更改,不再有效? 你的apache不会启动。 而是发送一个HUP给父进程,告诉它closures/重新打开文件句柄。
postrotate /bin/kill -HUP `cat /var/run/apache2.pid 2>/dev/null` 2>/dev/null || true endscript
如果PID丢失(或空或无效)导致kill也失败,则cat将失败,因此不需要围绕它的if..then块。
Hrm,在这种情况下,可能是Apache保持打开日志。
你可以尝试的一件事是rotatelogs脚本。 它是apache2-utils包的一部分,至less在我的Ubuntu工作站上。 另一种方法是每天轮换它们,而不是每周轮换一次,所以在压缩之前缓冲很less。