zl程序教程

您现在的位置是:首页 >  其他

当前栏目

Linux apache的常见配置(2)功能模块管理

2023-02-18 16:34:38 时间

说明:apache是一个模块化的软件,很多功能由一个个模块来提供的。

动态加载模块:DSO (Dynamic Shared Object)

Dynamic Shared Object,动态共享对象,加载动态模块配置,不需重启即生效

动态模块所在路径:
/usr/lib64/httpd/modules/
查看目前在apache中加载的模块:
httpd -M
管理模块:LoadModule指令

通过模块加载的配置文件结合LoadModule指令进行管理。

模块配置文件路径:/etc/httpd/conf.modules.d/

在00-base.conf的配置文件中注释或者添加loadModule指令来实现模块的加载和不加载
查看静态编译的模块:httpd -l

静态模块:编译的时候启用的模块功能,如果想换只能重新编译。

apache的多路处理模块(MPM)管理

httpd 支持三种MPM工作模式:prefork, worker, event

例如:查看默认使用的mpm工作模式:

[root@CentOS8 ~]# httpd -M | grep mpm
 mpm_event_module (shared)

 [root@centos7 ~]# httpd -M |grep mpm
message
 mpm_prefork_module (shared)
更改使用的MPM工作模式:

修改mpm的模块配置文件实现:

/etc/httpd/conf.modules.d/00-mpm.conf这个配置文件修改

范例:修改CentOS 8使用 prefork 模型

[root@CentOS8 ~]# vim /etc/httpd/conf.modules.d/00-mpm.conf 
[root@CentOS8 ~]# cat /etc/httpd/conf.modules.d/00-mpm.conf
# Select the MPM module which should be used by uncommenting exactly
# one of the following LoadModule lines.  See the httpd.conf(5) man
# page for more information on changing the MPM.

# prefork MPM: Implements a non-threaded, pre-forking web server
# See: http://httpd.apache.org/docs/2.4/mod/prefork.html
#
# NOTE: If enabling prefork, the httpd_graceful_shutdown SELinux
# boolean should be enabled, to allow graceful stop/shutdown.
#
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so #取消这行的注释

# worker MPM: Multi-Processing Module implementing a hybrid
# multi-threaded multi-process web server
# See: http://httpd.apache.org/docs/2.4/mod/worker.html
#
#LoadModule mpm_worker_module modules/mod_mpm_worker.so  #如果切换为worker就取消这行注释

# event MPM: A variant of the worker MPM with the goal of consuming
# threads only for connections with active processing
# See: http://httpd.apache.org/docs/2.4/mod/event.html
#
#LoadModule mpm_event_module modules/mod_mpm_event.so #默认是event模式

[root@CentOS8 ~]# httpd -M | grep prefork #已经动态切换为prefork模式
 mpm_prefork_module (shared)

#通过源码安装的直接就在主配置文件中进行开启或关闭

说明:不能同时开启多个MPM模块

MPM三种工作模式的配置
  • prefork 模式相关的配置
StartServers       100  #指定刚开启服务时开启的子进程

MinSpareServers   50  #最少预留的空闲进程

MaxSpareServers   80 #最多预留的空闲进程

ServerLimit     2560 #最多进程数,最大值 20000

MaxRequestWorkers    2560 #最大的并发连接数,默认256

MaxConnectionsPerChild  4000 #子进程最多能处理的请求数量。在处理MaxRequestsPerChild 个请求之后,子进程将会被父进程终止,这时候子进程占用的内存就会释放(为0时永远不释放)

MaxRequestsPerChild 4000  #从 httpd.2.3.9开始被MaxConnectionsPerChild代替
  • worker和event 模式相关的配置
ServerLimit         16  #最多开启的子进程  最多worker进程数 Upper limit on configurable number of processes

StartServers        10  #服务启动时开启多少个子进程

MaxRequestWorkers  150  #最大连接数(最多并发多少个连接)

MinSpareThreads     25

MaxSpareThreads     75

ThreadsPerChild     25  #每个子进程开多少个线程