博客园  :: 首页  :: 管理

关于apache-httpd-启用prefork及基本配置说明

Posted on 2023-10-18 14:04  520_1351  阅读(173)  评论(0编辑  收藏  举报

操作系统版本:Red Hat Enterprise Linux release 8.7 (Ootpa)

Apache的版本:httpd-2.4.37-56.module+el8.8.0+19808+379766d6.7.x86_64

 

1、编辑配置文件 /etc/httpd/conf.modules.d/00-mpm.conf ,保证3种MPM,只启用prefork

LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so
#LoadModule mpm_event_module modules/mod_mpm_event.so

对于httpd-2.4版本,默认是使用的event

2、基本配置 /etc/httpd/conf/httpd.conf,添加如下配置,不添加也会有默认值

<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 256
MaxConnectionsPerChild 0
</IfModule>

以上的配置就是配置的默认值的,其中部分选项说明如下:

MinSpareServers
If you are trying to set the value equal to or lower than MinSpareServers, Apache HTTP Server will automatically adjust it to MinSpareServers + 1

 

MaxRequestWorkers
For non-threaded servers (i.e., prefork), MaxRequestWorkers translates into the maximum number of child processes that will be launched to serve requests. The default value is 256; to increase it, you must also raise ServerLimit.


MaxConnectionsPerChild

The MaxConnectionsPerChild directive sets the limit on the number of connections that an individual child server process will handle. After MaxConnectionsPerChild connections, the child process will die. If MaxConnectionsPerChild is 0, then the process will never expire.

Setting MaxConnectionsPerChild to a non-zero value limits the amount of memory that a process can consume by (accidental) memory leakage.

 

遗留的问题:在官网可以看到有说明 prefork 

prefork 这个多处理模块(MPM)实现了一个无线程、prefork的web服务器。每个服务器进程可以回答传入的请求,父进程管理服务器池的大小。

它适用于需要避免线程化以与非线程安全库兼容的站点。它也是隔离每个请求的最佳MPM,这样单个请求的问题就不会影响任何其他请求。

但笔者,通过 ps命令, 发现其子进程,是有多个线程的

[root@qq-5201351 ~]# httpd -V | grep MPM
Server MPM:     prefork
[root@qq-5201351 ~]# ps -eLf|grep httpd
root       17746       1   17746  0    1 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17747  0   22 11:14 ?        00:00:07 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17749  0   22 11:14 ?        00:00:02 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17750  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17751  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17752  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17753  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17754  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17755  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17756  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17757  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17758  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17759  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17760  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17761  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17762  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17764  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17765  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17766  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17767  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17768  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17769  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17747   17746   17770  0   22 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17748   17746   17748  0    6 11:14 ?        00:00:07 /usr/sbin/httpd -DFOREGROUND
apache     17748   17746   17763  0    6 11:14 ?        00:00:02 /usr/sbin/httpd -DFOREGROUND
apache     17748   17746   17771  0    6 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17748   17746   17772  0    6 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17748   17746   17773  0    6 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
apache     17748   17746   17774  0    6 11:14 ?        00:00:00 /usr/sbin/httpd -DFOREGROUND
root       36550   36381   36550  0    1 14:07 pts/1    00:00:00 grep --color=auto httpd
[root@qq-5201351 ~]#

不知道如何理解这种情况,网上有一说法,是真正处理http请求的只有一个线程,其他线程是被其他模块所使用了,也希望有知道原因的大佬能帮忙解疑一下,在此感谢~

 

 

 

尊重别人的劳动成果 转载请务必注明出处:https://www.cnblogs.com/5201351/p/17771946.html