【问题标题】:AH00161: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers settingAH00161:服务器达到 MaxRequestWorkers 设置,考虑提高 MaxRequestWorkers 设置
【发布时间】:2016-08-23 19:47:43
【问题描述】:

我有一个非常繁忙的服务器:PHP (Wordpress) 使用 W3TotalCache APC、Varnish for Apache 和 Cloudflare 来处理所有流量。 Ubuntu 14.04.4 LTS

只有一个网站平均每天点击量约为 6 万次。

我不时收到此消息,一天几次。与暂时的流量高峰无关,我们将时间与 Google Analytics 进行了比较。

Thu Apr 28 14:14:42.938075 2016] [mpm_prefork:error] [pid 19137] AH00161: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting
[Thu Apr 28 15:43:25.594147 2016] [core:notice] [pid 19137] AH00051: child pid 19866 exit signal Segmentation fault (11), possible coredump in /etc/apache2
[Thu Apr 28 15:43:25.594313 2016] [core:notice] [pid 19137] AH00051: child pid 20386 exit signal Segmentation fault (11), possible coredump in /etc/apache2
[Thu Apr 28 15:43:25.594407 2016] [core:notice] [pid 19137] AH00051: child pid 19143 exit signal Segmentation fault (11), possible coredump in /etc/apache2
[Thu Apr 28 15:43:25.594498 2016] [core:notice] [pid 19137] AH00051: child pid 19144 exit signal Segmentation fault (11), possible coredump in /etc/apache2
[Thu Apr 28 15:43:25.594572 2016] [core:notice] [pid 19137] AH00051: child pid 20597 exit signal Segmentation fault (11), possible coredump in /etc/apache2
[Thu Apr 28 15:43:25.594642 2016] [core:notice] [pid 19137] AH00051: child pid 20395 exit signal Segmentation fault (11), possible coredump in /etc/apache2
[Thu Apr 28 15:43:25.594704 2016] [core:notice] [pid 19137] AH00051: child pid 20424 exit signal Segmentation fault (11), possible coredump in /etc/apache2
[Thu Apr 28 15:43:25.594785 2016] [core:notice] [pid 19137] AH00051: child pid 20598 exit signal Segmentation fault (11), possible coredump in /etc/apache2
[Thu Apr 28 15:43:25.594870 2016] [core:notice] [pid 19137] AH00051: child pid 19861 exit signal Segmentation fault (11), possible coredump in /etc/apache2
[Thu Apr 28 15:43:25.594957 2016] [core:notice] [pid 19137] AH00051: child pid 19782 exit signal Segmentation fault (11), possible coredump in /etc/apache2
....
....

所以我首先将 MaxRequestWorkers 增加到 100,然后增加到 500,现在增加到 1024。但仍在发生。

这是我目前的 apache2.conf。 代码:

<IfModule mpm_worker_module>
StartServers 256
MinSpareThreads 256
MaxSpareThreads 256
MaxClients 256
ServerLimit 256
ThreadLimit 256
ThreadsPerChild 256
MaxRequestWorkers 1024
MaxConnectionsPerChild 0
MaxRequestPerChild 1000
</IfModule>

有很多可用 RAM,平均负载约为 0.5,有时超过 1。但从未见过高于 2。因此服务器似乎可以正常处理流量。

top - 16:07:47 up 3 days, 18:18,  2 users,  load average: 0.57, 0.46, 0.55
Tasks: 113 total,   1 running, 112 sleeping,   0 stopped,   0 zombie
%Cpu(s): 10.5 us,  2.0 sy,  0.0 ni, 87.4 id,  0.1 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:   8176816 total,  2372560 used,  5804256 free,   189684 buffers
KiB Swap:        0 total,        0 used,        0 free.  1286692 cached Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                                                              
21930 www-data  20   0  337212  83308  60072 S  24.9  1.0   0:52.89 apache2                                                                                                                                              
21945 www-data  20   0  327640  72684  58816 S  24.3  0.9   0:48.37 apache2                                                                                                                                              
 1182 nobody    20   0  702868 442268  83496 S   0.7  5.4  42:41.32 varnishd

任何想法为什么 Apache 中断?

//j

【问题讨论】:

  • 我将 MaxRequestWorkers 增加到 5000,服务器已经稳定超过 24 小时。过去几周最长无需重启 apache。
  • 流量已增加到每天约 200 万次点击,我们也遇到了同样的问题。 StartServers 1024 MinSpareThreads 1024 MaxSpareThreads 1024 MaxClients 1024 ServerLimit 1024 ThreadLimit 1024 ThreadsPerChild 1024 MaxRequestWorkers 8192 MaxConnectionsPerChild 0 MaxRequestPerChild 4096 不添加更多服务器还能做些什么?
  • Stack Overflow 是一个编程和开发问题的网站。这个问题似乎离题了,因为它与编程或开发无关。请参阅帮助中心的What topics can I ask about here。也许Super UserUnix & Linux Stack Exchange 会是一个更好的提问地方。另见Where do I post questions about Dev Ops?

