First, you need to understand the MPM (Multi-Processing Modules) that Apache uses. MPM is the core of Apache, which manages network connections and dispatches requests.There are three types of MPM in Apache (perfork, worker, event).
Apache Version 2.4 New features: 1. MPM supports loading at runtime; however, to turn this feature on, enable these three functions at compile and installation; --enable-mpms-shared=all --with-mpm=event 2. Support event s 3. Support Asynchronous Read-Write 4. Specify the log level on each module and directory 5. Enhanced Expression Analyzer 6. Configuration per request: <If>, <Elseif> 7. Keep alive timeout at millisecond level 8. FQDN-based virtual hosts no longer require NameVirtualHost instructions 9. Support for using custom variables
Mainstream site server software:
* Apache: Early, modular design, stable performance on almost all operating systems; relatively complex configuration, unable to parse dynamic web pages by itself. * nginx: High-performance, highly concurrent websites and reverse proxy servers can also act as mail agents. Ali redeveloped tengine for Tmall and Taobao. *Tomcat:javaApplication servers, which are also servlet containers, can be considered extensions to Apache, run independently, or work with Apache.
The difference between Apache and nginx:
* nginx: Configuration is simple, reverse proxy, load balancing, static data processing capacity is more than three times that of Apache, consuming less memory. * Apache: supports common gateway interface (cgi) across all platforms, supports multiple dynamic website languages (php,python,perl,java), has more module components than nginx, runs stably, and has complex configuration
Required installation package:
Extraction Code: ltou
1) Write a script to install apache:
[root@localhost ~]# vim httpd.sh #!/bin/bash cd /root tar zxf apr-1.5.2.tar.gz cd apr-1.5.2/ ./configure --prefix=/usr/local/apr make && make install cd .. tar zxf apr-util-1.5.4.tar.gz cd apr-util-1.5.4/ ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make && make install cd .. tar zxf zlib-1.2.8.tar.gz cd zlib-1.2.8/ ./configure --prefix=/usr/local/zlib make && make install cd .. tar zxf pcre-8.39.tar.gz cd pcre-8.39/ ./configure --prefix=/usr/local/pcre make && make install cd .. tar zxf openssl-1.0.1u.tar.gz cd openssl-1.0.1u/ ./config -fPIC --prefix=/usr/local/openssl enable-shared make && make install mv /usr/bin/openssl /usr/bin/openssl.1.0.1e ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl cd .. tar zxf httpd-2.4.23.tar.gz cd 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 ln -s /usr/local/http-2.4.23/bin/* /usr/local/bin/ echo "ServerName www.example.com:80" >> /usr/local/http-2.4.23/conf/httpd.conf /usr/local/http-2.4.23/bin/apachectl start cp /usr/local/http-2.4.23/bin/apachectl /etc/init.d/httpd systemctl daemon-reload systemctl enable httpd systemctl start httpd
2) View httpd modules
* httpd-V \\ View versions and installed modules * httpd-l \\ View only static compilation modules * httpd-M \\ View all modules
3) MPM (Multi Process Modules): Multiprocessing module
Responsible for network monitoring, request processing and other functions, in order to achieve optimal performance and stability on different platforms.
Operating System Platform MPM BeOS beos NetWare mpm_netware OS/2 mpm_os2 linux prefork,worker,event Windows mpm_winnt
4) Three working modes of apache
Preork mode: Non-threaded, pre-generated process MPM, a subprocess can only process one user request at a time point, dynamically adjusting the subprocess to the number of concurrent requests *Advantages: stability; *Disadvantages: Slow, resource-intensive, not suitable for high concurrency scenarios
worker mode: Threaded, multi-process MPM, each process can generate multiple threads, each thread processes a request, drawbacks: long connections, resources are easy to occupy *Advantage: Preork takes up less memory and can process more requests at the same time; *Disadvantages: With keep-alive long connections, a thread is always occupied and needs to wait until the time-out to be released even if no data is transferred.If too many threads are occupied this way, it can also result in the availability of unserviced threads in high concurrency scenarios.(This also happens in prefork mode).
Evet mode: Improved version of worker that uses monitoring threads to handle resource usage issues with long connections *Benefits: Single threads respond to multiple requests, occupy less memory, perform better with high concurrency, have a dedicated thread to manage keep-alive type threads, pass requests to service threads when real requests come in, and allow them to be released after execution. *Disadvantage: No thread security control.
5) Apache Master Profile
[root@localhost conf]# vim /usr/local/http-2.4.23/conf/httpd.conf
Note: If you want to use any of the three modes, you need to comment out the two remaining modes in the main configuration file.
6) Modify mpm profile
This is just a brief introduction to event mode
[root@localhost ~]# vim /usr/local/http-2.4.23/conf/extra/httpd-mpm.conf <IfModule mpm_event_module> StartServers 3 #Number of child processes started by default at apache startup MinSpareThreads 75 #Minimum number of idle worker threads MaxSpareThreads 250 #Maximum number of worker threads idle ThreadsPerChild 25 #Number of threads per subprocess MaxRequestWorkers 400 #Maximum number of concurrent access requests allowed MaxConnectionsPerChild 0 #Number of requests that can be processed by each child process </IfModule>
7) Use ab command for stress testing
yum -y install httpd-tools ab -c 160 -n 10000 http://192.168.1.1/index.html 160 people were accessed concurrently using the ab stress test command and 10,000 requests were made.
grammar Ab (option) (parameter) option -A: Specify the basic credentials to connect to the server; -c: Specify the number of requests to the server at a time; -C: Add cookie s; -g: output test results as a "gnuolot" file; -h: Display help information; -H: Append an additional header to the request; -i: use the "head" request method; -k: Activate the "keepAlive" feature in HTTP; -n: Specify the number of requests used by the test session; -p: Specify the file that contains the data; -q: no progress percentage is shown; -T: Set the content type header when using POST data; -v: set detailed mode level; -w: Print the results in HTML form; -x: When output in tabular form, set the properties of the table; -X: Send the request using the specified proxy server; -y: Set table properties when output in tabular form. parameter Host: The host under test.