In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "what is the difference in load balancing of LVS/Nginx/Haproxy". In daily operation, I believe that many people have doubts about the different problems of load balancing in LVS/Nginx/Haproxy. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful to answer the doubts about "what is the difference between load balancing in LVS/Nginx/Haproxy?" Next, please follow the editor to study!
Definition of load balancer:
Load balancing is composed of multiple servers in a symmetrical way to form a set of servers, each server has an equivalent status, and can provide services independently without the assistance of other servers. Through some kind of load sharing technology, the requests sent from the outside are evenly distributed to a server in the symmetrical structure, and the server that receives the request responds to the client's request independently. Load balancing can evenly distribute customer requests to the server array, so as to provide rapid access to important data and solve a large number of concurrent access service problems. This clustering technology can achieve performance close to that of mainframes with minimal investment. This technology can be used when the traffic is congested, the access path is too long, the number of netizens is greatly increased, running this system load, greatly improving the reliability of the system, load balancing technology to solve the problem of network congestion, deal with a large number of concurrent access service capacity, improve the response speed of the server, and provide users with better access quality. Therefore, load balancing is an intelligent, high-performance and flexible technology.
Design ideas:
The processing capacity of an ordinary server can only reach tens of thousands to hundreds of thousands of requests per second, and can not process millions or more requests in a second. However, if multiple such servers can be formed into a system, and all requests are evenly distributed to all servers through related technologies, then the system will have the ability to handle millions or more requests per second. This is the original basic design idea of load balancing.
Several implementation techniques of load balancing:
Http redirection: when a http agent (such as a browser) requests a URL from the web server, the web server can return a new URL through the Location tag in the http response header information. This means that the HTTP agent needs to continue to request the new URL to complete the automatic jump.
DNS load balancing: this is also the earliest load balancing technology. In the DNS load balancing server, one of the addresses can be obtained by using the same name for different addresses and visiting different WEB servers for customers with different names, so as to achieve the purpose of load balancing. DNS load balancing cannot distinguish between servers.
Proxy load balancer: when ordinary users access the Web service (actually accessing the reverse proxy load balancer), they reverse the proxy load balancer, and then forward the request to multiple internal Web servers. In this way, external access requests are loaded to multiple internal Web servers according to the configuration policy, so as to achieve the purpose of load balancing.
Internal address external address translation load balancing: mapping external IP addresses to multiple internal addresses, address translation network management uniformly translates different internal server addresses for each connection, and then external computers connect with servers with their own translated addresses to achieve the purpose of load sharing.
Hardware load balancing: for example, F5 and Cisco will have hardware load balancers to handle the request load. But the price is relatively high.
Layer-4 vs layer-7 load balancer:
① 's so-called layer 4 is load balancer based on IP+ port; layer 7 is load balancer based on application layer information such as URL; similarly, there are layer 2 load balancer based on MAC address and layer 3 load balancer based on IP address. In other words, layer 2 cloud load balancer receives requests through a virtual MAC address and then assigns them to the real MAC address; layer 3 load balancer receives requests through a virtual IP address and then assigns them to the real IP address; layer 4 receives requests through the virtual IP+ port and then distributes them to the real server; layer 7 receives the request through the virtual URL or hostname and then distributes it to the real server.
② 's so-called layer 4 to layer 7 load balancing is to decide how to forward traffic according to the information of layer 4 or layer 7 when load balancing the backend server. For example, layer-4 load balancer publishes layer-3 IP addresses (VIP), and then adds layer-4 port numbers to determine which traffic needs to be balanced, NAT processes the traffic to be processed, forwards it to the backend server, and records which server handles the traffic of this TCP or UDP, and all traffic from this connection is also forwarded to the same server for processing. Layer-7 load balancer is based on layer-4 (without layer-4, there can be no layer-7), and then consider the characteristics of the application layer, such as the load balancer of the same Web server. In addition to identifying the traffic to be processed by VIP plus port 80, you can also decide whether to carry out load balancing based on the URL, browser category and language of layer 7. For example, if your Web server is divided into two groups, one in Chinese and the other in English, then layer-7 load balancer can automatically identify the user's language when users come to access your domain name, and then select the corresponding language server group for load balancing.
③ load balancers are commonly referred to as layer 4 switches or layer 7 switches. Layer 4 switch mainly analyzes IP layer and TCP/UDP layer to achieve layer 4 traffic load balancing. In addition to supporting layer 4 load balancing, layer 7 switches also analyze application layer information, such as HTTP protocol URI or Cookie information.
Comparison of three mainstream software load balancers (LVS VS Nginx VS Haproxy)
LVS: 1. Strong anti-load ability. It has strong load resistance and high performance, which can reach 60% of F5 hardware. It consumes relatively low memory and cpu resources. 2, it works at layer 4 of the network and is forwarded through vrrp protocol (for distribution only). The specific traffic is handled by the linux kernel, so no traffic is generated. 2. Good stability and reliability, and has a perfect hot backup scheme. (e.g. LVS+Keepalived) 3. It has a wide range of applications and can do load balancing for all applications. 4. It does not support regular processing and cannot do static and dynamic separation. 5. Support load balancing algorithms: rr (Round Robin), wrr (weighted Round Robin), lc (minimum connection), wlc (minimum weight connection) 6. Configuration is complex, network dependence is large, and stability is high.
Ngnix:1, working above the 7 layers of the network, can make some diversion strategies for http applications, such as domain name and directory structure. 2. Nginx is less dependent on the network and can theoretically carry out load functions as soon as it can communicate with ping. 3. Nginx is relatively simple to install and configure and convenient to test. 4. It can also bear high load pressure and stable, generally supporting more than 10, 000 concurrency. 5. For health check of backend servers, you can only check through port, not url. 6. Nginx's asynchronous processing of requests can help node servers lighten the load; 7. Nginx can only support http, https and Email protocols, so it is less applicable. 8. Direct retention of Session is not supported, but it can be solved through ip_hash. Support for Big request header is not very good. 9. Support load balancing algorithms: Round-robin (round robin), Weight-round-robin (weighted round robin), Ip-hash (Ip hash)
The characteristics of HAProxy are: 1, support two proxy modes: TCP (layer 4) and HTTP (layer 7), support virtual host; 2, be able to supplement some shortcomings of Nginx, such as Session maintenance, Cookie boot and other work 3, support url detection back-end server problem detection will be very helpful. 4. More load balancing strategies such as dynamic weighted Round Robin (Dynamic Round Robin), weighted Source address Hash (Weighted Source Hash), weighted URL Hash and weighted Parameter Hash (Weighted Parameter Hash) have been implemented. 5. In terms of efficiency, HAProxy will have better load balancing speed than Nginx. 6. HAProxy can load balance the Mysql, detect and load balance the DB nodes at the back end. 9. Support load balancing algorithms: Round-robin (round robin), Weight-round-robin (weighted round robin), source (original address retention), RI (request URL), rdp-cookie (according to cookie)
The three mainstream software load balancers are suitable for business scenarios:
1. At the beginning of website construction, Nigix/HAproxy can be selected as reverse proxy load balancer (or load balancer can not be selected for most of the traffic), because its configuration is simple and its performance can meet general business scenarios. If you consider that the load balancer has a single point problem, you can use Nginx+Keepalived/HAproxy+Keepalived to avoid the single point problem of the load balancer itself. 2. After website concurrency reaches a certain degree, LVS can be used to improve stability and forwarding efficiency. After all, LVS is more stable than Nginx/HAproxy, and the forwarding efficiency is also higher. However, the maintenance of LVS will have higher requirements for maintenance personnel and higher input costs. Note: compared with Haproxy, Niginx supports seven layers, has the largest number of users and is more reliable in stability. Haproxy supports layer 4 and layer 7, supports more load balancing algorithms, and supports session storage. Specific selection depends on the usage scenario. At present, the number of users of Haproxy is also increasing because it makes up for some shortcomings of Niginx.
At this point, the study on "what is the difference in load balancing of LVS/Nginx/Haproxy" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.