Apache 连接超时,可能是什么问题?

Apache 连接超时,可能是什么问题?

我有一个非常不稳定的 Apache 服务器,每天我都很难连接到 Apache。我不知道为什么,因为对我来说一切似乎都很好。该服务器一直有“大量”的免费资源。该服务器是 Linode 4098,具有 4GB 内存、48GB 硬盘和 2 个 CPU。

我在用着mod_status检查 apache 状态,但是当我尝试访问/服务器状态页面时,始终出现连接超时错误。

我当前的 Apache 配置

<IfModule mpm_prefork_module>
        StartServers            3
        ServerLimit             200
        MinSpareServers         3
        MaxSpareServers         5
        MaxRequestWorkers       175
        MaxConnectionsPerChild  100
        MaxRequestsPerChild     20
</IfModule>

几乎每秒对 /server-status 的 apache 请求都会因 ERR_CONNECTION_TIMED_OUT 而失败。

我不明白为什么会发生这种情况,因为当我检查服务器时,有大量可用资源和空闲连接。

例如 /server-status 报告许多可用的连接:

Parent Server Config. Generation: 1
Parent Server MPM Generation: 0
Server uptime: 1 hour 6 minutes 6 seconds
Server load: 0.09 0.15 0.14
Total accesses: 27206 - Total Traffic: 79.8 MB
CPU Usage: u3.92 s.77 cu0 cs0 - .118% CPU load
6.86 requests/sec - 20.6 kB/second - 3077 B/request
52 requests currently being processed, 1 idle workers

RRRCRRRRRRRRRRRRRRRRRRCRRC.RR.R.RRRRRRRRRCRRRRR_WCCRR.R..RR.....
................................................................
...............................................

并且随着运行时间的增加,我发现 CPU 也可用

load average: 0.05, 0.12, 0.14

并且有可用内存:

        total   used   free  shared  buff/cache   available  
> Mem:   3.9G    1.3G   413M     81M        2.1G        2.3G

谁知道可能出了什么问题?

更新:根据要求,这里是访问日志的片段。(99%是通过调用/api2/counting/count脚本处理程序来跟踪统计数据的请求)

