![apache mpm_prefork 限制为 306 个连接,但服务器限制设置为 1000,AH00159 无法分叉新进程](https://linux22.com/image/225911/apache%20mpm_prefork%20%E9%99%90%E5%88%B6%E4%B8%BA%20306%20%E4%B8%AA%E8%BF%9E%E6%8E%A5%EF%BC%8C%E4%BD%86%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%99%90%E5%88%B6%E8%AE%BE%E7%BD%AE%E4%B8%BA%201000%EF%BC%8CAH00159%20%E6%97%A0%E6%B3%95%E5%88%86%E5%8F%89%E6%96%B0%E8%BF%9B%E7%A8%8B.png)
运行 Virualmin,仍然有大约 1GB 的可用内存,apache 日志充满了:
[mpm_prefork:error] [pid 119747] (11)Resource temporarily unavailable: AH00159: fork: Unable to fork new process
<IfModule mpm_prefork_module>
StartServers 20
MinSpareServers 50
MaxSpareServers 100
MaxRequestWorkers 1000
Serverlimit 2000
MaxConnectionsPerChild 10000
</IfModule>
如果这有帮助:
user@vps:~$ ulimit -a
real-time non-blocking time (microseconds, -R) unlimited
core file size (blocks, -c) 0
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 1541537
max locked memory (kbytes, -l) 524288
max memory size (kbytes, -m) unlimited
open files (-n) 1024
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 62987
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
我也在运行 PHP-FPM,所以这是它的设置,我尝试将 60 更改为 100 但没有区别:
[154754643814302]
user = user
group = user
listen.owner = user
listen.group = user
listen.mode = 0660
listen = /var/php-fpm/154754643814302.sock
pm = dynamic
pm.max_children = 100
pm.start_servers = 8
pm.min_spare_servers = 1
pm.max_spare_servers = 30
php_value[upload_tmp_dir] = /home/user/tmp
php_value[session.save_path] = /home/user/tmp
php_value[error_log] = /home/user/logs/php_log
php_value[log_errors] = On
答案1
我想我已经找到了问题:在 apache 启动文件的 systemd 服务部分添加例如 TasksMax=2000 调整任务限制
root@vps:~# systemctl status apache2
● apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2023-11-04 12:23:42 AEDT; 51s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 2444581 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Main PID: 2444589 (apache2)
Tasks: 614 (limit: 614)
Memory: 261.7M
CGroup: /system.slice/apache2.service
├─2444589 /usr/sbin/apache2 -k start
├─2444590 /usr/sbin/apache2 -k start
├─2444591 /usr/sbin/apache2 -k start