Magelinux (0111)

Source: Internet
Author: User
Tags aliases expression engine keep alive

Web Service

Application layer: HTTP, HTTPS implementation of a specific type of application:


Transport Layer Protocol: TCP, UDP, SCTP

Iana:
0-1023: It is well known that the privileged port is permanently assigned to a fixed application;
1024-41951: Also for the registration port, but the requirements are not particularly strict, assigned to the program to register for the use of an application; 3306/tcp, 11211/tcp;
41952+: The client program uses a random port, a dynamic port, or a private port; its scope is defined in/proc/sys/net/ipv4/ip_local_port_range;

An implementation of BSD SOCKET:IPC that allows communication between processes located on different hosts (or the same host);
Socket API (encapsulates the system calls related to socket communication in the kernel)
SOCK_STREAM:TCP sockets
SOCK_DGRAM:UDP sockets
Sock_raw:raw set by word

Socket Domain According to the address format used by the socket:
Af_inet:address Family,ipv4
Af_inet6:ipv6
Af_unix: An address used by a socket socket communication between different processes on the same host; Unix_sock

TCP fsm:closed, Listen,syn_sent, SYN_RECV, established, Fin_wait1, close_wait, Fin_wait2, Last_ack, TIMEWAIT, CLOSED

Features of the TCP protocol:
Establish connection: three handshake;
Package data into segments: checksum (CRC32)
Confirmation, retransmission and timeouts;
Sort: logical Sequence number;
Flow control: Sliding window algorithm;
Congestion control: Slow start and congestion avoidance algorithm;

Http:hyper Text Transfer Protocol, Application layer protocol, 80/TCP, text protocol
Html:hyper text Mark language, programming language, Hypertext Markup language;

<title>TITLE</title>
<body>
<p> blabla <a href= "http://www.magedu.com/download.html" > Bla ... </a> </p>
</body>

Css:cascading Style Sheet
Js:javascript, client-side scripting;

Protocol version:
http/0.9: Prototype version, simple functionality
Http/1.0:cache, MIME, method,
Mime:multipurpose Internet Mail extesion
Method:get, POST, Head,put, Delete,trace, OPTIONS
http/1.1: Enhanced cache function;
Spdy
http/2.0:
Rfc

Operating mode:
HTTP request message: HTTP requests
HTTP Response message: HTTP response
One HTTP transaction: request <--> response

Web Resources: Web Resource
Static resources (no additional processing by the server):. jpg,. png,. gif,. html, TXT,. js,. css,. mp3,. avi
Dynamic resources (the service side needs to be processed by the execution program, sent to the client is the result of the program running):. PHP,. jsp

Note: There may be multiple resources displayed on one page, and each resource requires a separate request;

Identification mechanism of the resource: URL
Uniform Resource Locator: A location used to describe a particular resource of a server;
Example: http://www.sina.com.cn/index.html
scheme://server[:P Ort][/path/to/some_resource]

A complete HTTP request processing process:
(1) Establishing or processing connections: receiving requests or refusing requests;
(2) Receiving request: The process of receiving a request for a particular resource from a host request packet on the network;
(3) Processing request: To parse the request message, to obtain the resources requested by the client and the request method and other relevant information;
(4) Access to resources: To obtain the requested resources in the request message;
(5) Build the response message:
(6) Send the response message:
(7) Logging:

The model that receives the request:
Concurrent Access Response Model:
Single-process I/O Model: Initiates a process to process user requests; This means that only one request can be processed at a time, and multiple requests are serially responded to;
Multi-process I/O structure: Start multiple processes in parallel, each responding to a request;
multiplexed I/O structure: a process responds to n requests;
Multithreaded mode: A process generates n threads, and a thread processes a request;
Event-Driven (Event-driven): a process directly n requests;
Multiplexed multi-process I/O structure: Starts multiple (m) processes, each generating (n) threads;
Number of requests in response: M*n

Processing requests: HTTP request packet header for parsing request messages
HTTP protocol:
HTTP Request message Header
HTTP Response message Header

