1. What is layer-4 and layer-7 load balancing?
Layer-4 Server Load balancer is based on IP + port, and layer-7 Server Load balancer is based on URL and other application layer information.
Likewise, there are two-layer Server Load balancer Based on MAC addresses and three-layer Server Load balancer Based on IP addresses.
In other words, a layer-2 Server Load balancer receives requests through a virtual MAC address and distributes the requests to the real MAC address;
Layer-3 Server Load balancer receives requests through a virtual IP address and then distributes the requests to the real IP address;
Layer-4 requests are received through the virtual IP + port and then distributed to the real server;
Layer-7 requests are received through URLs or host names and then distributed to real servers.
2. What is the difference between layer-4 Server Load balancer and layer-7 Server Load balancer?
The so-called layer-4 Server Load balancer mainly uses the destination address and port in the packet,
In addition, the server selection method set by the Server Load balancer device determines the final internal server.
When receiving the first SYN request from the client, layer-4 SLB selects the best server
Modify the target IP address and port in the message (change to the backend server IP address and port) and forward the IP address and port to the server.
The TCP connection is established, that is, the three-way handshake is directly established between the client and the server,
The server Load balancer device only acts as a router-like forwarding action.
The so-called layer-7 load balancing, also known as content exchange, is mainly through the truly meaningful application layer content in the message,
In addition, the server selection method set by the Server Load balancer device determines the final internal server.
If you want to select a server based on the real application layer content, the Server Load balancer device can only proxy the final server and client
After a connection (three-way handshake) is established, messages of the real application layer content sent by the client can be received,
Then, based on the specific fields in the message and the server selection method set by the Server Load balancer device,
Decide the final internal server. In this case, the Server Load balancer device is more similar to a proxy server.
Server Load balancer and front-end clients and backend servers establish TCP connections respectively.
From this technical principle, layer-7 Server Load balancer obviously has higher requirements on Server Load balancer equipment,
The layer-7 processing capability must be lower than the layer-4 deployment mode.
3. Common Software Load Balancing Solutions
Layer-4 Server Load balancer stands for LVS and supports all applications above layer-4.
Layer-7 Server Load balancer is mostly based on HTTP reverse proxy, which indicates that the works include Nginx and HAProxy.
HAproxy also supports layer-4 load balancing.