![Apache 服务器上的最大连接数限制配置 - CentOS 6.4](https://linux22.com/image/615960/Apache%20%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84%E6%9C%80%E5%A4%A7%E8%BF%9E%E6%8E%A5%E6%95%B0%E9%99%90%E5%88%B6%E9%85%8D%E7%BD%AE%20-%20CentOS%206.4.png)
我们在 CentOs 6.4 上运行着一个 Apache 和一个 CherryPy (Python) 服务器。昨天 Apache 服务器突然宕机,而使用端口 8080 的 CherryPy 却运行正常。我们正在尝试解决问题,但没有成功。似乎最大同时连接数出了问题,但我们不知道如何修复,甚至不知道真正的问题所在。错误日志文件中有类似以下内容:
[Sun Aug 04 04:47:16 2013] [notice] mod_python: Creating 4 session mutexes based on 10 max processes and 0 max threads.
[Mon Aug 05 21:57:31 2013] [notice] mod_python: Creating 4 session mutexes based on 10 max processes and 0 max threads.
[Mon Aug 05 21:58:46 2013] [error] server reached MaxClients setting, consider raising the MaxClients setting
有人知道如何修复此问题吗?
PS:我们对服务器完全是新手。
答案1
您应该检查 /etc/httpd/conf/httpd.conf 中的值
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
您应该更改正在使用的处理模型(可能是工作者)
您可以尝试从 top/atop/htop 的输出中确定有多少个客户端可以为您的服务器提供服务
# top
top - 15:06:24 up 41 days, 16:18, 2 users, load average: 3.58, 2.59, 2.34
Tasks: 204 total, 1 running, 203 sleeping, 0 stopped, 0 zombie
Cpu(s): 14.6%us, 0.5%sy, 0.0%ni, 84.3%id, 0.3%wa, 0.0%hi, 0.3%si, 0.0%st
Mem: 24676512k total, 14828220k used, 9848292k free, 343688k buffers
Swap: 2102456k total, 188k used, 2102268k free, 10690524k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
19965 apache 16 0 413m 113m 3980 S 5.7 0.5 3:11.01 httpd
20954 apache 16 0 383m 83m 3952 S 5.7 0.3 1:16.31 httpd
21274 apache 16 0 382m 81m 3988 S 5.7 0.3 0:29.20 httpd
21376 apache 16 0 371m 67m 3728 S 5.7 0.3 0:03.58 httpd
20943 apache 16 0 384m 83m 3948 S 5.3 0.3 1:18.98 httpd
20969 apache 16 0 384m 83m 3928 S 5.3 0.3 1:18.67 httpd
21264 apache 16 0 382m 80m 3796 S 5.3 0.3 0:27.93 httpd
21364 apache 16 0 379m 75m 3848 S 5.3 0.3 0:04.28 httpd
21370 apache 16 0 378m 75m 3712 S 5.3 0.3 0:04.31 httpd
21371 apache 16 0 378m 74m 3772 S 5.3 0.3 0:04.51 httpd
21374 apache 16 0 379m 74m 3804 S 5.3 0.3 0:03.50 httpd
21377 apache 16 0 379m 76m 3896 S 5.3 0.3 0:04.54 httpd
21043 apache 16 0 383m 82m 3976 S 5.0 0.3 1:17.40 httpd
21262 apache 16 0 382m 81m 3900 S 5.0 0.3 0:28.30 httpd
从输出中可以看出 - 一个 Apache 进程所需的平均 RAM 量(RES 列)约为 80 mb