Four layer load balancing: Only onceTCP Connect

Seven layer load balancing: The load balancer and the client and the back-end server will establish aTCP Connect. That is the two time.TCP Connect.

( One)

   Simple understanding of four and seven layer load balancing:

  ①  The so-called four layers are based onIP+ Load balancing of ports; The seventh level is based onURL Load balancing of application layer information; Empathy, Also based onMAC Address based load balancing in two layersIP Three layer load balancing of address.
In other words, The second level load balancing will pass a virtualMAC Address receive request, And then reallocate it to the realMAC address; The three-tier load balancing will pass a virtualIP Address receive request, And then reallocate it to the realIP address; Four layers through virtualIP+ Port receive request, And then it's distributed to the real server; Seven layers through virtualURL Or host name receive request, And then it's distributed to the real server.

  ②  So called four to seven layer load balancing, That is, when load balancing the servers in the background, Decide how to forward traffic according to the information of four layers or seven layers.
For example, load balancing of four layers, Through the release of three layersIP address(VIP), Then add the port number of the fourth floor, To determine which traffic needs to be load balanced, For the flow to be processedNAT Handle, Forward to background server, And record thisTCP perhapsUDP Which server handles the traffic of, All subsequent traffic of this connection is also forwarded to the same server for processing. Seven layer load balancing, On the basis of the fourth floor( It's impossible to have seven floors without four), Consider the characteristics of application layer again, Like the sameWeb Load balancing of servers, In addition toVIP plus80 Port identifying traffic to be processed, According to theURL, Browser category, Language to decide whether to load balance. For instance, If yourWeb Servers are divided into two groups, One is in Chinese, One is in English, Then seven layer load balancing can be used when users access your domain name, Automatic identification of user language, Then select the corresponding language server group for load balancing.

Load balancers are often referred to as layer 4 switches or layer 7 switches. Main analysis of layer 4 switchIP Layer andTCP/UDP layer, Realize four layers of traffic load balancing. In addition to supporting layer 4 load balancing, layer 7 switch, And analyze the information of the application layer, asHTTP AgreementURI orCookie information.

  1, Load balancing is divided intoL4 switch( Four level switching), That is, inOSI The first4 Layer work, NamelyTCP Layer. SuchLoad
Balance Do not understand the application protocol( asHTTP/FTP/MySQL Wait). Example:LVS,F5.

  2, The other is calledL7 switch( Seven level switching),OSI The highest level, application layer. here, TheLoad Balancer Understand application protocol. Example:
 haproxy,MySQL Proxy.

   Be careful: A lot of themLoad Balancer We can do four layer exchange, You can also do a seven level exchange.

  ( Two)

   Load balancing devices are also known as" Four to seven layer switch", So what's the difference between the four and seven floors?

   first, Differences in technical principles.

   So called four layer load balancing, That is, it mainly passes through the destination address and port in the message, Plus the server selection mode set by the load balancing device, Determine the internal server of final choice.

   In commonTCP take as an example, The load balancer receives the firstSYN
Request time, Select the best server in the above way, And to the target in the messageIP Address modification( Change to back-end serverIP), Forward directly to this server.TCP Connection establishment of, That is, the three-way handshake is directly established by the client and the server, The load balancer just acts like a router. In some deployment cases, In order to ensure that the packet returned by the server can be returned to the load balancing device correctly, At the same time of forwarding the message, the original source address of the message may be modified.

   So called seven layer load balancing, also known as“ Content exchange”, That is to say, it mainly passes through the real meaningful application layer content in the message, Plus the server selection mode set by the load balancing device, Determine the internal server of final choice.

   In commonTCP take as an example, If the load balancing device chooses the server according to the real application layer content, You can only proxy the final server and client to establish a connection first( The three handshake) after, It is possible to receive the real application layer content message sent by the client, Then according to the specific field in the message, Plus the server selection mode set by the load balancing device, Determine the internal server of final choice. Load balancing equipment in this case, More like a proxy server. Load balancing and front-end clients and back-end servers will be established respectivelyTCP Connect. So in terms of the technical principle, Seven layer load balancing obviously requires higher load balancing equipment, The ability to handle layer 7 is also bound to be lower than the deployment mode of layer 4.

   Second, Requirements of application scenarios.

   Benefits of seven tier application load, Is to make the whole network more" Intellectualization
". For example, the traffic of users visiting a website, It can be done in seven layers, Forward requests for picture classes to specific picture servers and use caching technology; Requests for text classes can be forwarded to specific text servers and compression techniques can be used. Of course, this is just a small case of seven tier application, In terms of technical principle, In this way, the client's request and the server's response can be modified in any sense, Greatly improved the flexibility of the application system in the network layer. Many in the background, for exampleNginx perhapsApache The function of the upper deployment can be moved forward to the load balancing device, For example, theHeader Rewrite, Keyword filtering or content insertion in server response.

   Another feature that is often mentioned is security. The most commonSYN
Flood attack, That is, hackers control many source clients, Use falsehoodIP Address to same destinationSYN attack, Usually this kind of attack will send a lotSYN message, Exhaustion of related resources on the server, In order to achieveDenial
of Service(DoS
) Purpose. It can also be seen from the technical principle, In four tier mode, theseSYN Attacks will be forwarded to back-end servers; And in the 7-tier modeSYN Attacks naturally end on load balancing devices, It will not affect the normal operation of the background server. In addition, the load balancing equipment can set various strategies at the seven levels, Filter specific messages, for exampleSQL Injection Specific attack means at application level, Further improve the overall security of the system from the application level.

   Current7 Layer load balancing, Mainly focus on ApplicationHTTP Agreement, So its application scope is mainly based on many websites or internal information platformsB/S Developed system.
4 Layer load balancing corresponds to otherTCP application, For example, based onC/S DevelopedERP Other systems.

   Third, Problems to be considered in 7-tier application.

  1: Is it really necessary
, Seven layer application can really improve traffic intelligence, At the same time, it inevitably brings complex equipment configuration, The increase of load balancing pressure and the complexity of troubleshooting. In the design of the system, it is necessary to consider the hybrid situation of simultaneous application of four layers and seven layers.

  2: Does it really improve security. for exampleSYN
Flood attack, The layer 7 model does shield these traffic from the server, But load balancing equipment itself should have strong resistanceDDoS ability, Otherwise, even if the server is normal and the load balancing device as the central scheduling fails, the whole application will crash.

  3: Is there enough flexibility
. The advantage of seven layer application is that it can make the traffic of the whole application intelligent, But load balancing equipment needs to provide perfect seven layer function, Meet customer's application-based scheduling according to different situations. The simplest assessment is whether it can replace the backstageNginx perhapsApache Wait for the scheduling function on the server. A load balancing device that can provide a seven layer application development interface, It allows customers to set functions according to their needs, It's really possible to provide strong flexibility and intelligence.

  ( This section is from “ADC Technology blog” Blog, Be sure to keep this source

  ( Three)

   Introduction of load balancing layer 4 and 7:

   load balancing(Load
Balance) Build on existing network structure, It provides a cheap, efficient and transparent way to expand the bandwidth of network devices and servers, Increase throughput, Strengthen network data processing capacity, Improve network flexibility and availability.

   Load balancing has two meanings: First, A large number of concurrent accesses or data flows are shared to multiple node devices for separate processing, Reduce user waiting time for response; Secondly, Single heavy load operation is shared to multiple node devices for parallel processing, After each node device processing, Summarize results, Return to user, The processing capacity of the system has been greatly improved.

   The load balancing technology introduced in this paper mainly refers to the application of balancing the traffic load between all servers and applications in the server cluster, At present, most of the load balancing technologies are used to improve the performance ofWeb The server,FTP On servers and other mission critical serversInternet Availability and scalability of server programs.

   Classification of load balancing technology

   At present, there are many different load balancing technologies to meet different application needs, The following equipment objects are used for load balancing, Network level of application( fingerOSI reference model) And applied geographical structure to classify.

   soft/ Hardware load balancing

   Software load balancing solution is to install one or more additional software on the corresponding operating system of one or more servers to achieve load balancing, asDNS Load
Balance,CheckPoint Firewall-1
ConnectControl etc. Its advantage is based on specific environment, Simple configuration, Flexible use, Low cost, Can meet the general load balancing needs.

   Software solutions have many disadvantages, Because installing additional software on each server will consume the system's unlimited resources, More powerful modules, More consumption, So when the connection request is very large, Software itself will be a key to the success of server work; Software scalability is not very good, Limited by operating system; Because of theBug, Often causes safety problems.

   The solution of hardware load balancing is to install load balancing equipment directly between server and external network, This kind of equipment is usually called load balancer, Because of special equipment to complete special tasks, Operating system independent, The overall performance has been greatly improved, Plus a variety of load balancing strategies, Intelligent traffic management, To achieve the best load balancing requirements. 

   Load balancers come in many forms, In addition to being a load balancer in an independent sense, Some load balancers are integrated in switching devices, Placed on server andInternet Link between, Some use two network adapters to integrate this function intoPC in, One piece connected toInternet upper, Connect to the internal network of back-end server cluster.

   generally speaking, Hardware load balancing in function, Better performance than software, But it's expensive.

   local/ Global load balancing

   Load balancing is divided into local load balancing according to the geographical structure of its application(Local Load Balance) And global load balancing(Global Load
Balance, Also called regional load balancing), Local load balancing refers to load balancing the local server group, Global load balancing refers to the geographical location, Load balancing among servers with different network structures.

   Local load balancing can effectively solve the problem of excessive data flow, The problem of network overload, And you don't have to spend a lot of money on high-performance servers, Make full use of existing equipment, Avoid data traffic loss caused by server single point failure. It has flexible and diverse equalization strategies to distribute data traffic reasonably to the servers in the server cluster. Even expand and upgrade existing servers, Simply add a new server到服务群中,而不需改变现有网络结构,停止现有的服务. 






IP,Virtual IP








  在实际应用中,我们可能不想仅仅是把客户端的服务请求平均地分配给内部服务器,而不管服务器是否宕机.而是想使Pentium III服务器比Pentium





  权重轮循均衡(Weighted Round


  权重随机均衡(Weighted Random):此种均衡算法类似于权重轮循算法,不过在处理请求分担时是个随机选择的过程.








  HTTP URL侦测:比如向HTTP服务器发出一个对main.html文件的访问请求,如果收到错误信息,则认为服务器出现故障.


  还有一种路径外返回模式(Out of Path









User Interfaces),有基于普通web页的管理,也有通过Java Applet
进行安全管理,一般都需要管理端安装有某个版本的浏览器;三,SNMP(Simple Network Management