当我启动 apache 并继续杀死我的机器时,如何防止大量 apache 进程产生? [英] How can I prevent tons of apache processes spawning when I start apache and proceeding to kill my machine?

查看:31
本文介绍了当我启动 apache 并继续杀死我的机器时,如何防止大量 apache 进程产生?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一台 debian 机器上有一个流量很大的应用程序,apache 开始表现得很奇怪.

每次我启动 apache 时,都会产生大量的 apache 进程,应用程序根本无法加载,很快整个机器就死机,必须重新启动才能重新启动.

这是我在启动 apache 后立即得到的 top:

<前>top - 20:14:44 up 1:16, 2 个用户,平均负载:0.48, 0.10, 0.03任务:总共 330 个,运行 5 个,睡眠 325 个,停止 0 个,僵尸 0 个Cpu(s): 12.0%us, 21.4%sy, 0.0%ni, 65.7%id, 0.2%wa, 0.1% 0.7%si, 0.0%st内存:总共 8179920k,已使用 404984k,空闲 7774936k,60716k 缓冲区交换:总共 2097136k,已使用 0k,可用 2097136k,缓存 43424k10251 www-data 15 0 467m 8100 4016 S 6 0.1 0:00.04 apache210262 www-data 15 0 467m 8092 4012 S 6 0.1 0:00.05 apache210360 www-data 15 0 468m 8296 4016 S 6 0.1 0:00.05 apache210428 www-data 15 0 468m 8272 3992 S 6 0.1 0:00.05 apache210241 www-data 15 0 467m 8256 4012 S 4 0.1 0:00.03 apache210259 www-data 15 0 467m 8092 4012 S 4 0.1 0:00.04 apache210274 www-data 15 0 467m 8056 4012 S 4 0.1 0:00.03 apache210291 www-data 15 0 468m 8292 4012 S 4 0.1 0:00.03 apache210293 www-data 15 0 468m 8292 4012 S 4 0.1 0:00.03 apache210308 www-data 15 0 468m 8296 4016 S 4 0.1 0:00.02 apache210317 www-data 15 0 468m 8292 4012 S 4 0.1 0:00.02 apache210320 www-data 15 0 468m 8292 4012 S 4 0.1 0:00.04 apache210325 www-data 15 0 468m 8292 4012 S 4 0.1 0:00.04 apache2

等等......更多的apache2进程.

不到一分钟后,您可以在下方看到负载从 0.48 变为 2.17.如果此时我不停止 apache,负载会在几分钟或更短的时间内继续上升,直到机器死机.

<前>top - 20:15:34 up 1:17, 2 个用户,平均负载:2.17, 0.62, 0.21任务:总共1850个,5个运行,1845个睡眠,0个停止,0个僵尸Cpu(s): 0.3%us, 2.1%sy, 0.0%ni, 96.4%id, 0.0%wa, 0.1% 1.0%si, 0.0%st内存:总共 8179920k,已使用 1938524k,6241396k 空闲,60860k 缓冲区交换:总共 2097136k,已使用 0k,可用 2097136k,缓存 44196k

我们有一个防火墙,可以将我们知道可以访问我们网站的地址列入白名单.

任何关于问题可能是什么的想法都非常受欢迎.

谢谢!

解决方案

您可能犯了将 Apache 配置为使用远远超过您所有 ram 的错误.这是一个容易犯的错误.

我假设您使用的是 Prefork Apache 和进程内应用程序服务器(例如 PHP 或 mod_perl).在此模型中,您最终将使用最多(MaxClients * 每个进程的应用程序的最大内存使用量)内存.如果您几乎没有那么多,是时候减少一个、另一个或两者都减少了.

在一般情况下,这意味着将 MaxClients 减少到您的服务器有足够内存来应对的程度.

如果您使用 Prefork 模型(大多数应用服务器要么不支持,要么不鼓励),通常用于 MaxClients 的默认值(典型值为 150)不适合在普通机器上运行进程内重量级应用服务器,线程模型的使用).

但是,减少 MaxClients 最终会导致应用程序变得不可用,特别是如果您启用了 keepalive 并且 keepalive 超时时间过长.只是保持连接处于活动状态的进程(服务器状态中的状态 K)仍然使用大量 RAM,这可能是一个问题 - 尽量减少保持活动超时,或完全关闭它.

