Apache-2.2

阿帕奇突然變慢

  • December 30, 2015

我的網路伺服器上的 Apache 突然變得很慢。我在 digitalocean 有一個 8 GB Ram、4 CPU 伺服器,安裝了 LAMP。我能做些什麼來解決這個問題?

這是top輸出:

top - 10:37:15 up 93 days, 20:20,  1 user,  load average: 0.22, 0.22, 0.28
Tasks: 471 total,   3 running, 468 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.4 us,  0.6 sy,  0.0 ni, 97.4 id,  0.1 wa,  0.0 hi,  0.5 si,  0.0 st
KiB Mem:   8176832 total,  6816036 used,  1360796 free,   184160 buffers
KiB Swap:        0 total,        0 used,        0 free.  5057196 cached Mem

 PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND                                                                                                
6463 mysql     20   0 2420696  88740   3808 S   0.7  1.1 348:23.30 mysqld                                                                                                 
16207 www-data  20   0  385076  11560   4376 S   0.7  0.1   0:00.18 apache2                                                                                                
   7 root      20   0       0      0      0 S   0.3  0.0 818:55.76 rcu_sched                                                                                              
   8 root      20   0       0      0      0 S   0.3  0.0 464:04.83 rcuos/0                                                                                                
1053 root      20   0  100708   2624    708 S   0.3  0.0   9:19.16 sendmail-mta                                                                                           
16168 www-data  20   0  384812  11420   4424 S   0.3  0.1   0:00.17 apache2                                                                                                
16194 www-data  20   0  385076  11620   4384 S   0.3  0.1   0:00.21 apache2                                                                                                
16202 www-data  20   0  384820  11432   4428 S   0.3  0.1   0:00.22 apache2                                                                                                
16276 www-data  20   0  385076  11588   4440 S   0.3  0.1   0:00.15 apache2                                                                                                
16287 www-data  20   0  386696  13136   4436 S   0.3  0.2   0:00.18 apache2                                                                                                
16309 www-data  20   0  385068  11592   4404 S   0.3  0.1   0:00.17 apache2                                                                                                
16333 www-data  20   0  384812  11392   4396 S   0.3  0.1   0:00.14 apache2                                                                                                
16340 www-data  20   0  386348  12608   4416 R   0.3  0.2   0:00.11 apache2                                                                                                
16353 www-data  20   0  386696  13036   4404 S   0.3  0.2   0:00.22 apache2                                                                                                
16385 www-data  20   0  385076  11640   4404 S   0.3  0.1   0:00.21 apache2                                                                                                
16412 www-data  20   0  386696  13116   4436 S   0.3  0.2   0:00.40 apache2                                                                                                
16446 www-data  20   0  386672  13080   4404 S   0.3  0.2   0:00.14 apache2                                                                                                
16454 www-data  20   0  386696  13100   4424 S   0.3  0.2   0:00.17 apache2                                                                                                
16479 www-data  20   0  386412  12852   4396 S   0.3  0.2   0:00.14 apache2                                                                                                
16540 root      20   0   25212   1988   1176 R   0.3  0.0   0:00.33 top                                                                                                    
   1 root      20   0   33500   2688   1328 S   0.0  0.0   0:44.63 init                                                                                                   
   2 root      20   0       0      0      0 S   0.0  0.0   0:00.15 kthreadd                                                                                               
   3 root      20   0       0      0      0 S   0.0  0.0 202:28.30 ksoftirqd/0                                                                                            
   5 root       0 -20       0      0      0 S   0.0  0.0   0:00.00 kworker/0:0H                                                                                           
   6 root      20   0       0      0      0 S   0.0  0.0 157:44.10 kworker/u8:0                                                                                           
   9 root      20   0       0      0      0 R   0.0  0.0 164:29.67 rcuos/1                                                                                                
  10 root      20   0       0      0      0 S   0.0  0.0 152:37.93 rcuos/2                                                                                                
  11 root      20   0       0      0      0 S   0.0  0.0  68:24.97 rcuos/3                                                                                                
  12 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcu_bh                                                                                                 
  13 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/0                                                                                                
  14 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/1                                                                                                
  15 root      20   0       0      0      0 S   0.0  0.0   0:00.00 rcuob/2       

這是apache錯誤日誌:

