龙空技术网

Linux基础架构学习 - Apache用于企业级容错 - Day07

小白熊工作室 217

前言:

现时小伙伴们对“杀死apache进程”可能比较珍视,各位老铁们都想要了解一些“杀死apache进程”的相关知识。那么小编也在网络上汇集了一些有关“杀死apache进程””的相关知识,希望小伙伴们能喜欢,我们快快来学习一下吧!

调整Apache HTTP

开箱即用,Apache HTTP表现良好;但是,您会发现通过调优可以从Apache中获得更多。本节介绍了一些可用于从Apache中获取更多性能的选项。

硬件

Apache受物理RAM量和系统中CPU处理能力的限制。这是一个更大更好的情况。您拥有的CPU和RAM越多,您可以分叉的Apache HTTP子级越多,或者您可以创建的线程越多,以提供更多连接。 Apache服务器不应该交换进程,因为这会大大降低性能。计算每个子进程占用的内存量,并将其乘以允许的最大Apache HTTP子进程数。解决方案是Apache所需的最小RAM量,不包括其他进程和操作系统。

网络吞吐量对Apache HTTP的性能也非常重要。如果您的HTTP服务器具有多个网络接口,则Apache HTTP的网络带宽容量会增加。对于繁忙的站点,应考虑10GB网络接口。此外,具有冗余的多个网络接口,并使用Linux网络接口控制器(NIC)绑定将它们绑定,以便为您提供故障转移以及增加容量。

软件

使用最新版本的Apache可以从HTTP进程中获得更多。通常,较新版本的Apache比以前的版本具有性能改进,或者可能会为当前环境增加重要价值的错误修复。

模块

Apache HTTP提供了许多模块,其中许多模块都是默认加载的。您可以通过查询server-info获取服务器中加载的所有模块的列表,如清单6-10所示。

清单6-10。查询Apache加载模块

# curl -s  | html2text****** Apache Server Information ****** Server Module List core.c event.c http_core.c mod_access_compat.c mod_alias.c mod_auth_basic.c mod_authn_core.c mod_authn_file.c mod_authz_core.c mod_authz_groupfile.c mod_authz_host.c mod_authz_user.c mod_autoindex.c mod_dir.c mod_env.c mod_filter.c mod_headers.c mod_info.c mod_log_config.c mod_mime.c mod_reqtimeout.c mod_setenvif.c mod_so.c mod_status.c mod_unixd.c mod_version.c===============================================================================

其中一些模块可能不需要,应该删除。要了解模块的功能,请阅读上的模块文档。要在/usr/local/apache2/conf/httpd.conf中禁用模块,请注释以要禁用的模块的LoadModule <modulename>开头的行,然后使用命令/ usr / local / apache2重新启动Apache HTTP / bin / apachectl restart。

修改MPM配置

Apache HTTP默认配置为在使用默认设置安装时接受一定数量的客户端连接。对于基于事件的MPM,您可以轻松地增加MaxRequestWorkers连接以适应服务器的内存量。清单6-11显示了基于事件的MPM的默认设置。如果要增加Apache可以为基于事件的MPM处理的并发连接数,请增加MaxRequestWorkers的值。将ServerLimit的值与ThreadsPerChild相乘得出MaxRequestWorkers值。如果增加MaxRequestWorkers,还应该增加ServerLimit的值。 ServerLimit默认为16;如果在httpd-mpm.conf文件中找不到它,请将其添加进行清除。

Apache HTTP启动单个父进程,然后生成StartServers中指定的服务器数。在清单6-11中,这是一个父级,后跟三个进程。然后,这些进程中的每一个都生成MinSpareThreads,在本例中为75.除了MinSpareThreads之外,还会生成另一个线程,它是一个侦听器线程,用于侦听连接并将它们传递给处理线程。

