In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
Introduction of Apache working mode
Apache is the most widely used and most stable open source server software for web servers today.
There are many working modes. When the source package installs httpd, you can view the httpd-mpm.conf file. The file is located in the extra/conf directory. At present, there are three main modes: event mode, prefork mode, worker mode, event working mode introduction.
Event is the latest working mode of Apache, which is very similar to worker mode, except that it solves the problem of line occupation when keep-alive has a long connection.
The problem of process resources being wasted
Event working mode will fail when it encounters some incompatible modules and will fall back to worker mode
The event working mode requires epoll support from the Linux system (Linux 2.6 +) to enable it. What needs to be added is the way HTTPS SSL event works.
In the event working mode, there are specialized threads to manage these keep-alive types of threads
When a real request comes, pass the request to the thread of the server, and when the execution is complete, allow it to release
In this way, a thread can handle several requests, achieving asynchronous non-blocking. This enhances the explanation of event parameters for request processing in high concurrency scenarios.
In the httpd-mpm.conf configuration file, the following is the definition of the event module:
Parameter StartServers 3MinSpareThreads 75MaxSpareThreads 250ThreadsPerChild 25MaxRequestWorkers 400MaxConnectionsPerChild 0 indicates the initial number of processes when the StartServers service starts, the minimum number of free child processes in the default 3MinSpareThreads, the maximum number of free child processes in the default 75MaxSpareThreads, the number of threads generated by each child process in the default 250ThreadsPerChild, and the maximum number of requests accessed by the client at the same time limited by 25MaxRequestWorkers. By default, 400MaxConnectionsPerChild allows the maximum number of requests per child process during its life cycle. If the total number of requests has reached this value, the child process will end, and if set to 0, the child process will never end. Setting this value to a non-zero value can prevent memory leaks caused by running PHP. Introduction to prefork working mode.
Prefork is a general multiprocessing module (MPM), which implements a process-based, pre-derived web server, which is suitable for systems without thread-safe libraries and need to avoid thread compatibility problems.
It has good characteristics when each request is required to be independent of each other. If there is a problem with one request, it will not affect other requests.
It has a strong ability of self-regulation, and only a few configuration instructions are needed to adapt to the requirements of enterprise applications.
The most important thing is to set MaxClients to a large enough value to handle potential request peaks while not too large to avoid the prefork mode of working in which the required memory exceeds the physical memory.
A separate control process (parent process) is responsible for generating child processes, which are used to listen to requests and respond, so there will always be some spare or idle child processes in memory to respond to new requests, which can speed up the response.
The parent process usually runs as root to bind port 80, and the child process usually runs as a low-privileged user, which can be configured through the User and Group of the configuration item
The user running the child process must have read access to the content of the site, but must have as few permissions as possible to other resources to ensure system security.
No working mode is specified when compiling and installing. Prefork mode is used by default. You can use httpd-l to view the prefork parameter and explain it.
In the httpd-mpm.conf configuration file, the following is the definition of the prefork module
Parameter StartServers 20MinSpareServers 10MaxSpareServers 50MaxClients 150MaxRequestsPerChild 0 indicates the maximum number of processes created when ServerLimit is started. MinSpareServers minimum idle process MaxSpareServers maximum idle process MaxClients maximum number of child processes to handle requests MaxRequestsPerChild the maximum number of requests processed by each process, the process will be destroyed if it is set to 0, the child process will never end the introduction of worker working mode
Worker is also a multiplexing module (MPM), which enables the network server to support mixed multithreading and multiprocess.
Because threads are used to process requests, it can handle a large number of requests, and the overhead of system resources is less than that of process-based MPM.
But it also uses multiple processes, each with multiple threads, to achieve the stability of process-based MPM
The most important instructions to control the MPM are the ThreadsPerChild instruction to control the number of threads allowed to be established by each child process and the MaxClients instruction worker to control the number of buses allowed to be established.
The number of threads each process can have is fixed, and the server will increase or decrease the number of processes according to the load.
A separate control process (parent process) is responsible for the establishment of child processes. Each child process can set up a number of ThreadsPerChild service threads and one listener thread, which listens for access requests and passes them to the service thread for processing and response
Apache always maintains a spare or idle pool of service threads, and the client can be serviced without waiting for a new thread or process to be established.
The parent process is usually started as root to bind port 80, and then Apache sets up child processes and threads with lower privileges
The User and Group directives are used to configure the running user of the Apache child process. The child process should have read permission to the content of the web page, but the permission should be limited as much as possible. The worker parameter explanation
In the httpd-mpm.conf configuration file, the following is the definition of the worker module
The ServerLimit 40ThreadLimit 200StartServers 20MaxClients 1000MinSpareThreads 25MaxSpareThreads 100ThreadsPerChild 200MaxRequestsPerChild 1000 parameter indicates the maximum number of processes in ServerLimit. The default value is the maximum number of threads per child process of "16" ThreadLimit, and the default value is the number of child processes established when the "64" StartServers server starts. The default value is the maximum number of access requests allowed by "3" MaxClients (maximum number of threads) MinSpareThreads minimum number of idle threads, and the default value is "75" MaxSpareThreads sets the maximum number of idle threads. The default value is the number of resident threads of execution established by each child process of the "250th" ThreadsPerChild. The default value is 25MaxRequestsPerChild to set the maximum number of requests that each child process is allowed to serve during its lifetime. Set to "0", the child process will never end the Apache directory attribute parameter function Options sets which properties to use in a particular directory AllowOverride allows instruction types that exist in .htaccess files Require sets the access control of the directory Indexes when the user accesses the directory but does not specify which file to access, and when there is no default web page in the directory, returns the multi-focus graph negotiated between the files in the directory and the subdirectory list MultiViews content An intelligent feature of Apache. When accessing objects that do not exist in the directory, ExecCGl allows the execution of CGI scripts in this directory FollowSymLinks allows file systems to use symbolic connections Includes allows server-side to include functions IncludesNoExec allows server-side to include functions, but forbids execution of CGI scripts All to include all features except MultiViews, if there is no Options statement, the default is All to manually compile and install the Apache service:
(1) install the DNS service package bind.
[root@localhost ~] # yum install bind-y.mp / omit the installation process [root@localhost ~] #
(2) modify the main configuration file of the DNS service.
[root@localhost ~] # vim / etc/named.confoptions {listen-on port 53 {any;}; / / 127.0.0.1 change to any listen-on-v6 port 53 {:: 1;}; directory "/ var/named"; dump-file "/ var/named/data/cache_dump.db" Statistics-file "/ var/named/data/named_stats.txt"; memstatistics-file "/ var/named/data/named_mem_stats.txt"; recursing-file "/ var/named/data/named.recursing"; secroots-file "/ var/named/data/named.secroots"; allow-query {any;}; / / localhost changed to any
(3) modify the regional configuration file of the DNS service.
[root@localhost ~] # vim / etc/named.rfc1912.zoneszone "abc.com" IN {/ / add a domain name information type master; file "abc.com.zone"; allow-update {none;};}
(4) check the IP address.
[root@localhost named] # ifconfig ens33: flags=4163 mtu 1500 inet 192.168.52.133 netmask 255.255.255.0 broadcast 192.168.52.255 inet6 fe80::3e1d:31ba:f66a:6f80 prefixlen 64 scopeid 0x20 ether 00:0c:29:27:1c:3f txqueuelen 1000 (Ethernet) RX packets 14532 bytes 20210558 (19.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 6054 bytes 399142 (389.7 KiB ) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
(5) reserve the right to copy a regional data configuration file of the DNS service and modify it.
[root@localhost ~] # cd / var/named/ change the directory [root@localhost named] # ls / / View data dynamic named.ca named.empty named.localhost named.loopback slaves [root@localhost named] # cp-p named.localhost abc.com.zone / / copy [root@localhost named] # vim abc.com.zone $TTL 1D @ IN SOA @ rname.invalid. (0; serial 1D; refresh 1H; retry 1W; expire 3H) Minimum NS @ A 127.0.0.1www IN A 192.168.52.133 / / Domain name resolution by adding IPv4
(6) start the named service.
[root@localhost named] # systemctl start named / / enable the service [root@localhost named] # systemctl stop firewalld.service / / turn off the firewall [root@localhost named] # setenforce 0 / / disable the enhanced security feature [root@localhost named] #
(7) share the toolkits we need at the host.
(8) Mount the toolkit to the Linux system through the Samba service.
[root@localhost ~] # smbclient-L / / 192.168.100.50 / / View share Enter SAMBA\ root's password: / / Anonymous share, no password Direct enter OS= [Windows 10 Enterprise LTSC 2019 17763] Server= [Windows 10 Enterprise LTSC 2019) Sharename Type Comment-IPC$ IPC remote IPC share Disk tools Disk Users Disk Connection to 192.168.100.50 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND) NetBIOS over TCP disabled-- no workgroup available [root@localhost ~] # mkdir / mnt/tools/ / create a mount directory [root@localhost ~] # mount.cifs / / 192.168.100.50/tools / mnt/tools/ mount Password for root@//192.168.100.50/tools: [root@localhost ~] # cd / mnt/tools/ enter the mount directory [root @ localhost tools] # ls / / View awstats-7.6.tar.gz extundelete-0.2.4.tar.bz2 forbid.png jdk-8u191-windows-x64.zip LAMP-C7cronolog-1.6.2-14.el7.x86_64.rpm fiddler.exe intellijideau2018.rar john-1.8.0.tar.gz picture.jpg [root@localhost tools] #
(9) unpack the source code compilation and installation of the Apache service to the "/ opt/" directory.
[root@localhost tools] # cd LAMP-C7/ switch directory [root@localhost LAMP-C7] # lsapr-1.6.2.tar.gz Discuz_X2.5_SC_UTF8.zip LAMP-php5.6.txt php-5.6.11.tar.bz2apr-util-1.6.0.tar.gz httpd-2.4.29.tar.bz2 mysql-5.6.26.tar.gz [root@localhost LAMP-C7] # tar jxvf httpd-2.4.29.tar.bz2-C / opt/ decompress. / / omit decompression details [root@localhost LAMP-C7] # tar zxvf apr-1.6.2.tar.gz-C / opt/ decompression. / / omit decompression details [root@localhost LAMP-C7] # tar zxvf apr-util-1.6.0.tar.gz-C / opt/ / / decompress. / / omit the decompression details
(10) go to the "/ opt/" directory, move the two apr packages to the "httpd-2.4.29/srclib/" directory, and rename them.
[root@localhost LAMP-C7] # cd / opt/ [root@localhost opt] # lsapr-1.6.2 apr-util-1.6.0 httpd-2.4.29 rh [root@localhost opt] # mv apr-1.6.2/ httpd-2.4.29/srclib/apr [root@localhost opt] # mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util
(11) go to the "httpd-2.4.29/" directory and install the environment package required for compilation.
[root@localhost opt] # lshttpd-2.4.29 rh [root@localhost opt] # cd httpd-2.4.29/ [root@localhost httpd-2.4.29] # lsABOUT_APACHE ap.d CHANGES docs httpd.spec libhttpd.dep Makefile.win README srclibacinclude.m4 build CMakeLists.txt emacs-style include libhttpd.dsp modules README.cmake supportApache-apr2 .dsw BuildAll.dsp config.layout httpd.dep INSTALL libhttpd.mak NOTICE README.platforms testApache.dsw BuildBin.dsp configure httpd.dsp InstallBin.dsp LICENSE NWGNUmakefile ROADMAP VERSIONINGapache_probes.d buildconf configure.in httpd.mak LAYOUT Makefile.in os server [root@localhost httpd-2.4.29] # [root@localhost httpd-2.4.29] # Yum-y install\ > gcc\ > gcc-c++\ > make\ > pcre\ > pcre-devel\ > expat-devel\ > zlib-devel\ > perl.// omits the installation process
(12) configure the Apache server.
[root@localhost httpd-2.4.29] #. / configure\ >-- prefix=/usr/local/httpd\ / / installation path >-- enable-so\ / / enable dynamic loading module support >-- enable-rewrite\ / / enable web address rewriting function >-- enable-charset-lite\ / / enable character set support >-- enable-cgi / / enable CGI script program support
(13) compile and install the Apache service.
[root@localhost httpd-2.4.29] # make & & make install.// omits the compilation and installation process [root@localhost httpd-2.4.29] #
(14) modify the Apache service configuration file
[root@localhost httpd-2.4.29] # ln-s / usr/local/httpd/conf/httpd.conf / etc/httpd.conf / / create a soft link to facilitate the use of [root@localhost httpd-2.4.29] # Listen 192.168.50.133 usr/local/httpd/conf/httpd.conf 80 / / enable IPv4 snooping # Listen 80 / / comment IPv6 snooping # ServerName www.abc.com:80 / / set domain name Apache working mode experiment
(1) Open the sub-profile of the working mode.
[root@localhost httpd-2.4.29] # vim / etc/httpd.conf# Server-pool management (MPM specific) Include conf/extra/httpd-mpm.conf / / Delete "#"
(2) check the current working mode, which is event mode (default).
[root@localhost httpd-2.4.29] # httpd- lCompiled in modules: core.c mod_so.c http_core.c event.c [root@localhost httpd-2.4.29] #
(3) check the current working mode and the number of processes opened.
[root@localhost httpd-2.4.29] # service httpd stop / / disable service [root@localhost httpd-2.4.29] # service httpd start / / enable service [root@localhost httpd-2.4.29] # lsof-I: 80 / / View port process COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEhttpd 91399 root 3u IPv4 266957 0t0 TCP localhost.localdomain:http (LISTEN) httpd 91401 daemon 3u IPv4 266957 0t0 TCP localhost.localdomain:http (LISTEN) httpd 91402 daemon 3U IPv4 266957 0t0 TCP localhost.localdomain:http (LISTEN) httpd 91403 daemon 3u IPv4 266957 0t0 TCP localhost.localdomain:http (LISTEN) [root@localhost httpd-2.4.29] #
(4) modify the configuration of event working mode, change StartServers from "3" to "5", and optimize other items accordingly.
[root@localhost httpd-2.4.29] # cd / usr/local/httpd/conf/extra/ [root@localhost extra] # lshttpd-autoindex.conf httpd-default.conf httpd-languages.conf httpd-mpm.conf httpd-ssl.conf httpd-vhosts.confhttpd-dav.conf httpd-info.conf httpd-manual.conf httpd-multilang-errordoc.conf httpd-userdir.conf proxy-html.conf [root@localhost extra] # vim httpd- Mpm.conf StartServers 5 MinSpareThreads 150 MaxSpareThreads 400 ThreadsPerChild 30 MaxRequestWorkers 390 MaxConnectionsPerChild 0
(5) restart the service and check the number of port processes again. The number of child processes has changed from 3 to 5.
[root@localhost extra] # service httpd stop [root@localhost extra] # service httpd start [root@localhost extra] # lsof-I: 80COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAMEhttpd 92896 root 3u IPv4 270648 0t0 TCP localhost.localdomain:http (LISTEN) httpd 92898 daemon 3u IPv4 270648 0t0 TCP localhost.localdomain:http (LISTEN) httpd 92899 daemon 3u IPv4 270648 0t0 TCP localhost.localdomain:http (LISTEN) httpd 92900 daemon 3u IPv4 270648 0t0 TCP localhost. Localdomain:http (LISTEN) httpd 92901 daemon 3U IPv4 270648 0t0 TCP localhost.localdomain:http (LISTEN) httpd 92902 daemon 3u IPv4 270648 0t0 TCP localhost.localdomain:http (LISTEN) [root@localhost extra] #
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.