The format of the header of the request message:
<method> <URL> <VERSION>
HEADERS: (Name:value)
<request body>

Access resource: Gets the requested resource in the request message

A Web server, a host of web resources, that provides the requestor with a static resource requested by the other, or the result of a dynamic resource run, which should normally be placed under a path on the local file system; This path is called docroot;

If the RPM package is installed, the default location is/var/www/html/: This can be changed in the configuration file
Images/logo.jgp

Http://www.magedu.com/images/logo.jpg

How to map the Web server's resource path:
(a) Docroot
(b) Alias
(c) Docroot of the virtual host
(d) Docroot of the user's home directory

Connection mode in HTTP request processing:
Keep connected (long connection): Keep-alive
Time:
Number:
Non-hold connection (short connection):

Three times the handshake is the first time the client requests the connection, the second server side corresponds and requests the connection, and the third client request. Four times the wave is the first client request, the second server-side response, the third server-side request, and the fourth client response. The second handshake is to combine the request and response, and four times the wave is separated, and some servers will block in the second server response this phase, is not want to break up, do not want to disconnect, to ensure that if the client in the process of request disconnection request data, you can also transfer data, no need to re-establish the connection

A full connection does not necessarily send only one resource. This is called a short connection if you are spending a single connection on such a resource. For example, a Web page has 5 images, 5 images is 5 resources, customers to visit this page, it is necessary to go 5 times such a three times handshake-transfer data-4 This wave of the process.

There is also a pattern called a long connection, or a Keep-alive connection (keep alive), such as a single connection can send up to 5 resources, or can hold a maximum of a few seconds, time is up, the connection is broken. The first one says the scene is actually like this. Model HTTP Server program: httpd (Apache) nginxlighttp

Application Server:
IIS:. Net
Tomcat:. JSP

www.netcraft.com

Installation and use of httpd:
Asf:apache Software Foundation
Httpd:apache
A patchy server = Apache
httpd

Features of the httpd:
Highly modular: Core + modules
Dso:dynamic Shared Object
Mpm:multipath processing Modules (multi-path processing module)
Prefork: A multi-process model in which each process responds to a request;
A main process: responsible for generating sub-processes and recycling child processes, responsible for creating sockets, responsible for receiving requests, and distributing them to a sub-process for processing;
N Child processes: Each child process processes a request;
Working model: Several idle processes are pre-generated, ready to be used in response to user requests, maximum idle and minimum idle;
Worker: Multi-process multithreaded model with one user request per thread;
A main process: responsible for generating child processes, responsible for creating sockets, responsible for receiving requests, and distributing them to a sub-process for processing;
Multiple child processes: Each child process is responsible for generating multiple threads;
Per thread: Responsible for responding to user requests;
Number of concurrent responses: M*n
M: Number of child processes
N: The maximum number of threads that can be created per child process;

Event: Events-driven model, multi-process model, each process responds to multiple requests;
A main process: responsible for generating child processes, responsible for creating sockets, responsible for receiving requests, and distributing them to a sub-process for processing;
Child process: Respond to multiple requests directly based on the event-driven mechanism;
httpd-2.2: The model is still used for testing;
Httpd-2.4:event can be used in production environment;

HTTPD version of the program:
HTTPD 1.3: Official has ceased maintenance;
HTTPD 2.0:
HTTPD 2.2:
HTTPD 2.4: Currently the latest stable version;

HTTPD Features:
Cgi:common Gateway Interface
Virtual Host: Ip,port, FQDN
Reverse Proxy
Load Balancing
Path aliases
A rich user authentication mechanism
Basic
Digest
Support for third-party modules
......

Install httpd:
RPM Package: Available directly from the CentOS release;
Compile and install: Customize new features, or other reasons;

CentOS 6:httpd-2.2 (support for MPM dynamic switching is not supported)
Program Environment:
Configuration file:
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf
Service script:
/etc/rc.d/init.d/httpd
Script configuration file:/etc/sysconfig/httpd
Main Program Files:
/usr/sbin/httpd
/usr/sbin/httpd.event
/usr/sbin/httpd.worker
Log file:
/VAR/LOG/HTTPD:
Access_log: Access Log
Error_log: Error Log
Site Documentation:
/var/www/html
Module file path:
/usr/lib64/httpd/modules

