最近公司有个客户报了一个问题,就是运行一段时间后在apache的日志/var/log/httpd/error_log文件中有一条错误信息
[Fri Jul 29 15:45:37 2016] [error] server reached MaxClients setting, consider raising the MaxClients setting
检查了一下,这是由于并发链接数太多导致的,后来查了一下apache的文档,发现可以通过修改apache的配置文件
/etc/httpd/conf/httpd.conf中的MaxClients参数来调整。
在调整之前首先要检查一下apache运行在哪一种模式下是prefork还是worker,使用“/usr/sbin/httpd -l”命令来检查,当检查出是哪一种模式之后,就可以找到/etc/httpd/conf/httpd.conf中对应的配置部分来修改。
# httpd -l
Compiled in modules:
core.c
prefork.c
http_core.c
mod_so.c
修改一下参数,将其中
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
</IfModule>
修改为
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 20
ServerLimit 1024
MaxClients 1024
MaxRequestsPerChild 50
</IfModule>
然后重新启动apache “service httpd restart”。
关于参数的意义,在apache的配置中有详细说明,如下:
# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# ServerLimit: maximum value for MaxClients for the lifetime of the server
# MaxClients: maximum number of server processes allowed to start
# MaxRequestsPerChild: maximum number of requests a server process serves
# worker MPM
# StartServers: initial number of server processes to start
# MaxClients: maximum number of simultaneous client connections
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves