In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Blog outline:
First, install the Apache2.4 version; second, explain in detail the three working modes of Apache services; third, modify the working mode of apache; fourth, optimize and modify the working mode of apache; fifth, the difference between processes and threads.
Apache is a modular design service, the so-called modularization is to separate each function and feature independently, the advantage of this design is strong expansibility, the dependence between each function is relatively weak, it is very convenient to modify, upgrade and add new functions in the later stage. Different modules can be statically compiled into the program, or can be loaded dynamically. Dynamic loading is a feature of apache (DSO,dynamic shared object). When the so-called dynamic loading requires new functions, you only need to compile the functional module and load it into the apache service through the configuration file without recompiling apache.
There are three versions of apache: 2.0,2.2 and 2.4. there are some differences in installation for each version. What I am introducing today is version 2.4. brothers, you should read carefully if you use it.
Introduction to the new features of the new version 2.4 of Apache service:
New module
Mod_proxy_fcgi (can provide fcgi proxy) mod_ratelimit (limit user bandwidth) mod_request (request module, filter requests) mod_remoteip (match client's IP address)
The access control based on IP has been modified, and the allow,deny,order mechanism is no longer supported, but require is used uniformly.
The following new features are also added:
MPM supports loading at run time and supports event support asynchronously reading and writing log-level enhanced expression parsers on each module and each directory per request configuration: millisecond keepalive timeout FQDN-based virtual hosts no longer need NameVirtualHost directives to support the use of custom variables 1. Install Apache2.4
Installation environment: operating system: Centos7.2, turn off selinux
Check to see if the httpd package is installed, and uninstall it if installed.
Download the source package:
Httpd-2.4.23.tar.gz
Apr-1.5.2.tar.gz
Apr-util-1.5.4.tar.gz
Zlib-1.2.8.tar.gz
Pcre-8.39.tar.gz
Note: apr (Apache Portable Runtime) Apache portable runtime, which is an extraction of operating system calls
The image library is used to realize the use of the operating system by the internal components of Apache and improve the portability of the system.
Link: https://pan.baidu.com/s/1km0qEYh656OtEygqc7I1GQ
1. Start installing [root@apache ~] # rz # xshell Use the rz command to upload the downloaded tar package to the web server # the following is to extract all source code packages [root@apache ~] # tar zxf openssl-1.0.1u.tar.gz-C / usr/src [root@apache ~] # tar zxf pcre-8.39.tar.gz-C / usr/src [root@apache ~] # tar zxf zlib-1.2.8.tar.gz-C / usr/src [root@apache ~] # tar zxf httpd-2. 4.23.tar.gz-C / usr/src [root@apache ~] # tar zxf apr-1.5.2.tar.gz-C / usr/src [root@apache ~] # tar zxf apr-util-1.5.4.tar.gz-C / usr/src# below start installing the dependency package required for apache [root@apache ~] # cd / usr/src/apr-1.5.2/ [root@apache apr-1.5.2] #. / configure-- Prefix=/usr/local/apr & & make & & make install [root@apache apr-1.5.2] # cd.. / apr-util-1.5.4/ [root@apache apr-util-1.5.4] #. / configure-- prefix=/usr/local/apr-util-- with-apr=/usr/local/apr & & make & & make install [root@apache zlib-1.2.8] # cd.. / zlib-1.2.8/ [root@apache zlib- 1.2.8] #. / configure-- prefix=/usr/local/zlib & & make & & make install [root@apache pcre-8.39] # cd.. / pcre-8.39/ [root@apache pcre-8.39] #. / configure-- prefix=/usr/local/pcre & & make & & make install [root@apache pcre-8.39] # cd. / openssl-1.0.1u/ [root@apache openssl-1.0.1u] #. / config- FPIC-- prefix=/usr/local/openssl enable-shared & & make & & make install# dependency installation is complete Start installing http service [root@apache openssl-1.0.1u] # cd.. / httpd-2.4.23/ [root@apache httpd-2.4.23] #. / configure-- prefix=/usr/local/http-2.4.23-- enable-so-- enable-cgi-- enable-cgid-- enable-ssl-- with-ssl=/usr/local/openssl-- enable-rewrite-- with-pcre=/usr/local/pcre-- with-z=/usr/local / zlib-with-apr=/usr/local/apr-with-apr-util=/usr/local/apr-util-enable-modules=most-enable-mods-shared=most-enable-mpms-shared=all-with-mpm=event-enable-proxy--enable-proxy-fcgi-enable-expires-enable-deflate & & make & & make install [root@apache httpd-2.4.23] # cd / usr/local/http-2.4.23/bin/ [root@apache bin] # ln-sf / Usr/local/http-2.4.23/bin/* / usr/local/bin/ # soft link the apache command [root@apache bin] # apachectl start # to start the apache service Will prompt the following information, it doesn't matter. # if you want to solve the problem, simply add the domain name to the main configuration file of apache: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::c94:cd92:5c18:a1. Set the 'ServerName' directive globally to suppress this message
The relevant explanations for the configuration items when installing the apache service are as follows:
-- enable-so: enable dos support to add additional features after compilation is completed
-- enable-cgi: enable cgi general network management interface
-- enable-cgid: open the cig general network management interface management program
-- enable-ssl:http encrypted transport protocol, which supports https protocol.
-- enable-rewrite: enable address rewriting for hotlink protection
-- with- service name = / PATH path: specify the path that depends on the service during installation
-- enable-mods-shared=most: install common modules during installation
-- enable-mpms-shared=all: install all operating modes of apache
-- enable-proxy: enable http proxy function
-- enable-proxy-fcgi: fcgi protocol that supports fastcgi Fast Universal Gateway Interface
-- enable-expires: supports caching
-- enable-deflate: supports compression
Apache installation is complete!
Second, the working mode of Apache
The Apache HTTP server is designed as a powerful and flexible server that can work on multiple platforms and environments.
Server. This modular design is called the "MultiProcessing Module, MPM", also known as the working mode.
The three modes of operation of apache services are:
Prefork: pre-spawned child process; worker: multi-process + multi-thread; event: multi-process + multi-thread + epoll processing model; 1.prefork working mode
Prefork is a non-threaded, pre-derived MPM, which uses multiple processes, and each process processes only one connection at a certain time, which is efficient but uses a large amount of memory.
Advantages: suitable for systems that do not have thread-safe libraries and need to avoid thread compatibility problems. It is the best MPM that requires that each request be independent of each other, so that if there is a problem with one request, other requests will not be affected.
Disadvantages: a process takes up more system resources and consumes more memory. Moreover, it is not good at handling highly concurrent requests, in which case it puts the request in a queue until a process is available before the request is processed. 2.Worker working mode
Worker uses a mixed mode of multi-process and multi-thread, and worker mode also pre-derives some child processes, and then each child process creates some threads, including a listening thread, and each request is assigned to a thread to serve.
Advantages: threads are lighter than processes, because threads share the memory space of the parent process, so the memory footprint is reduced. In scenarios with high concurrency and high traffic, there are more threads available than prefork, and the performance is better.
Disadvantages: if there is a problem with one thread, it will also cause problems with threads under the same process. If there is a problem with multiple threads, it will only affect part of the Apache, not all. Due to the use of multi-process and multi-threading, thread safety needs to be taken into account. When using keep-alive persistent connections, a thread will be occupied all the time, even if there is no request in the middle, it will have to wait until the timeout (this problem also exists in prefork mode). 3.Event working mode
The latest working mode of Apache, which is very similar to worker mode.
Advantages: the difference is that it solves the keep-alive long connection when the occupation of thread resources is wasted (HTTP's Keepalive way can reduce the number of TCP connections and network load), in the event work mode, there will be some special threads used to manage these keep-alive type threads, when there is a real request, pass the request to the server thread, and then allow it to release after the completion of execution. This enhances request processing in high concurrency scenarios. 3. Modify the Apache working mode [root@apache bin] # / etc/init.d/httpd-M # View the module loaded by apache [root@apache bin] # / etc/init.d/httpd-V # View the working mode of apache. # omit part of the content Server's Module Magic Number: 20120211:61Server loaded: APR 1.5.2 APR-UTIL 1.5.4Compiled using: APR 1.5.2 APR-UTIL 1.5.4Architecture: 64-bitServer MPM: event # this line is its working mode threaded: yes (fixed thread count) forked: yes (variable process count). # omit part of the content [root@apache bin] # cd / usr/local/http-2.4.23/conf/ # switch to the specified directory [ Root@apache conf] # vim httpd.conf. # omit part of the content Include conf/extra/httpd-mpm.conf # locate the httpd-mpm here Remove the opening comment symbol. # omit part of the content LoadModule mpm_event_module modules/mod_mpm_event.so#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so#LoadModule mpm_worker_module modules/mod_mpm_worker.so # locate the worker to this line # the three lines above are the three working modes of the apache service, which mode of work is required Just comment out the original working mode # and remove the comment symbol from the desired working mode line, and then start the service (note: start, not restart). # omit part of the content # for example, I now change it to worker working mode, then the configuration is as follows: Include conf/extra/httpd-mpm.conf # locate httpd-mpm here Remove the opening comment symbol. # omit part of the content # LoadModule mpm_event_module modules/mod_mpm_event.so#LoadModule mpm_prefork_module modules/mod_mpm_prefork.soLoadModule mpm_worker_module modules/mod_mpm_ worker.so [root @ apache conf] # / etc/init.d/httpd restart # when restarting, the following information may be prompted because of the domain name It doesn't matter AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::c94:cd92:5c18:a1. Set the 'ServerName' directive globally to suppress this message# if you want to resolve those prompts, open the apache's main configuration file and make changes: [root@apache conf] # pwd # determine the current path / usr/local/http-2.4.23/conf [root@apache conf] # vim httpd.conf # Open the file and change the line below, which is native IP, if there is a domain name You can directly write the domain name ServerName 192.168.20.4 # without the annotation symbol at the beginning [root@apache conf] # / etc/init.d/httpd-V # to view the working mode of apache again: Apache/2.4.23 (Unix) Server built: Oct 10 2019 20:52:01Server's Module Magic Number: 20120211:61Server loaded: APR 1.5.2, APR-UTIL 1.5.4Compiled using: APR 1.5.2 APR-UTIL 1.5.4Architecture: 64-bitServer MPM: worker # you can find that the change takes effect. # part of the content is omitted. IV. Optimization and modification of apache working mode.
Changing the working mode above is actually calling a configuration file somewhere else, and the calling configuration file is conf/extra/httpd-mpm.conf, which is why when you change the working mode above, you need to remove the comments on the line Include conf/extra/httpd-mpm.conf first, just to call this configuration file.
[root@apache conf] # cat extra/httpd-mpm.conf | egrep-v'^ # | ^ $'# View the contents of its file And filter out comments and blank lines PidFile "logs/httpd.pid" StartServers 5 MinSpareServers 5 MaxSpareServers 10 MaxRequestWorkers 250 MaxConnectionsPerChild 0 StartServers 3 MinSpareThreads 75 MaxSpareThreads 250 ThreadsPerChild 25 MaxRequestWorkers 400 MaxConnectionsPerChild 0 StartServers 3 MinSpareThreads 75 MaxSpareThreads 250 ThreadsPerChild 25 MaxRequestWorkers 400 MaxConnectionsPerChild 0 ThreadStackSize 65536 StartThreads 250 MinSpareThreads 25 MaxSpareThreads 250 MaxThreads 1000 MaxConnectionsPerChild 0 StartServers 2 MinSpareThreads 5 MaxSpareThreads 10 MaxConnectionsPerChild 0 ThreadsPerChild 150 MaxConnectionsPerChild 0 MaxMemFree 2048 MaxMemFree 100
As the above configuration file is too cumbersome to explain, a figure is attached here, which you can refer to to change the above configuration:
Note: the value of each configuration item has a default limit. If you want to change its limit, you need to add the ServerLimit configuration item on the previous line of the configuration item, and the ServerLimit configuration item also has the maximum limit. If you want to modify various values, it is recommended to read the following carefully before making changes.
Worker "StartServers" child processes are generated by the main control process. Each child process contains a fixed number of ThreadsPerChild threads, and each thread processes the request independently. Similarly, in order not to generate threads when the request arrives, MinSpareThreads and MaxSpareThreads set the minimum and maximum number of idle threads. MaxRequestWorkers sets the maximum total number of clients connected at the same time. If the total number of threads in the existing child process does not meet the load, the control process will derive new child processes MinSpareThreads and MaxSpareThreads with maximum default values of 75 and 250, respectively. These two parameters have little effect on the performance of Apache and can be adjusted according to the actual situation. ThreadsPerChild is the most performance-related instruction in worker MPM. The maximum default value for ThreadsPerChild is 64, which is not enough if the load is heavy. The ThreadLimit instruction is used explicitly, and its maximum default value is 20000. The total number of requests that can be processed simultaneously in Worker mode is determined by the total number of child processes multiplied by the ThreadsPerChild value, which should be greater than the equal MaxRequestWorkers. If the load is so heavy that the number of existing child processes cannot be satisfied, the control process will derive new child processes. By default, the maximum number of child processes is 16, and you also need to explicitly declare ServerLimit when you enlarge (the maximum number of processes configured by the system, the maximum is 20000). It is important to note that if ServerLimit is explicitly declared, its value multiplied by ThreadsPerChild must be greater than or equal to MaxRequestWorkers, and MaxRequestWorkers must be an integral multiple of ThreadsPerChild, otherwise Apache will automatically adjust to a corresponding value. Fifth, the difference between process and thread
A thread is an execution unit within a process and a schedulable entity within a process.
The difference from the process:
(1) address space: an execution unit within a process; the process has at least one thread; they share the process's address space; and the process has its own independent address space.
(2) Resource ownership: a process is a unit of resource allocation and ownership, and threads in the same process share the resources of the process.
(3) Thread is the basic unit of processor scheduling, but the process is not.
(4) both of them can be executed concurrently.
Processes and threads are the basic units of program running experienced by the operating system, and the system uses this basic unit to realize the system's response to the
Concurrency of the application.
The difference between a process and a thread is:
In short, a program has at least one process and a process has at least one thread.
The division scale of threads is smaller than that of processes, which makes multithreaded programs have high concurrency. In addition, the process has an independent memory unit during execution, and multiple threads share memory, which greatly improves the running efficiency of the program.
This is the end of this article. Thank you for reading
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: 261
*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.