httpd进程占用大量内存解决办法

   

突然发现wearm所在的centos中,httpd进程占用大量的内存,杀掉进程过不了多久就又吃回来了,看来是apache在搞事情。

通过top按照内存使用量排序shitf+m可以看到,同时有四个httpd进程,每个占用20%进程执行命令可以看到,其实有6个:

# ps -aux |grep httpd |wc -l
6

设置Apache MPM Prefork模块:

#vim /usr/local/apache/conf/extra/httpd-mpm.conf
...
# 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
# MaxRequestWorkers: maximum number of server processes allowed to start
# MaxConnectionsPerChild: maximum number of connections a server process serves
#                         before terminating
<IfModule mpm_prefork_module>
    StartServers                              5
    MinSpareServers                      5
    MaxSpareServers                     10
    ServerLimit                               400
    MaxRequestWorkers               250
    MaxConnectionsPerChild        40  
</IfModule>
...

StartServers:服务器启动时建立的子进程数量
MinSpareServers:空闲子进程的最小值
MaxSpareServers: 空闲子进程的最大值
ServerLimit:手动添加ServerLimit,修改apache最大并发连接数的参数设置,一定要将它放在MaxRequestWorkers的前面,并且它的值也一定要大于MaxRequestWorkers的值
MaxRequestWorkers: 最大数量的服务器进程允许
MaxConnectionsPerChild:一个独立的子进程将能处理的请求数量,原先的值是0,代表无限,这应该就是吃内存的原因,我将其改为40

顺便还修改了一个连接多少时间后断开,一般来说30-60都可:

#vim /usr/local/apache/conf/extra/httpd-default.conf
...
Timeout 30
...

发表评论