Apache2:服务器已达到 MaxClients 设置,请考虑提高 MaxClients 设置

Apache2:服务器已达到 MaxClients 设置,请考虑提高 MaxClients 设置

我在专用的 Ubuntu 12.04 LTS(Apache/2.2.22)、PHP 5.3 和 APC 上遇到了问题。

每隔几个小时我就会看到这样的情况:

[Fri Aug 17 15:36:51 2012] [error] server reached MaxClients setting, consider raising the MaxClients setting

这会导致服务器丢弃/拒绝所有连接。

当我重新启动 apache 时:

[Fri Aug 17 15:38:14 2012] [warn] child process 8946 still did not exit, sending a SIGTERM
[Fri Aug 17 15:38:14 2012] [warn] child process 7496 still did not exit, sending a SIGTERM
[Fri Aug 17 15:38:16 2012] [warn] child process 8946 still did not exit, sending a SIGTERM
[Fri Aug 17 15:38:16 2012] [warn] child process 7496 still did not exit, sending a SIGTERM
[Fri Aug 17 15:38:18 2012] [warn] child process 8946 still did not exit, sending a SIGTERM
[Fri Aug 17 15:38:18 2012] [warn] child process 7496 still did not exit, sending a SIGTERM
[Fri Aug 17 15:38:20 2012] [error] child process 8946 still did not exit, sending a SIGKILL
[Fri Aug 17 15:38:20 2012] [error] child process 7496 still did not exit, sending a SIGKILL
[Fri Aug 17 15:38:21 2012] [notice] caught SIGTERM, shutting down
[Fri Aug 17 15:38:21 2012] [warn] Init: Session Cache is not configured [hint: SSLSessionCache]
[Fri Aug 17 15:38:22 2012] [notice] Apache/2.2.22 (Ubuntu) PHP/5.3.10-1ubuntu3.2 with Suhosin-Patch mod_ssl/2.2.22 OpenSSL/1.0.1 configured -- resuming normal operations

自从发生这种情况后,我提高了 apache 的配置(它是一台 6 核机器,具有 16Gb 的 RAM,所以我认为我会大大提高它的配置)。

<IfModule mpm_prefork_module>
    StartServers          8
    MinSpareServers       5
    MaxSpareServers      10
    ServerLimit         500
    MaxClients          500
    MaxRequestsPerChild 1000
</IfModule>

该服务器只提供 PHP(没有静态文件),页面加载时间绝不会超过几秒钟……

我一直在观察 mod_status(刚刚激活它),但我没有看到任何奇怪的东西......

Server uptime: 20 minutes 46 seconds
Total accesses: 9206 - Total Traffic: 641 kB
CPU Usage: u147.52 s17.21 cu0 cs0 - 13.2% CPU load
7.39 requests/sec - 526 B/second - 71 B/request
2 requests currently being processed, 8 idle workers

___...W__..._W.....__...........................................
................................................................
................................................................
................................................................
................................................................
................................................................
................................................................
....................................................

我甚至尝试用 apache ab 运行一些压力测试,看看是否可以重现它......没有运气。:(

编辑:我刚刚有一个重大发现:

DEBUG: WARNING - require(): GC cache entry '/var/www/common/revisions/1061/library/core/bootstrap.php' (dev=64513 ino=1577080) was on gc-list for 3601 seconds /var/www/common/revisions/1061/library/core/cache/disk/dao.php (16)

这个错误是导致问题的原因,我相信它与 APC 有关。

答案1

问题似乎是 APC 内存不足或某些原因(用于将文件存储在操作码中),导致 Apache 崩溃。当我将内存限制提高到 256M ( apc.shm_size=256M) 时,问题就消失了。

答案2

将 Apache 置于反向代理之后(如 nginx,...)在从源代码编译 Apache 之前,您需要“硬编码”到 Apache 源代码中,以将限制从 256 增加到 2048 左右

相关内容