Simple understanding of the difference between four-and seven-layer load balancing

Source: Internet
Author: User

First of all, we are talking about the four-story, seven-story, we all know our network Seven Layer Protocol (OSI): 7: Application layer, 6: Presentation layer, 5: Session layer, 4: Transport layer, 3: Network layer, 2: Data link layer, 1: physical layer.

application tier (Application layer)

An application that communicates with other computers, which is the communication service of the corresponding application. For example, a word processor without a communication function would not be able to execute the code of communication, and the programmer working on the word processing did not care about the 7th layer of the OSI. However, if you add an option to transfer files, the programmer of the word processor will need to implement the 7th layer of the OSI. Example: Telnet,http,ftp,nfs,smtp and so on.

presentation layers (Presentation layer)

The primary function of this layer is to define the data format and encryption. For example, FTP allows you to choose to transfer in either binary or ASCII format. If binary is selected, the sender and receiver do not change the contents of the file. If you select ASCII format, the sender converts the text from the sender's character set to the standard ASCII and sends the data. Converts standard ASCII to the receiver computer's character set on the receiver side. Example: Encryption, ASCII, and so on.

Session Layer

It defines how to start, control, and end a session, including control and management of multiple two-way messages, so that the app can be notified when only part of a continuous message is completed, so that the data that the presentation layer sees is continuous, and in some cases, data represents the presentation layer if all the data is received by the presentation layer. Example: Rpc,sql and so on.

The Transport layer (Transport layer)

The functionality of this layer includes whether to choose the error recovery protocol or the error-free recovery protocol, and to reuse the input of data streams from different applications on the same host, as well as the reordering of packets that are not received in the wrong order. Example: Tcp,udp,spx.

Network Layer

This layer defines the end-to-end package transport, which defines the logical addresses that identify all nodes, and defines how and how the routes are implemented. To accommodate transmission media with a maximum transmission unit length of less than the packet length, the network layer also defines a segmentation method that decomposes a packet into smaller packets. Example: Ip,ipx and so on.

Data Link Layer

It defines how data is transferred on a single link. These protocols are related to the various media being discussed. Example: Atm,fddi and so on.

Physical layers (physical layer)

The OSI Physical layer specification is a characteristic standard for transmission media that is often referenced by other organizations ' standards. Connection head, frame, frame use, current, encoding and light modulation are all the contents of various physical layer specifications. The physical layer often uses multiple specifications to complete the definition of all the details. Example: rj45,802.3 and so on.

After a brief look at the network protocol seven-tier structure, we looked at four-layer and seven-tier load balancing in a nutshell.

Name implies:

L4 switch (quad Exchange) load balancing: The fourth layer of the OSI is the transport layer. That is, load balancing based on the ip+ port, such as Lvs,f5. There are also two-tier load balancers based on MAC addresses and three-tier load balancing based on IP addresses. In other words, a two-tier load balancer receives requests through a virtual MAC address and assigns them to a true MAC address; three-tier load balancing receives requests through a virtual IP address and then assigns them to a real IP address, and the four tiers receive the request through a virtual ip+ port before being assigned to the real server Layer seven receives the request through a virtual URL or hostname and then assigns it to the real server.

L7 switch (seven-layer switching) Load balancing: OSI's highest layer, application layer. such as Haproxy,mysql Proxy. Load balancing based on application layer information such as URLs.

The so-called four or seven-layer load balancing, is in the background of the server load balancing, based on the four layer of information or seven layers of information to determine how to forward traffic. For example, four layer of load balancing, is to publish three layer of IP address (VIP), and then add four layer of port number, to determine which traffic needs to do load balancing, to handle the traffic to the NAT processing, forwarding to the background server, and record the TCP or UDP traffic is from which server processing, All subsequent traffic for this connection is also forwarded to the same server for processing. Seven layer of load balancing, is on the basis of four layer (no four layer is absolutely impossible seven layer), and then consider the characteristics of the application layer, than like a Web server load balancing, in addition to the VIP plus 80 port to identify whether to handle traffic, but also according to the seven layer of the URL, browser category, Language to determine whether to load balance. For example, if your Web server is divided into two groups, one for the Chinese language and one for the English language, the seven-tier load balancer can automatically identify the user's language when the user accesses your domain name, and then select the corresponding language server group for load Balancing.