4.139.128.194 - - [23/Jan/2017:11:38:36 +0000] "POST /api2/counter/count?r=1485171514298 HTTP/1.1" 200 441 "-" "WriteDiary4.72"
176.38.149.76 - - [23/Jan/2017:11:38:36 +0000] "POST /api2/counter/count?r=1485171517077 HTTP/1.1" 200 454 "-" "WriteDiary4.72"
67.84.227.131 - - [23/Jan/2017:11:38:36 +0000] "GET /keepalive?471:1485171524866 HTTP/1.1" 200 469 "https://www.writediary.com/notes" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.79 Safari/537.36 Edge/14.14393"
122.178.156.252 - - [23/Jan/2017:11:38:36 +0000] "POST /api2/counter/count?r=1485171515804 HTTP/1.1" 200 441 "-" "WriteDiary4.72"
82.137.13.18 - - [23/Jan/2017:11:38:37 +0000] "POST /api2/counter/count?r=1485171525558 HTTP/1.1" 200 441 "-" "WriteDiary4.72"
103.199.35.221 - - [23/Jan/2017:11:38:37 +0000] "POST /api2/counter/count?r=1485171515470 HTTP/1.1" 200 441 "-" "WriteDiary4.72"
95.218.142.245 - - [23/Jan/2017:11:38:37 +0000] "POST /api2/counter/count?r=1485171516264 HTTP/1.1" 200 441 "-" "WriteDiary4.72"
47.31.143.106 - - [23/Jan/2017:11:38:37 +0000] "POST /api2/counter/count?r=1485171515787 HTTP/1.1" 200 441 "-" "WriteDiary4.72"
94.139.128.194 - - [23/Jan/2017:11:38:37 +0000] "POST /api2/counter/count?r=1485171515619 HTTP/1.1" 200 441 "-" "WriteDiary4.72"
120.188.33.198 - - [23/Jan/2017:11:38:37 +0000] "POST /api2/counter/count?r=1485171515867 HTTP/1.1" 200 454 "-" "WriteDiary4.72"
47.29.174.163 - - [23/Jan/2017:11:38:37 +0000] "POST /api2/counter/count?r=1485171515122 HTTP/1.1" 200 441 "-" "WriteDiary4.72"
85.115.224.151 - - [23/Jan/2017:11:38:37 +0000] "POST /api2/counter/count?r=1485171515453 HTTP/1.1" 200 441 "-" "WriteDiary4.72"
47.11.219.147 - - [23/Jan/2017:11:38:37 +0000] "POST /api2/counter/count?r=1485171516596 HTTP/1.1" 200 441 "-" "WriteDiary4.72"
61.5.53.52 - - [23/Jan/2017:11:38:37 +0000] "POST /api2/counter/count?r=1485171520665 HTTP/1.1" 200 441 "-" "WriteDiary4.72"
116.102.205.20 - - [23/Jan/2017:11:38:37 +0000] "POST /api2/counter/count?r=1485171516590 HTTP/1.1" 200 454 "-" "WriteDiary4.72"
101.60.31.133 - - [23/Jan/2017:11:38:37 +0000] "POST /api2/counter/count?r=1485171516802 HTTP/1.1" 200 441 "-" "WriteDiary4.72"
47.31.147.213 - - [23/Jan/2017:11:38:37 +0000] "POST /api2/counter/count?r=1485171515431 HTTP/1.1" 200 5131 "-" "WriteDiary4.72"
186.78.73.222 - - [23/Jan/2017:11:38:37 +0000] "POST /api2/counter/count?r=1485171669305 HTTP/1.1" 200 454 "-" "WriteDiary4.72"
112.79.186.36 - - [23/Jan/2017:11:38:38 +0000] "POST /api2/counter/count?r=1485171736857 HTTP/1.1" 200 454 "-" "WriteDiary4.72"
94.139.128.194 - - [23/Jan/2017:11:38:38 +0000] "POST /api2/counter/count?r=1485171516605 HTTP/1.1" 200 441 "-" "WriteDiary4.72"
24.236.88.161 - - [23/Jan/2017:11:38:38 +0000] "POST /api2/counter/count?r=1485171516752 HTTP/1.1" 200 441 "-" "WriteDiary4.72"
150.31.100.192 - - [23/Jan/2017:11:38:38 +0000] "POST /api2/counter/count?r=1485171517315 HTTP/1.1" 200 454 "-" "WriteDiary4.72"
12.181.196.67 - - [23/Jan/2017:11:38:38 +0000] "GET /keepalive?50412:1485171517975 HTTP/1.1" 200 501 "https://www.writediary.com/notes" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.99 Safari/537.36"
112.198.75.139 - - [23/Jan/2017:11:38:38 +0000] "POST /api2/counter/count?r=1485171408169 HTTP/1.1" 200 4794 "-" "WriteDiary4.72"
114.125.201.114 - - [23/Jan/2017:11:38:38 +0000] "POST /api2/counter/count?r=1485172944904 HTTP/1.1" 200 441 "-" "WriteDiary4.72"

解决方案:我不得不升级服务器以允许更多工作者。由于每个 Apache 连接需要大约 30MB 或 Ram,因此服务器正在突破 4GB RAM 的极限 = 4000MB / 30MB = 最多 133 个连接...并且当部分内存分配给 mysql 和其他系统功能时,实际上只有 3.5GB 可用,最多接近 100 个连接。

当升级到 8GB RAM 时,最大限制接近 250 个连接,这使得一切都运行顺畅。事实上,在重新调整 RAM 后,服务器状态报告 Apache 在高峰时段同时处理了 200 个请求,持续了数小时。这可以解释为什么服务器在高峰时段遇到困难,限制接近 100。

答案1

你能发布 apache 访问日志吗

如果你正在使用 ubuntu,你可以使用这个命令来查找日志

cat /var/log/apache2/access.log

但它根据你的平台而有所不同

相关内容