![Apache 突然变慢](https://linux22.com/image/673886/Apache%20%E7%AA%81%E7%84%B6%E5%8F%98%E6%85%A2.png)
我的 Web 服务器上的 Apache 突然变得非常慢。我在 digitalocean 上有一个 8 GB 内存、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
我的网站示例页面很慢,这是阿帕奇我猜是 iptables 拖慢了速度,因为硬件方面没有原因,有足够的可用资源。我有 8 GB 内存和 4 个 CPU。
答案1
63.2 requests/sec - 1.4 MB/second - 23.4 kB/request
375 requests currently being processed, 0 idle workers
您已用尽了可用的 Apache 进程数。您需要增加maxclients
。检查您的 Apache 错误日志以获取有关该问题的更多详细信息。
答案2
您能发布以下结果吗?
top -u
这应该可以让你概览服务器上所有进程的 CPU 使用率。你可能还想 grep 出所有内容,只留下 Apache。
top -u | grep Apache
可能还存在其他占用大量资源的情况,或者出现大量内存泄漏。