Service Control and Startup:
Chkconfig httpd On|off
Service {Start|stop|restart|status|configtest|reload} httpd

CentOS 7:httpd-2.4
Program Environment:
Configuration file:
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf
Module-related configuration files:/etc/httpd/conf.modules.d/*.conf
SYSTEMD Unit File:
/usr/lib/systemd/system/httpd.service
Main Program Files:
/usr/sbin/httpd
httpd-2.4 supports MPM dynamic switching;
Log file:
/VAR/LOG/HTTPD:
Access_log: Access Log
Error_log: Error Log
Site Documentation:
/var/www/html
Module file path:
/usr/lib64/httpd/modules

Service Control:
Systemctl enable|disable Httpd.service
Systemctl {Start|stop|restart|status} httpd.service


0111-3
Review:
Concurrent Service Response Model:
Single process model;
Multi-process model;
The model of multiplexed I/O;
Multithreaded mode
Event-driven;
Multi-process multithreading model for multiplexing

Mpm:
Prefork: A multi-process model in which a process responds to a request;
Worker: Multi-process multithreaded model, a thread responds to a request;
Event: Incident-driven model, a process responding to n requests;

Web Service (2)

Common configurations for httpd-2.2

The master profile is divided into three paragraphs, where the second and third paragraphs can only have one entry into effect:/etc/httpd/conf/httpd.conf
# # # Section 1:global Environment (Global environment)
# # # 2: ' Main ' Server configuration (central host)
# # # section 3:virtual hosts (virtual host)

Configuration format:
Directive value
Directive (Configuration Directive): Character case insensitive;
Value: When the path is case-sensitive, it is dependent on the file system;

Common configuration:
1, modify the listening IP and port
Listen [Ip:]port

(1) The omitted IP is represented as 0.0.0.0;
(2) Listen instructions can be repeated multiple times;
Listen 80
Listen 8080
(3) Modify the listening socket, restart the service process to take effect;

2. Persistent continuous
Persistent CONNECTION:TCP after successive establishment, each resource gets completed not completely disconnected, but continues to wait for other resource requests to proceed;
How to disconnect?
Quantity limit
Time limit

Side effects: For servers with a large number of concurrent accesses, the long connection mechanism causes some subsequent requests not to get normal response;
Tradeoff: Use shorter persistent connection lengths, and fewer requests;

KeepAlive on| Off
KeepAliveTimeout 15
Maxkeepaliverequests 100

Test:
Telnet web_server_ip PORT
Get/url http/1.1
Host:web_server_ip
Enter the above after continuous input two times



If it is a short connection, it will be disconnected immediately after acquiring a resource, and if it is a long connection, it will not be disconnected immediately, only after the quantity or time limit.

3. MPM

httpd-2.2 does not support compiling multiple MPM modules at the same time, so only the one selected to use is compiled, and the CentOS 6 RPM package specifically provides three application files, httpd (prefork), Httpd.worker, Httpd.event,

Used to implement support for different MPM mechanisms; Verify which program file is being used now:
PS aux | grep httpd

You can see the prefork mode, and just open the opportunity to start eight sub-processes

The default is/USR/SBIN/HTTPD, which is the MPM module of Prefork;
To view a list of modules for the HTTPD program:
To view statically compiled modules:
# httpd-l
To view statically compiled and dynamically compiled modules:
# httpd-m

Replace the use of the HTTPD program to support other MPM mechanisms;
Edit Script configuration file/etc/sysconfig/httpd
Httpd=/usr/sbin/httpd. {Worker,event}



Note: Restarting the service process will take effect
For Linux, the performance gains from using threading mode instead of process mode are very limited, which is to replace prefork with worker
For CENTOS6 apache2.2, the event is a test phase and is not recommended for use in production environments

MPM configuration: In the master configuration file
Configuration of the Prefork
<ifmodule prefork.c>
Startservers 8
Minspareservers 5
Maxspareservers 20
Serverlimit 256
MaxClients 256
Maxrequestsperchild 4000
</IfModule>


In this configuration file, Maxrequestsperchild is 4000 to indicate that a process can handle up to 4,000 requests, processing to an explicit
Must be destroyed
MaxClients can be understood as the maximum number of concurrent (maximum requests), Serverlimit is the most process, so serverlimit is greater than or equal to Max
Clients
PV and UV. PV is the number of page visits
Suppose a process can send 5 resources a second, then 256 is 1280, that is, a server can send 1280 resources a second, and assume a page
With 100 resources, the server can support a maximum of 12.8 PV per second


Configuration of the worker:
<ifmodule worker.c>
Startservers 4
MaxClients 300
Minsparethreads 25
Maxsparethreads 75
Threadsperchild 25
Maxrequestsperchild 0
</IfModule>
In this configuration file, Maxrequestsperchild is 0 for infinity, which means that a thread can handle requests without being destroyed.

In both the worker and Prefork modes, there is only one main process running as root, which is responsible for assigning the received requests
To a child process or thread, while a thread or process is running as Apache. The startserver in both configurations refer to sub-processes,
Above this worker mode server will open 4 sub-processes, each child process started 25 threads (Threadsperchild) and then started
100 threads, but he configured the maxsparethreads to 75, this is the maximum idle thread, so cut off a sub-process, that is, just started with three
Child process. Why this match, Marco also express difficult to understand
Pv,uv
Pv:page View
Uv:user View

4. DSO
Configuration Directives Implement module loading
LoadModule <mod_name> <mod_path>

The module file path can use relative paths:
Relative to ServerRoot (default/etc/httpd)

5. Define the document page path for ' Main ' server
DocumentRoot ""

Document PATH Mapping:
The path that Doucmentroot points to is the starting position of the URL path
It is equivalent to the root path of the site URL;

(FileSystem)/web/host1/index.html---(URL)/index.html

6. Site access Control common mechanism

There are two mechanisms to indicate what access control to which resources, one is the file system path, and the other is the URL path

File system path:
<directory "" > (for Catalogs)
...
</Directory>

<file "" > (for individual files)
...
</File>

<filematch "PATTERN" > (regular Expression) (but to make this configuration file effective requires an extra
Start the regular expression engine, which is less efficient
Matches the normal character. So you can use this without this.
...
</FileMatch>

URL path:
<location "" >
...
</Location>

<locationmatch "" >
...
</LocationMatch>

<Directory> "Source-based address" for access control:
(1) Options
followed by 1 or more "options" lists separated by a blank character;
Indexes: The index list is returned to the user when a resource file corresponding to the defined master page resource does not exist under the specified URL path;
FollowSymLinks: Allows tracing of the source file pointed to by the symbolic link file;
None:
All:

(2) allowoverride (this is not used)
Which directives related to access control can be placed in the. htaccess file (each directory can have one);
All:
None:

(3) Order and allow, deny
Order: Define the order of entry, and write the default rule in the following notation;

Allow from, Deny from
Source Address:
The following formats are both legitimate and have the same effect:
172.16
172.16.0.0
172.16.0.0/16
172.16.0.0/255.255.0.0

7, define the site Main page:
DirectoryIndex index.html Index.html.var

8. Define Path aliases
Format:
alias/url/"/path/to/somedir/"

DocumentRoot "/www/htdocs"
http://www.magedu.com/download/bash-4.4.2-3.el6.x86_64.rpm
/www/htdocs/download/bash-4.4.2-3.el6.x86_64.rpm

alias/download/"/rpms/pub/"
If the above aliases are set, access the HTTP://WWW.MAGEDU.COM/DOWNLOAD/BASH-4.4.2-3.EL6.X86_64.RPM
You'll jump to/rpms/pub/bash-4.4.2-3.el6.x86_64.rpm.


9. Set the default character set
Adddefaultcharset UTF-8

Chinese character set: GBK, GB2312, GB18030

10. Log Settings
Log type: Access log and error log

Magelinux (0111)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.