标签: apache ubuntu-14.04


【解决方案1】:

你应该编辑mpm_prefork

<IfModule mpm_prefork_module>
      StartServers                     10
      MinSpareServers               10
      MaxSpareServers              20
      ServerLimit                      2000
      MaxRequestWorkers         1500
      MaxConnectionsPerChild    10000
</IfModule>

【讨论】:

    【解决方案2】:

    在我的情况下,在响应速度较低之后,首先我将MaxRequestWorkers从150增加到500。但是在apacheerror.log中出现警告时,我意识到我也应该增加ServerLimit,因为它的默认值是256.另外,我在mpm_prefork.conf中没有找到ServerLimit 256,所以我在其中添加了ServerLimit 512作为新行,问题解决了。

    【讨论】:

      【解决方案3】:

      基本上配置被覆盖: /etc/apache2/mods-available/mpm_prefork.conf

      我将新设置放入该文件中,现在看来 Apache 可以正常工作了。

      希望这对其他人有所帮助,不要将您的配置直接放在 apache2.conf 或 httpd.conf 中。确保更改所有加载的配置文件。

      【讨论】:

      • 我很高兴它似乎为您解决了,但是当您说“我将新设置放入该文件中”时,您指的是哪个设置?什么是旧值,什么是新值?
      • 投反对票:此响应对其他人没有用 - 您不包括您实际进行的更改,也不提供有关其他人可以采取哪些措施来解决此问题的任何说明。请更新您替换的配置/键值对的有用信息/sn-ps/等。
      • @MattRabe 反对什么?除非您不熟悉 Apache 或... Linux 目录/文件,否则提供的答案是完全可以理解的。
      • @LucianoFantuzzi OP 选择他们自己的答案是正确的,尽管没有包括所有相关信息。 “新设置”......可以从页面的其余部分推断出关键和价值,但这个答案本身仍然缺乏完整性。如果 OP 会进行细微的修改以包含键和值,那么我完全赞成!
      【解决方案4】:

      就我而言,我找不到任何解决方案,所以我将把这个答案留在这里,以帮助其他遇到此问题的人。在我们的例子中,增加 MaxRequestWorkers 没有帮助。

      我们的服务器至少可以正常工作一年。突然之间,它开始出现连接 https 的问题。在 apache 错误日志中,我们发现“服务器已到达 MaxRequestWorkers”错误,但流量非常慢(30 - 40 名访问者活跃)。

      在深入查看日志和一些研究后,我发现问题是Slowloris DoS attack

      攻击很容易缓解。你可以看看this post

      【讨论】:

        【解决方案5】:

        我还尝试在我的服务器上增加MaxRequestWorkers,但没有看到任何效果。当我从命令行运行“httpd”时,我意识到发生了什么,它给了我这个警告:

        AH00180: WARNING: MaxRequestWorkers of 512 exceeds ServerLimit value of
         256 servers, decreasing MaxRequestWorkers to 256.
         To increase, please see the ServerLimit directive.
        

        在您的配置中,ServerLimit 仍然是 256,因此 MaxRequestWorkers 也受此值的限制。

        【讨论】:

          【解决方案6】:

          您修改了错误的文件。您的日志显示“mpm_prefork”错误。所以你需要修改mpm_prefork.conf而不是mpm_worker.conf。

          您也可以使用“apachectl -M”查看您正在使用的模块。 例如我的apache2正在使用mpm_event_module,所以我需要修改mpm_event.conf

          $ apache2ctl -M
          Loaded Modules:
           core_module (static)
           so_module (static)
           watchdog_module (static)
           http_module (static)
           log_config_module (static)
           logio_module (static)
           version_module (static)
           unixd_module (static)
           access_compat_module (shared)
           alias_module (shared)
           auth_basic_module (shared)
           authn_core_module (shared)
           authn_file_module (shared)
           authz_core_module (shared)
           authz_host_module (shared)
           authz_user_module (shared)
           autoindex_module (shared)
           deflate_module (shared)
           dir_module (shared)
           env_module (shared)
           filter_module (shared)
           mime_module (shared)
           **mpm_event_module (shared)**
           negotiation_module (shared)
           setenvif_module (shared)
           status_module (shared)
           wsgi_module (shared)
          

          【讨论】:

            【解决方案7】:

            您可能需要检查您的网络服务器访问日志。如果日志中充斥着 xml-rpc 帖子(例如“POST /xmlrpc.php HTTP/1.1”200 403),您可能会成为 xml-rpc 攻击的目标。有多种方法可以防止它发生,但 Wordpress 很容易出现这种情况。

            【讨论】:

            • 请问我在我的访问日志中是否发现了 xmlrpc 请求,但不是太多.. 这仍然被认为是攻击吗?
            猜你喜欢
            • 2016-11-16
            • 2015-07-19
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-08-09
            • 2021-11-08
            相关资源
            最近更新 更多