为什么 logrotate 每次都会导致 Apache 出现分段错误?

为什么 logrotate 每次都会导致 Apache 出现分段错误?

每次logrotate运行 Apache/2.4.7 (Ubuntu) 都会遇到段错误并且无法重新启动:

[Wed Sep 10 06:35:54.266018 2014] [mpm_event:notice] [pid 20599:tid 140630283466624] AH00493: SIGUSR1 received.  Doing graceful restart
[Wed Sep 10 06:35:54.885118 2014] [core:notice] [pid 20599] AH00060: seg fault or similar nasty error detected in the parent process

我的 apache logrotate 脚本如下所示:

/var/log/apache2/*.log {
    daily
    missingok
    rotate 52
    compress
    delaycompress
    notifempty
    create 640 root adm
    sharedscripts
    postrotate
        /usr/sbin/apachectl graceful
    endscript
    prerotate
        if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
            run-parts /etc/logrotate.d/httpd-prerotate; \
        fi; \
    endscript
}

/srv/apache/log/*.log {
    daily
    missingok
    rotate 52
    compress
    delaycompress
    notifempty
    create 640 root adm
    sharedscripts
    postrotate
        /usr/sbin/apachectl graceful
    endscript
    prerotate
        if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
            run-parts /etc/logrotate.d/httpd-prerotate; \
        fi; \
    endscript
}

我将默认日志保存在 中,但我将/var/log/apache2vhost 特定日志(针对此服务器上托管的三个不同 vhost)保存在 目录中/srv/apache/log(例如mysite1_error.log,,,.... )。mysite1_access.logmysite2_error.logmysite2_access.log

相关部分/etc/apache2/apache.conf

#/etc/apache2/apache.conf
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel trace8   # I set to try and get more info about this problem.
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

其中export APACHE_LOG_DIR=/var/log/apache2$SUFFIX。在我的 vhost conf 文件中,例如 /etc/apache2/sites-enabled/mysite1.conf

#/etc/apache2/sites-enabled/mysite1.conf
LogLevel debug
ErrorLog  /srv/apache/log/mysite1_error.log
CustomLog /srv/apache/log/mysite2_access.log combined

其他网站也类似。

有人知道为什么 logrotate 会导致这次崩溃吗?

还有一件事:

以 root 身份手动强制 logrotate:

logrotate -v -f /etc/logrotate.d/apache2

不会导致段错误,但我知道这是 logrotate,因为我尝试过调整时间(每周、每天),而段错误总是在日志旋转时准确发生。

如何按需复制

# Set a crontab to run each minute (simulating cron.daily run of logrotate)
crontab -e
*/1 * * * * root /usr/sbin/logrotate -v -f /etc/logrotate.d/apache2 > /home/myuser/logrotate.log 2>&1

最后

如果我注释掉段错误/srv/apache/log/*.log中的旋转块,/etc/logrotate.d/apache也不会发生。

答案1

似乎如果我将 logrotate 脚本更改为单个块,即/var/log/apache2/*.log, /srv/apache/logs/*.log {....}我不会遇到段错误。所以只是两个块在第一次重启时导致第二次重启尝试...

如果我apache2ctl graceful & apache2ctl graceful & apache2ctl graceful & apache2ctl graceful &在命令行中输入,我的系统确实会出现段错误,这似乎证实了

相关内容