A load balancer is often referred to as a four-layer switch or a seven-layer switch. The four-layer switch mainly analyzes the IP layer and the TCP/UDP layer to achieve four-layer traffic load balancing. In addition to supporting four-tier load balancing, layer seven switches also analyze application layer information, such as HTTP protocol URI or cookie information.


first, the technical principle of the difference.

The so-called four-layer load balancing , that is, mainly through the message of the destination address and port, coupled with the load Balancer device settings of the server selection method, determine the final choice of internal server.

In the case of common TCP, the load balancer device, when it receives the first SYN request from the client, chooses the best server in the above way and modifies the destination IP address in the message (instead of the backend server IP) and forwards it directly to the server. TCP connection is established, that is, the three-time handshake is established directly between the client and the server, the load balancer device is just a router-like forwarding action. In some deployment situations, in order to ensure that the server back-up can be correctly returned to the load balancer device, while forwarding the message may also be the original source address of the message to modify.

the Called seven-layer load balancing , also known as "content Exchange", that is, mainly through the message of the real meaningful application layer content, coupled with the load Balancer device settings of the server selection method, determine the final choice of internal server.

For example, in the case of TCP, the load balancing device can only accept the message of the real application layer content sent by the client after the server is selected by the actual application layer and then the client must establish a connection (three handshake), and then according to the specific fields in the message, Plus the server selection method of the Load Balancer device setting determines the final selected internal server. Load balancer device In this case, it is more like a proxy server. The load balancer and the front-end clients and the backend servers establish TCP connections separately. So from this point of view, the seven-layer load balancer is significantly more demanding for load balancing devices, and the ability to handle seven layers is bound to be lower than the four-tier mode deployment.

second, the needs of the application scenario.

The benefit of seven-tier application load is to make the whole network more " intelligent ". For example, access to a Web site user traffic, you can pass the request of the picture class to a specific image server through seven layers, and can use the caching technology, the text class request can be forwarded to a specific word server and can use compression technology. Of course, this is only a small case of seven-tier application, from the technical principle, this way can be the client's request and the response of the server in any sense, greatly improved the application system in the network layer of flexibility. Many of the features deployed in the background, such as Nginx or Apache, can be moved forward to the load balancer device, such as header rewriting in customer requests, keyword filtering in server responses, or content insertion.

Another feature that is often referred to is security. The most common SYN flood attack in the network, that is, hackers control many source clients, using a false IP address to send SYN attacks to the same target, usually this kind of attack will send a large number of SYN packets, exhausted the relevant resources on the server to achieve denial of Service (DoS ) for the purpose. It can also be seen from the technical principle that these SYN attacks are forwarded to the backend server in the four-layer mode, whereas in the seven-tier mode these SYN attacks are naturally cut off on the load-balanced device without affecting the normal operation of the backend servers. In addition, the load Balancer device can set up various strategies at seven layers, filter specific messages, such as SQL injection and other application-level attack methods, and further improve the overall security of the system from the application level.

Now the 7-layer load balancing, mainly focus on the application of HTTP protocol, so its application is mainly a number of web sites or internal information platform, such as based on B/s development system. The 4-tier load balancer corresponds to other TCP applications, such as ERP systems based on C/s development.

Third, the seven-tier application needs to be considered.

1: Whether it is really necessary , seven-tier applications can indeed improve the flow of intelligence, but also must not avoid the complexity of equipment configuration, load balancing pressure, and troubleshooting problems. In the design of the system you need to consider the four-layer seven-layer simultaneous application of the mixed situation.

2: Is it really possible to improve security ? For example, a SYN flood attack, seven-tier mode does block these traffic from the server, but the load balancer device itself has a strong anti-DDoS capability, or even if the server is functioning as a central dispatch load Balancer device failure can cause the entire application to crash.

3: whether there is sufficient flexibility . The advantage of seven-tier applications is that the flow of the entire application can be intelligent, but the load balancing device needs to provide a complete seven-tier capability to meet the customer's application-based scheduling according to different situations. One of the simplest tests is the ability to replace the scheduler on a server such as a background nginx or Apache. A load balancing device capable of providing a seven-tier application development interface that allows the customer to arbitrarily set functions based on demand, is truly likely to provide great flexibility and intelligence.

Part excerpt from: http://kb.cnblogs.com/page/188170/

Simple understanding of the difference between four-and seven-layer load balancing

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.