[Tue Dec 29 10:32:11.628945 2015] [:error] [pid 16404] [client 61.178.71.8:37626] PHP Notice:  Undefined variable: config_location in /var/www/html/a/lib/common.php on line 32, referer: http://hi-techno.xyz/clicknety.html
[Tue Dec 29 10:32:11.727455 2015] [:error] [pid 16447] [client 87.168.254.145:63259] PHP Notice:  Undefined variable: countryname in /var/www/html/c/arth.php(33) : eval()'d code on line 1, referer: http://eywow.com/c/arth.php?slug=balls
[Tue Dec 29 10:32:11.727566 2015] [:error] [pid 16447] [client 87.168.254.145:63259] PHP Notice:  Undefined variable: city in /var/www/html/c/arth.php(33) : eval()'d code on line 1, referer: http://eywow.com/c/arth.php?slug=balls
[Tue Dec 29 10:32:11.728356 2015] [:error] [pid 16447] [client 87.168.254.145:63259] PHP Notice:  Undefined offset: -1 in /var/www/html/c/arth.php on line 323, referer: http://eywow.com/c/arth.php?slug=balls
[Tue Dec 29 10:32:12.077442 2015] [:error] [pid 16326] [client 138.0.68.53:2349] PHP Notice:  A session had already been started - ignoring session_start() in /var/www/html/a/lib/common.php on line 3, referer: http://hi-techno.xyz/clicknety.html
[Tue Dec 29 10:32:12.077514 2015] [:error] [pid 16326] [client 138.0.68.53:2349] PHP Notice:  Undefined index: domain in /var/www/html/a/lib/common.php on line 14, referer: http://hi-techno.xyz/clicknety.html
[Tue Dec 29 10:32:12.077950 2015] [:error] [pid 16326] [client 138.0.68.53:2349] PHP Notice:  Undefined variable: config_location in /var/www/html/a/lib/common.php on line 32, referer: http://hi-techno.xyz/clicknety.html
[Tue Dec 29 10:32:12.213301 2015] [:error] [pid 16220] [client 187.111.210.17:4461] PHP Notice:  A session had already been started - ignoring session_start() in /var/www/html/a/lib/common.php on line 3, referer: http://hi-techno.xyz/clicknety.html
[Tue Dec 29 10:32:12.213353 2015] [:error] [pid 16220] [client 187.111.210.17:4461] PHP Notice:  Undefined index: domain in /var/www/html/a/lib/common.php on line 14, referer: http://hi-techno.xyz/clicknety.html
[Tue Dec 29 10:32:12.213812 2015] [:error] [pid 16220] [client 187.111.210.17:4461] PHP Notice:  Undefined variable: config_location in /var/www/html/a/lib/common.php on line 32, referer: http://hi-techno.xyz/clicknety.html
[Tue Dec 29 10:32:12.902652 2015] [:error] [pid 16256] [client 162.156.92.161:57060] PHP Notice:  Undefined variable: countryname in /var/www/html/c/arth.php(33) : eval()'d code on line 1, referer: http://eywow.com/c/arth.php?slug=ufo
[Tue Dec 29 10:32:12.902836 2015] [:error] [pid 16256] [client 162.156.92.161:57060] PHP Notice:  Undefined variable: city in /var/www/html/c/arth.php(33) : eval()'d code on line 1, referer: http://eywow.com/c/arth.php?slug=ufo
[Tue Dec 29 10:32:13.002648 2015] [:error] [pid 16427] [client 41.190.198.114:50583] PHP Notice:  A session had already been started - ignoring session_start() in /var/www/html/a/lib/common.php on line 3, referer: http://hi-techno.xyz/clicknety.html
[Tue Dec 29 10:32:13.002704 2015] [:error] [pid 16427] [client 41.190.198.114:50583] PHP Notice:  Undefined index: domain in /var/www/html/a/lib/common.php on line 14, referer: http://hi-techno.xyz/clicknety.html
[Tue Dec 29 10:32:13.003456 2015] [:error] [pid 16427] [client 41.190.198.114:50583] PHP Notice:  Undefined variable: config_location in /var/www/html/a/lib/common.php on line 32, referer: http://hi-techno.xyz/clicknety.html
[Tue Dec 29 10:32:13.136681 2015] [:error] [pid 16256] [client 119.93.37.113:38315] PHP Notice:  A session had already been started - ignoring session_start() in /var/www/html/a/lib/common.php on line 3, referer: http://hi-techno.xyz/clicknety.html
[Tue Dec 29 10:32:13.136740 2015] [:error] [pid 16256] [client 119.93.37.113:38315] PHP Notice:  Undefined index: domain in /var/www/html/a/lib/common.php on line 14, referer: http://hi-techno.xyz/clicknety.html
[Tue Dec 29 10:32:13.137251 2015] [:error] [pid 16256] [client 119.93.37.113:38315] PHP Notice:  Undefined variable: config_location in /var/www/html/a/lib/common.php on line 32, referer: http://hi-techno.xyz/clicknety.html

我的站點範例頁面很慢,這是apache的伺服器狀態頁面我的猜測是iptables正在減慢它,因為硬體方面沒有原因,有足夠的可用資源。我有 8 GB 記憶體和 4 個 CPU。

63.2 requests/sec - 1.4 MB/second - 23.4 kB/request
375 requests currently being processed, 0 idle workers

您已經用盡了可用的 Apache 程序。你需要增加maxclients. 檢查您的 Apache 錯誤日誌以獲取有關該問題的更多詳細資訊。

你可以發布以下結果嗎?

top -u

這應該可以讓您大致了解伺服器上所有程序的 CPU 使用率排名。你可能還想把所有的東西都找出來,只剩下 Apache。

top -u | grep Apache

可能還有其他一些資​​源佔用或許多記憶體洩漏。

引用自:https://serverfault.com/questions/745785