MaxSpareThreads是备用线程的上限,之后Apache开始杀死线程以使它们保持在MaxSpareThreads之下。 MaxConnectionsPerChild是孩子可以服务的连接数,之后孩子被杀死并产生一个新孩子。如果Web应用程序中存在内存泄漏,这可能会有所帮助。将此值设置为零可让Apache知道在服务的某个连接限制之后无需终止线程。

对于事件和工作者MPM,ServerLimit的代码限制为20,000。对于prefork,限制为200,000。如果要超出每个服务器的限制,则必须在源代码中更改MAX_SERVER_LIMIT的值并重新编译。

Listing 6-11. Event MPM Defaults

## From /usr/local/apache2/conf/extra/httpd-mpm.conf# event MPM# StartServers: initial number of server processes to start# MinSpareThreads: minimum number of worker threads which are kept spare# MaxSpareThreads: maximum number of worker threads which are kept spare# ThreadsPerChild: constant number of worker threads in each server process# MaxRequestWorkers: maximum number of worker threads# MaxConnectionsPerChild: maximum number of connections a server process serves# before terminating<IfModule mpm_event_module> ServerLimit 16 StartServers 3 MinSpareThreads 75 MaxSpareThreads 250 ThreadsPerChild 25 MaxRequestWorkers 400 MaxConnectionsPerChild 0</IfModule>

您可以使用命令pstree查看Apache HTTP将创建的进程数和线程数。 当ServerLimit为3时,MinSpareThreads为3,您会看到类似于清单6-12所示的输出。 你会有一个父进程; 此示例中的进程ID为65427,然后生成三个子节点:65428,65429和65430.每个子节点都有一个侦听线程和最少线程数,在本例中为三个。 每个进程有一个“额外”线程的原因是处理传入连接并将它们传递给“工作”线程。

Listing 6-12. pstree with the Event MPM

httpd(65427)-+-httpd(65428)-+-{httpd}(65486) | |-{httpd}(65487) | |-{httpd}(65488) | |-{httpd}(65489) |-httpd(65429)-+-{httpd}(65460) | |-{httpd}(65461) | |-{httpd}(65462) | |-{httpd}(65463) `-httpd(65430)-+-{httpd}(65434) |-{httpd}(65435) |-{httpd}(65436) |-{httpd}(65437)

工人MPM与基于事件的MPM非常相似。 因此,设置似乎相似。 清单6-13显示了worker MPM的默认值。

清单6-13。 工人MPM默认值

# worker MPM# StartServers: initial number of server processes to start# MinSpareThreads: minimum number of worker threads that are kept spare# MaxSpareThreads: maximum number of worker threads that are kept spare# ThreadsPerChild: constant number of worker threads in each server process# MaxRequestWorkers: maximum number of worker threads# MaxConnectionsPerChild: maximum number of connections a server process serves# before terminating<IfModule mpm_worker_module> ServerLimit 16 StartServers 3 MinSpareThreads 75 MaxSpareThreads 250 ThreadsPerChild 25 MaxRequestWorkers 400 MaxConnectionsPerChild 0</IfModule>

prefork MPM与事件和工作者有点不同,因为它产生进程而不是线程。 而不是事件和工作者的默认75个线程,prefork以StartServers值5开始.MaxRequestWorkers小于事件和工作者MPM,并且列在250,而事件和工作者则为400。 进程比线程更昂贵,因此您需要更多资源来执行相同的任务。 清单6-14显示了prefork MPM的默认值。

清单6-14。 Prefork MPM默认值

# prefork MPM# StartServers: number of server processes to start# MinSpareServers: minimum number of server processes that are kept spare# MaxSpareServers: maximum number of server processes that are kept spare# MaxRequestWorkers: maximum number of server processes allowed to start# MaxConnectionsPerChild: maximum number of connections a server process serves# before terminating<IfModule mpm_prefork_module> ServerLimit 16 StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxRequestWorkers 250 MaxConnectionsPerChild 0</IfModule>

标签: #杀死apache进程