清除日志后在 CentOS 7 中强制重启 Apache

清除日志后在 CentOS 7 中强制重启 Apache

我有以下目录,其中存储了充满 17GB 错误的域日志:

/usr/local/apache/logs

每两个月我必须删除一次日志,因为它们变得像这样大。

清除日志后,我必须重新启动 Apache 才能真正清除日志:

systemctl restart httpd

清除后尝试上述命令时出现以下错误:

Job for httpd.service failed because the control process exited with error code. See "systemctl status httpd.service" and "journalctl -xe" for details.

我可以通过重新启动整个 Web 服务器来解决这个问题,但这确实不太好。只有在删除日志后才会发生这种情况。我认为像这样直接删除文件不是正确的做法。

答案1

centos 7 中 httpd 提供的 /etc/logrotate.d/httpd logrotate 配置文件几乎执行相同的操作(见下文)。

/var/log/httpd/*log {
missingok
notifempty
sharedscripts
delaycompress
postrotate
    /bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
endscript
}

日志轮换后执行 /bin/systemctl reload httpd.service。也许您的 http 服务出现了其他问题,在这种情况下,“systemctl status httpd”的输出或检查 /var/log/httpd/error_log 可能会提供更多信息。

相关内容