httpd每xx秒处理cpu达到100%+

我的第一篇文章,不幸的是由于我的专用(Linux Centos 6)服务器上运行一些个人和一个商业网站的问题。

Server version: Apache/2.4.18 (Unix) Server built: Mar 7 2016 20:22:35 Cpanel::Easy::Apache v3.32.10 rev9999 root@server213-171-196-40 [~]# free total used free shared buffers cached Mem: 16212880 15939912 272968 1939060 65928 13730952 -/+ buffers/cache: 2143032 14069848 Swap: 4194296 1477616 2716680 PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND [b] 2900 nobody 20 0 90636 14m 2408 R 99.1 0.1 0:07.42 httpd[/b] 72 root 20 0 0 0 0 R 17.3 0.0 8:08.35 kswapd0 436 root 20 0 0 0 0 S 2.3 0.0 1:54.42 md1_raid1 1 root 20 0 19356 668 452 S 0.0 0.0 0:00.72 init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd 3 root RT 0 0 0 0 S 0.0 0.0 0:00.03 migration/0 4 root 20 0 0 0 0 S 0.0 0.0 0:00.37 ksoftirqd/0 5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 stopper/0 6 root RT 0 0 0 0 S 0.0 0.0 0:00.05 watchdog/0 7 root RT 0 0 0 0 S 0.0 0.0 0:00.04 migration/1 

以上是httpd进程“颠簸”时的一个例子。 它显然将服务器上的负载向上推,当有4个httpd进程执行相同的操作时,网站变得非常没有响应,你可以想象。 通常httpd进程运行在0.1%0.5%的范围内,很好地打勾。

CPU负载的高峰仅在星期一早上的几个小时开始,而且我没有在周日重新构buildApache /更改任何configuration。

我跑了不lessWordPress的网站 – 我仔细检查,看到当时插件的任何更新。

我的Linux技能有点有限,我select了一个最大的httpd进程之一的PID,并试图跟踪它使用strace -p命令

显示这个滚动过去的速度很快..看起来像我的未经训练的眼睛像DOS攻击? 淹没服务器?

 1457649966.654499 read(114, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1024) = 1024 <0.000005> 1457649966.654515 read(114, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1024) = 1024 <0.000005> 1457649966.654531 read(114, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1024) = 1024 <0.000005> 1457649966.654545 read(114, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1024) = 1024 <0.000006> 1457649966.654559 read(114, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1024) = 1024 <0.000005> 1457649966.654573 read(114, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1024) = 1024 <0.000005> 1457649966.654587 read(114, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1024) = 1024 <0.000005> 

我显然可能是错的 – 在10秒左右的秒杀,我的日志文件输出超过200万行! 所以大量的短时间运行“读取”。

另一个失控过程的痕迹:

 root@server213-171-196-40 [/usr/local/iftop-0.17]# strace -c -p 23369 Process 23369 attached ^CProcess 23369 detached % time seconds usecs/call calls errors syscall ------ ----------- ----------- --------- --------- ---------------- 100.00 0.044961 0 2367035 read ------ ----------- ----------- --------- --------- ---------------- 100.00 0.044961 2367035 total 

我实际上并不了解发生了什么 – 我的猜测是某种方式在我的httpd进程中推送了大量的噪音/空数据,并且每隔20秒/每隔几分钟就这样做。

或者这完全是另一回事,我完全不了了之。

我试图把我的一些网站在cloudflare下a)使用他们的CDN加速graphics密集的网站,而且试图增加一层额外的防御。 还没有做我能看到的任何东西。 如果有的话,我甚至不能确定哪个url是网站的原因。

服务器确实有mod_security,有一套标准的规则 – 我closures了一个ip检查,因为读取的地方可能会放缓服务(虽然没有影响)。 服务器有足够的内存(16G),4个CPU(一个8核心英特尔机器)和apache进程显示一个微小的内存使用情况,这一切都是CPU。

PHP版本5.6.18(或.19,需要仔细检查)。

Netstat在“秒杀”的时候不会显示任何单个IP连接超过20个,而且服务器也不会超负荷(我已经closures了我的繁忙网站,每天吸引超过15,000名访问者去除stream量)。

 root@server213-171-196-40 [~]# netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n 1 108.162.221.138 1 108.162.246.252 1 141.101.98.176 1 173.245.50.109 1 199.16.156.125 1 213.128.67.90 1 213.205.194.66 1 222.186.34.163 1 79.70.61.9 1 86.128.207.3 1 94.14.114.56 1 95.151.139.42 1 Address 1 servers) 2 108.162.222.88 2 173.245.56.127 4 86.4.247.37 5 136.243.48.85 6 78.147.41.131 7 90.220.251.88 

服务器工作正常,直到星期一早上 – 在比现在更重的负载下。

从httpd.conf:

 Timeout 300 TraceEnable Off ServerSignature Off ServerTokens ProductOnly FileETag All StartServers 5 <IfModule prefork.c> MinSpareServers 5 MaxSpareServers 10 </IfModule> ServerLimit 256 MaxRequestWorkers 150 MaxConnectionsPerChild 15000 KeepAlive On KeepAliveTimeout 5 MaxKeepAliveRequests 100 

目前使用prefork MPM,但我正在使用事件MPM愉快地运行,我根据WHM / CPANAL easyapache3在“标准”前叉设置重buildApache,看看是否重新build设和更改Apache的configuration将工作,它没有。

如果你们中的任何一个人看到了类似的痕迹输出,或者同样的http抖动,我很乐意听到你的build议。