Operating mode 1, Prefork MPM
Prefork MPM implements a non-threaded, pre-derived Web server. At the beginning of Apache startup, it pre-derives some child processes and waits for connections, reducing the overhead of frequent creation and destruction of processes, with only one thread per child process, and only one request in a single point in time. This is a mature and stable, can be compatible with new and old modules, do not need to worry about thread safety issues, but a process is relatively resource-intensive, consuming a lot of memory, not good at dealing with high concurrency scenarios. (-1)
2, the Worker MPM
Compared with prefork mode, the worker uses a mixed mode of multi-process and multi-threading, the worker pattern also pre-derives some child processes, and then each child process creates some threads, including a listener thread, each request will be assigned to a thread service. A thread is lighter than a process because the thread is sharing the memory space of the parent process, so the memory footprint is reduced, and in high concurrency scenarios there are more threads available than prefork, and the performance will be better, and if one thread is having a problem, it can cause a thread in the same process to become problematic. If there is a problem with multiple threads, it only affects part of Apache, not all. Due to the use of multi-process multi-threading, it is necessary to take into account the security of the thread, when using keep-alive long connection, a thread will always be occupied, even if there is no request, need to wait until the timeout will be released (the problem is also present in Prefork mode). (-2)
3. The Event MPM
This is the Apache mode of operation, it is similar to the worker mode, the difference is that it solves the keep-alive long connection when the use of thread resources is wasted, in the event mode, there will be some specialized threads to manage these keep-alive types of threads, When there is a real request coming, the thread that passes the request to the server, after execution, is allowed to release it. This enhances request handling in high concurrency scenarios.
View Apache working mode:
# httpd-v
Switch mode of operation:
RPM-Installed Apache
#vim/etc/sysconfig/httpd
#vim/etc/httpd/conf.modules.d/00-mpm.conf
To modify different loading modules
Compiled and installed Apache
./configure--prefix= ""
Compiling the installation requires specifying
You can use--with-mpm=prefork|worker| when you configure compilation parameters in Configure.
Event to specify the type of MPM to compile, of course, it can be compiled to three kinds of support:--enable-
Mpms-shared=all, which automatically compiles three in the modules directory at compile time.
MPM file, and then change the MPM by modifying the httpd.conf configuration file
Note: Switching to non-process mode requires that PHP be closed
Number of initialization processes
Maximum number of idle processes
Minimum number of idle processes
Maximum concurrency
Number of connections per process that can be accepted
Number of initialization processes
Maximum number of idle processes
Minimum number of idle processes
Number of threads in each process
Maximum concurrency
Number of connections per process that can be accepted
Process mode
Threading mode
Event Mode:
Both of these stable mpm methods are somewhat inadequate in very busy server applications. Although the keepalive way of HTTP can reduce the number of TCP connections and network load, keepalive needs to be bound to the service process or thread, which causes a busy server to consume all the threads. The Event MPM is a new model for solving this problem, which separates the service process from the connection. The event MPM approach is most effective when the server is processing fast and has a very high click-through rate, the number of threads available is the critical resource limit. A busy server that works as a worker mpm can withstand a good tens of thousands of visits per second (for example, at the peak of a large news Service site), and event MPM is used to handle higher loads. It is important to note that the Event MPM does not work under secure HTTP (HTTPS) access.
For the event mode, Apache gives the following warning:
This MPM was experimental, so it could or may not be work as expected.
This MPM is currently under trial, and he may not be able to work as expected.
RPM Installation mode default 3 modes are supported
Process mode:
<ifmodule prefork.c>
Startservers 8
Minspareservers 5
Maxspareservers 20
Serverlimit 256 Process Cap
maxclients 256 Max concurrency
Maxrequestsperchild 4000
</IfModule>
Threading Mode:
<ifmodule worker.c>
Startservers 4
MaxClients 300
Minsparethreads 25
Maxsparethreads 75
Threadsperchild 25
Maxrequestsperchild 0
</IfModule>
Event Mode:
<ifmodule mpm_event_module>
Startservers 3
Serverlimit 16
Minsparethreads 75
Maxsparethreads 250
Threadsperchild 25
Maxrequestworkers 400//with MaxClients
Maxconnectionsperchild 1000
</IfModule>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Timeout 15
--------------------
KeepAlive Long connection (keep connected, persistent connection)
Open keepalive:
KeepAlive on//on is on, off is off
Eepalivetimeout 15//Two time interval between get files
Maxkeepaliverequests 100//maximum number of requests that can be accepted per long connection
Open process
Client---Server
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
KeepAlive an option within the Apache configuration file
KeepAlive TCP/IP also has keepalive
Keepalived High-availability scenarios
Access control
Prepare the test catalog:
#mkdir/var/www/html/site1
#echo site1 >/var/www/html/site1/index.html
#cat/var/www/html/site1/index.php
<?php
Phpinfo ();
?>
Access Control Testing:
allow all hosts to access:
<directory "/var/www/html/site1" >
AllowOverride None
Require all granted//wing test this is the default value, do not write also can
</Directory>
AllowOverride all allows settings in the. htaccess in the subdirectory to overwrite the current setting
AllowOverride None does not allow the settings in the. htaccess in subdirectories to overwrite the current settings
allow only a subset of clients to access:
<directory "/var/www/html/site1" >
AllowOverride None
Require IP 192.168.245.3//can write network segment
Require IP 127.0.0.1
</Directory>
deny only a subset of client access:
<directory "/var/www/html/site1" >
AllowOverride None
<RequireAll>
Require not IP 127.0.0.1 192.168.245.3
Require all granted
</RequireAll>
</Directory>
deny all client access:
<directory "/var/www/html/site1" >
AllowOverride None
<RequireAll>
Require all denied
</RequireAll>
</Directory>
Wing Test Apache 2.2 still takes effect:
<directory "/var/www/html/site1" >
AllowOverride None
Order Allow,deny
Deny from all
</Directory>
<directory "/var/www/html/site1" >
AllowOverride None
Order Deny,allow//allow and deny who writes the back first, regardless of the order of the following deny and allow
Deny from all
Allow from 192.168.245.3
</Directory>
individually control whether certain paging files can be accessed by some clients:
<directory "/var/www/html/site1" >
AllowOverride None
Require all granted
<files ~ "\.php$" >
Order Allow,deny
Deny from all
</Files>
</Directory>
~ Indicates a match
\.php$. php
\ escape Character
$ indicates the end of the preceding character
user-based access control: User name and password required for access
1. Create a password file (add first account)
# HTPASSWD-CM/ETC/HTTPD/CONF/HTTPPASSWD User1
-C Create a password file
-M MD5 mode encryption
Add multiple other accounts:
# htpasswd-m/ETC/HTTPD/CONF/HTTPPASSWD User2
2. Configure Support Certifications
To modify the master configuration file:
<directory "/var/www/html/site1" >
AllowOverride All
Require all granted
</Directory>
3. Create the. htaccess file:
# vim/var/www/html/site1/.htaccess
AuthName "Hello kity"
AuthType Basic
AuthUserFile "/ETC/HTTPD/CONF/HTTPPASSWD"
Require Valid-user
Apache Basic Deployment