后遇到了一些问题我在全新、干净的 Fedora 24 平台上重建了我的服务器。这是一台相当繁忙的服务器,现在当它启动时,我在 apache 的 error_log 中收到大量此类消息:
[Thu Dec 08 19:30:26.954314 2016] [mpm_prefork:error] [pid 379] (11)Resource temporarily unavailable: AH00159: fork: Unable to fork new process
[Thu Dec 08 19:30:36.957269 2016] [mpm_prefork:error] [pid 379] (11)Resource temporarily unavailable: AH00159: fork: Unable to fork new process
[Thu Dec 08 19:30:46.963876 2016] [mpm_prefork:error] [pid 379] (11)Resource temporarily unavailable: AH00159: fork: Unable to fork new process
[Thu Dec 08 19:30:56.967167 2016] [mpm_prefork:error] [pid 379] (11)Resource temporarily unavailable: AH00159: fork: Unable to fork new process
[Thu Dec 08 19:31:06.974127 2016] [mpm_prefork:error] [pid 379] (11)Resource temporarily unavailable: AH00159: fork: Unable to fork new process
我尝试过调整和调优,但似乎没有办法解决这个问题。我使用的机器在 Fedora 23 下运行良好,所以我知道它可以处理负载。
这是我的 Apache 服务器状态:
Apache Server Status for example.com (via x.x.x.x)
Server Version: Apache/2.4.23 (Fedora) OpenSSL/1.0.2j-fips PHP/5.6.28
Server MPM: prefork
Server Built: Jul 18 2016 15:38:14
Current Time: Thursday, 08-Dec-2016 19:38:57 UTC
Restart Time: Thursday, 08-Dec-2016 19:29:02 UTC
Parent Server Config. Generation: 1
Parent Server MPM Generation: 0
Server uptime: 9 minutes 55 seconds
Server load: 2.86 2.38 1.48
Total accesses: 13045 - Total Traffic: 112.5 MB
CPU Usage: u485.32 s25.57 cu.05 cs.03 - 85.9% CPU load
21.9 requests/sec - 193.6 kB/second - 8.8 kB/request
165 requests currently being processed, 0 idle workers
KKKKWKKKKKKKKKKKKKKWKKKKKWKKKKKWWKKKKKKKKKKWKKKWKKKWKKKKKKKWWKKW
WKKKKKKKKKKWKKKKKKWKKKWKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKWKKK
KKKKKKKWWKKKKWKKKKKKKKWKKKKKKKKKKKWKW...........................
................................................................
................................................................
................................................................
...然后就这样继续下去。有很多空位,但是某物服务器上的 ulimits 阻止了新进程启动和处理负载。但是我的 ulimits 设置得很高 - 可能太高了!
# ulimit -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 1546671
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 102400
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 10240
cpu time (seconds, -t) unlimited
max user processes (-u) 1546671
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
为了完整起见,以下是我的 limits.conf 设置:
* soft core unlimited
* soft nofile 102400
* hard nofile 152400
* soft sigpending 1546671
* hard sigpending 2046671
* soft stack 10240
* hard stack 14240
* soft nproc 1546671
* hard nproc 2046671
这是我的 apache mpm-worker 设置 - 同样,可能太高,但如果将所有这些设置得较低(或设置为默认值),问题也会存在,而且通常会更快。
ServerLimit 8192
StartServers 40
MinSpareServers 25
MaxSpareServers 100
MaxClients 8192
MaxRequestsPerChild 10000
显然仍有一些东西限制新流程的启动,但我不知道下一步该怎么做。
一如既往,我们欢迎任何建议!
谢谢,迈克
答案1
暂定的解决方案是将以下内容添加到httpd.conf:
EnableMMAP Off
这会禁用内存映射,这似乎对服务器产生了非常不利的影响。
有关详细信息,请参阅:http://httpd.apache.org/docs/2.4/mod/core.html#enablemmap
如果这不是解决方案,我会在这里向大家更新。
答案2
我们也遇到过类似的问题。这似乎systemd
是造成我们限制的原因。
https://www.freedesktop.org/software/systemd/man/systemd.resource-control.html#TasksMax=N