apache在运行的过程中,错误日志中出现如下一段报错信息

[error] server reached MaxClients setting, consider raising the MaxClients setting

检查apache的版本

[root@ logs]# httpd -v
Server version: Apache/2.2.31 (Unix)
Server built:   May 26 2016 01:33:18

查看apache工作模型,可以看以prefork.c

[root@ logs]# apachectl -l
Compiled in modules:
  core.c
  mod_authn_file.c
  mod_authn_dbm.c
  mod_authn_anon.c
  mod_authn_dbd.c
  mod_authn_default.c
  mod_authz_host.c
  mod_authz_groupfile.c
  mod_authz_user.c
  mod_authz_dbm.c
  mod_authz_owner.c
  mod_authz_default.c
  mod_auth_basic.c
  mod_auth_digest.c
  mod_dbd.c
  mod_dumpio.c
  mod_reqtimeout.c
  mod_ext_filter.c
  mod_include.c
  mod_filter.c
  mod_substitute.c
  mod_deflate.c
  mod_log_config.c
  mod_logio.c
  mod_env.c
  mod_expires.c
  mod_headers.c
  mod_ident.c
  mod_setenvif.c
  mod_version.c
  prefork.c
  http_core.c
  mod_mime.c
  mod_dav.c
  mod_status.c
  mod_autoindex.c
  mod_asis.c
  mod_info.c
  mod_cgi.c
  mod_dav_fs.c
  mod_vhost_alias.c
  mod_negotiation.c
  mod_dir.c
  mod_p_w_picpathmap.c
  mod_actions.c
  mod_speling.c
  mod_userdir.c
  mod_alias.c
  mod_rewrite.c
  mod_so.c

apache中MaxClient设置是在apache工作目录下的conf/extra/httpd-mpm.conf

prefork模型的默认设置如下,最在连接数只 150,远远无法满足生产需求

<IfModule mpm_prefork_module>
    StartServers          5
    MinSpareServers       5
    MaxSpareServers      10
    MaxClients          150
    MaxRequestsPerChild   0
</IfModule>

     StartServers:初始启动进程数

     MinSpareServers:最小闲置进程数

     MaxSpareServers:最大闲置进程数

     MaxClients:最大客户端连接数

     MaxRequestsPerChild:每个子进程可处理的请求数,0为不限制

修改为如下:

<IfModule mpm_prefork_module>
    StartServers          10
    MinSpareServers       10
    MaxSpareServers      15
    ServerLimit         2000
    MaxClients          1000
    MaxRequestsPerChild   10000
</IfModule>

如果是worker模型,初始设置为:

<IfModule mpm_worker_module>
    StartServers          2
    MaxClients          150
    MinSpareThreads      25
    MaxSpareThreads      75
    ThreadsPerChild      25
    MaxRequestsPerChild   0
</IfModule>

可修改为如下:

<IfModule mpm_worker_module>
    ThreadLimit        200
    ServerLimit        25
    StartServers        3
    MaxClients         2000
    MinSpareThreads      50
    MaxSpareThreads      200
    ThreadsPerChild      100
    MaxRequestsPerChild     0
</IfModule>

MaxClients必须是ThreadsPerChild的整数倍,ThreadsPerChild*ServerLimit必须大于MaxClients

修改完成后重启apache服务