您需要密切关注服务器状态(由 mod_status 提供).

当然,只有在您了解后果的情况下才应该进行任何这些更改.三思而后行,更改一次配置.如果您有能力在类似规格的非生产机器上使用模拟负载测试更改,请这样做.

I have a highly trafficked application on one debian machine and apache has started acting strange.

Every time I start apache, tons of apache processes are spawned, the app doesn't load at all, and very quickly the whole machine freezes and must be powercycled to reboot.

Here is what I get for top immediately after starting apache:

top -   20:14:44    up         1:16,      2 users,    load average: 0.48, 0.10, 0.03
Tasks:  330 total,  5 running, 325 sleeping,   0 stopped,   0 zombie
Cpu(s): 12.0%us,    21.4%sy,   0.0%ni,        65.7%id,   0.2%wa,  0.1%hi,  0.7%si,  0.0%st
Mem:    8179920k    total,     404984k used,  7774936k free,    60716k buffers
Swap:   2097136k    total,     0k used,       2097136k free,    43424k cached


10251 www-data  15   0  467m 8100 4016 S    6  0.1   0:00.04 apache2
10262 www-data  15   0  467m 8092 4012 S    6  0.1   0:00.05 apache2
10360 www-data  15   0  468m 8296 4016 S    6  0.1   0:00.05 apache2
10428 www-data  15   0  468m 8272 3992 S    6  0.1   0:00.05 apache2
10241 www-data  15   0  467m 8256 4012 S    4  0.1   0:00.03 apache2
10259 www-data  15   0  467m 8092 4012 S    4  0.1   0:00.04 apache2
10274 www-data  15   0  467m 8056 4012 S    4  0.1   0:00.03 apache2
10291 www-data  15   0  468m 8292 4012 S    4  0.1   0:00.03 apache2
10293 www-data  15   0  468m 8292 4012 S    4  0.1   0:00.03 apache2
10308 www-data  15   0  468m 8296 4016 S    4  0.1   0:00.02 apache2
10317 www-data  15   0  468m 8292 4012 S    4  0.1   0:00.02 apache2
10320 www-data  15   0  468m 8292 4012 S    4  0.1   0:00.04 apache2
10325 www-data  15   0  468m 8292 4012 S    4  0.1   0:00.04 apache2

And so forth.. with more apache2 processes.

Less than a minute later, you can see below that the load has gone from 0.48 to 2.17. If I do not stop apache at this point, the load continues to rise over a few minutes or less until the machine dies.

top -    20:15:34 up 1:17,       2 users,  load average: 2.17, 0.62, 0.21
Tasks:   1850 total,  5 running, 1845 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.3%us,      2.1%sy,    0.0%ni, 96.4%id,  0.0%wa,  0.1%hi,  1.0%si,  0.0%st
Mem:     8179920k     total,     1938524k used,  6241396k free,    60860k buffers
Swap:    2097136k     total,     0k used,  2097136k free,    44196k cached

We have a firewall where we whitelist the addresses we know are allowed to hit our site.

Any ideas about what the problem might be are very welcome.

Thanks!

解决方案

You have probably made the error of configuring Apache to use far more than all of your ram. This is an easy mistake to make.

I am assuming you are using a Prefork Apache, and an in-process application server (such as PHP or mod_perl). In this model, you will end up with a maximum of (MaxClients * max memory usage of your application per process) memory used. If you don't have nearly that much, it's time to decrease one, the other or both.

In the general case, this means decreasing MaxClients to the point where your server has enough ram to cope.

The default values typically used for MaxClients (150 is typical) are not suitable for running an in-process heavyweight application server on a modest machine if you are using the Prefork model (Most application servers either don't support, or discourage, the use of threaded models).

However, decreasing MaxClients will eventually cause the application to become unavailable, particularly if you have keepalives on and the keepalive timeout too long. Processes which are just keeping a connection alive (state K in server-status) still use a lot of RAM, and that may be a problem - try to minimise keepalive timeout, or turn it off altogether.

You need to keep an eye on server-status (as provided by mod_status).

Of course you should only make ANY of these changes if you understand the consequences. Think twice, change the config once. If you have ANY ability to test the changes with simulated load on a similar spec non-production machine, do so.

这篇关于当我启动 apache 并继续杀死我的机器时,如何防止大量 apache 进程产生?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