Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Advantages and disadvantages of Nginx, HAProxy and LVS

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

First, Nginx advantages: 1, working on the network layer 7, you can do some diversion strategies for http applications, such as for domain names, directory structure, its formal rules are more powerful and flexible than HAProxy, so it is widely popular so far. 2. Nginx has little dependence on network stability, and can carry out load function if it can communicate with ping in theory. 3, Nginx installation and configuration is relatively simple, testing is also more convenient, basically can print out the error log. 4. It can bear high load pressure and is stable, and it can generally support tens of thousands of concurrent times when the hardware is not bad, and the load degree is smaller than that of LVS. 5. Nginx can detect the internal fault of the server through the port, such as the status code and timeout returned by the web page according to the server, and will resubmit the request that returns an error to another node. 6. Not only an excellent load balancer / reverse proxy software, but also a powerful Web application server. LNMP is also a very popular Web architecture in recent years, and it is also stable in a high-traffic environment. 7. It can be used as a middle-level reverse proxy. 8. Can be used as a static web page and picture server. 9. The Nginx community is active, there are many third-party modules, and related materials can be found everywhere on the Internet. Nginx general and HTTP requests and corresponding flowcharts:

Nginx disadvantages: 1, the scope of adaptation is small, can only support http, https, Email protocols. 2. For health check of backend servers, only port detection is supported, but url is not supported. For example, if a user is uploading a file, and the node handling the upload just fails during the upload process, Nginx will cut the upload to another server for re-processing, while the LVS will be cut off directly. If it is uploading a large file or a very important file, the user may be dissatisfied with this. Second, LVS advantages: 1, strong anti-load ability, is working on the network layer 4 only for distribution, no traffic generation, this characteristic also determines its strongest performance in the load balancing software, relatively low consumption of memory and cpu resources. 2, the configuration is relatively low, which is a disadvantage and an advantage, because there are no things that can be configured too much, so it does not need too much contact, which greatly reduces the probability of human error. 3. The work is stable because of its strong anti-load ability, and it has a complete dual-machine hot backup solution, such as LVS+Keepalived, but we use LVS/DR+Keepalived most often in the implementation of the project. 4. No traffic. LVS only distributes requests, but traffic does not flow out from itself, which ensures that the performance of equalizer IO will not be affected by large traffic. 5, a wide range of applications, because LVS works on the fourth floor, so it can do load balancing for almost all applications, including http, database, online chat rooms and so on. Network flowchart of LVS DR (Direct Routing) mode:

LVS's disadvantages: 1, the software itself does not support regular expression processing, can not do static and dynamic separation; and now many websites have a strong demand in this area, this is the advantage of Nginx/HAProxy+Keepalived. 2. If the website application is relatively large, the implementation of LVS/DR+Keepalived is more complex, especially if there is a Windows Server behind the machine, if the implementation, configuration and maintenance process is more complex, relatively speaking, Nginx/HAProxy+Keepalived is much simpler. Advantages of HAProxy: 1. HAProxy supports virtual hosts and can work in layers 4 and 7 (supports multiple network segments) 2. The advantages of HAProxy can supplement some of the shortcomings of Nginx, such as supporting the maintenance of Session and the boot of Cookie; at the same time, it supports checking the status of the back-end server by obtaining the specified url. 3. HAProxy, similar to LVS, is only a load balancing software. In terms of efficiency, HAProxy has a better load balancing speed than Nginx, and it is also better than Nginx in concurrent processing. 4. HAProxy supports load balancer forwarding of TCP protocol. It can load balance MySQL reads, detect and load balance backend MySQL nodes. You can use LVS+Keepalived to load balance MySQL master and slave. 5. There are many HAProxy load balancing strategies. HAProxy's load balancing algorithms now include the following eight types of ① roundrobin for simple polling. Forex analyst http://www.gendan5.com/experts.html is the most smooth and fair algorithm when the server's processing time is evenly distributed. The algorithm is dynamic, and the weight of the server that starts slowly for the instance will be adjusted during the run. Supports up to 4095 backend hosts

The server with the least number of ② leastconn connections receives the connection first. Leastconn is recommended for long session services such as LDAP, SQL, TSE, etc., but not for short session protocols. Such as HTTP. The algorithm is dynamic, and the weight of the server that starts slowly for the instance will be adjusted during the run. ③ static-rr is used in turn for each server based on weight, similar to roundrobin, but it is static, meaning that runtime modification permissions are invalid. In addition, it has no limit on the number of servers. This algorithm is generally not used; ④ source hashes the request source IP address, divides the total weight of available servers by the hash value, and allocates it according to the result. As long as the server is normal, the same client IP address always accesses the same server. If the results of the hash vary with the number of servers available, the client is directed to a different server; this algorithm is generally used for Tcp schemas that cannot be plugged into cookie. It can also be used on the WAN to provide the most effective adhesion for clients that refuse to use session cookie; the algorithm is static by default, so it is invalid to modify the weight of the server at run time, but the algorithm is adjusted according to the change of "hash-type". ⑤ uri means to hash according to the left end of the requested URI (before the question mark), divide the total weight of the available servers by the hash value, and assign it according to the result. As long as the server is normal, the same URI address always accesses the same server. It is generally used for proxy cache and anti-virus proxy to maximize the hit rate of the cache. This algorithm can only be used for the HTTP backend; it is generally used for the backend cache server; the algorithm is static by default, so it is invalid to modify the weight of the server at run time, but the algorithm will be adjusted according to the change of "hash-type". ⑥ url_param looks for the URL parameters specified in the query string of the HTTP GET request, which can basically lock the requirement of using a special URL to a specific load balancer node. This algorithm is generally used to send the information of the same user to the same backend server. The algorithm is static by default, so it is invalid to modify the weight of the server at run time, but the algorithm will be adjusted according to the change of "hash-type". ⑦ hdr (name) looks for HTTP headers in each HTTP request, and the HTTP header will be treated as in each HTTP request and for a specific node; if the header is missing or the header does not have any value, then use roundrobin instead; the algorithm is static by default, so it is invalid to modify the weight of the server at run time, but the algorithm will adjust according to the change of "hash-type". ⑧ rdp-cookie (name) queries and hashes RDP cookie; for each incoming TCP request this mechanism is used in a degenerate persistence mode so that the same user or the same session ID is always sent to the same server. If there is no cookie, the roundrobin algorithm is used instead; this algorithm is static by default, so it is not valid to change the weight of the server at run time, but the algorithm adjusts to the change of "hash-type". Working model diagram of haproxy:

Disadvantages of HAPorxy: 1. Does not support POP/SMTP protocol 2. Does not support SPDY protocol 3. The HTTP cache feature is not supported. Nowadays, many open source lb projects have HTTP cache functions more or less. 4. The ability to reload the configuration requires a restart of the process, and although it is also soft restart, reaload without Nginx is smoother and friendlier. 5. Multi-process mode support is not good enough

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report