apache mpm_prefork 限制为 306 个连接,但服务器限制设置为 1000,AH00159 无法分叉新进程

apache mpm_prefork 限制为 306 个连接,但服务器限制设置为 1000,AH00159 无法分叉新进程

运行 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

在此输入图像描述

相关内容