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

fpg*_*ost 15 logrotate segmentation-fault apache-2.4

每次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
Run Code Online (Sandbox Code Playgroud)

我的 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
}
Run Code Online (Sandbox Code Playgroud)

我将默认日志保留在 中/var/log/apache2,但我将特定于vhost 的日志(针对此服务器上托管的三个不同 vhost)保留在/srv/apache/log目录中(例如mysite1_error.logmysite1_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
Run Code Online (Sandbox Code Playgroud)

哪里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
Run Code Online (Sandbox Code Playgroud)

其他网站也类似。

任何人都知道为什么 logrotate 会导致这次崩溃?

还有一件事:

以 root 身份手动强制 logrotate:

logrotate -v -f /etc/logrotate.d/apache2
Run Code Online (Sandbox Code Playgroud)

不会导致 seg 错误,但我知道它是 logrotate,因为我已经尝试过与时间(每周、每天)一起玩,并且 seg 错误总是在仅轮换日志时发生。

如何按需复制

# 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
Run Code Online (Sandbox Code Playgroud)

最后

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

fpg*_*ost 13

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

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