: This article mainly introduces (summary) the advantages and disadvantages of NginxLVSHAProxy server load balancer software. For more information about PHP tutorials, see. PS: Nginx/LVS/HAProxy is currently the most widely used three load balancing software. I have implemented these software in multiple projects. I have referenced some materials and combined some of my experience in using it, to sum up.
Generally, server load balancer uses different technologies at different stages as the website scale increases. Specific application requirements have to be analyzed. for small and medium-sized Web applications, such as daily PV smaller than 10 million, Nginx is enough. if there are many machines, DNS round-robin can be used, LVS consumes a lot of machines. LVS can be used for large websites or important services with a large number of servers.
One is through hardware. common hardware includes expensive F5, Array, and other commercial load balancers, it has the advantage of a professional maintenance team to maintain these services. The disadvantage is that the cost is too large. Therefore, it is not required for small network services for the time being; in addition, it is similar to Nginx/LVS/HAProxy's Linux-based open-source free server load balancer software, which is implemented at the software level, so the cost is very low.
Currently, the website architecture is generally reasonable and popular: the Web front-end uses Nginx/HAProxy + Keepalived as the load balancer, and the backend uses the MySQL database for master-slave and read-write separation, use the LVS + Keepalived architecture. Of course, you must develop a scheme based on the specific needs of the project.
Next we will talk about their respective characteristics and applicable occasions.
Nginx has the following advantages:
1. working on Layer 7 of the network, you can implement some shunting policies for http applications. for example, for domain names and directory structures, its regular rules are more powerful and flexible than HAProxy, this is one of the main reasons for its widespread popularity. Nginx is far more usable than LVS alone.
2. Nginx has a very small dependence on network stability. Theoretically, it can be pinged to implement the load function. this is also one of its advantages. On the contrary, LVS is highly dependent on network stability, I have a deep understanding of this;
3. Nginx is easy to install and configure, and is easy to test. it can print errors in logs. It takes a long time to configure and test LVS. LVS is highly dependent on the network.
3. it can handle high load pressure and stability. in the case of poor hardware, it can support tens of thousands of concurrent requests, and the load is relatively smaller than LVS.
4. Nginx can detect internal server faults through ports, such as processing status codes returned by webpages based on the server, timeout, and so on, and resubmit the returned error requests to another node, however, the disadvantage is that url detection is not supported. For example, if a user is uploading a file and the node that handles the upload fails during the upload process, Nginx will cut the upload to another server and re-process it, and LVS will be disconnected directly, if you upload a large file or a very important file, the user may be dissatisfied.
5. Nginx is 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. It is also stable in high-traffic environments.
6. Nginx is now becoming more and more mature as the Web reverse acceleration cache, which is faster than the traditional Squid server. you can consider using Nginx as the reverse proxy accelerator.
7. Nginx can be used as a middle-layer reverse proxy. Nginx basically has no rivals on this layer. The only thing that can be compared with Nginx is lighttpd. However, lighttpd does not yet provide complete Nginx functions, the configuration is not so clear and easy to read, and community information is far from Nginx active.
8. Nginx can also be used as a static web page and image server, which has no performance rival. The Nginx Community is also very active, and there are many third-party modules.
Nginx has the following disadvantages:
1. Nginx only supports http, https, and Email protocols, so it is smaller in scope. this is a disadvantage of Nginx.
2. backend server health check only supports Port detection, but does not support url detection. Direct Session persistence is not supported, but can be solved through ip_hash.
LVS: implements a high-performance and high-availability server load balancer using Linux kernel clusters. it has good Scalability, Reliability, and Manageability ).
LVS has the following advantages:
1. strong anti-load ability, working on layer 4 of the network for distribution only, no traffic is generated, this feature also determines its strongest performance in the server load balancer software, and its consumption of memory and cpu resources is relatively low.
2. low configuration, which is a disadvantage and an advantage. because there is no configuration item, there is no need for too many contacts, which greatly reduces the chance of human error.
3. stable operation, because of its strong load resistance capability, it has a complete dual-machine hot standby solution, such as LVS + Keepalived, however, LVS/DR + Keepalived is the most widely used in project implementation.
4. no traffic. LVS only distributes requests, but the traffic does not go out of it. This ensures that the I/O performance of the balancer will not be affected by the large traffic.
5. a wide range of applications. because LVS works on layer 4, it can load balance almost all applications, including http, databases, and online chat rooms.
LVS has the following disadvantages:
1. the software itself does not support regular expression processing and does not support static/dynamic separation. many websites have strong requirements in this regard, which is the advantage of Nginx/HAProxy + Keepalived.
2. if there are a large number of website applications, the implementation of LVS/DR + Keepalived is complicated. in particular, if there is a Windows Server Machine later, if the implementation, configuration, and maintenance process are complicated, Nginx/HAProxy + Keepalived is much simpler.
HAProxy features:
1. HAProxy also supports virtual hosts.
2. the advantages of HAProxy can supplement some shortcomings of Nginx, such as support Session persistence and Cookie guidance. It also supports obtaining a specified url to detect the status of the backend server.
3. similar to LVS, HAProxy itself is only a server load balancer software. in terms of efficiency alone, HAProxy has a better load balancing speed than Nginx, it is superior to Nginx in concurrent processing.
4. HAProxy supports TCP server load balancer forwarding. it supports load balancing for MySQL reads, and checks and balances backend MySQL nodes, you can use LVS + Keepalived to perform load balancing on the master and slave databases of MySQL.
5. There are many load balancing policies for HAProxy. the following eight load balancing algorithms are available for HAProxy:
① Roundrobin indicates simple round robin. this is basically what server load balancer has;
② Static-rr, indicating that according to the weight, we recommend that you pay attention to it;
③ Leastconn, which indicates that the minimum number of connectors is handled first. we recommend that you pay attention to it;
④ Source indicates the Request source IP address. This is similar to the IP_hash mechanism of Nginx. We use it as a solution to the session problem. we recommend that you pay attention to it;
⑤ Ri, indicating the URI based on the request;
⑥ Rl_param indicates the request URl parameter 'balance url_param' requires an URL parameter name;
7. hdr (name) indicates locking each HTTP request based on the HTTP request header;
Extends rdp-cookie (name) indicates that each TCP request is locked and hashed based on the cookie (name.
Summary of comparison between Nginx and LVS:
1. Nginx works on Layer 7 of the network. Therefore, it can be used to distribute traffic to http applications, such as domain names and directory structures. In contrast, LVS does not have such a function, therefore, Nginx is much more usable than LVS alone. However, Nginx uses these functions to make them more adjustable than LVS, so it often needs to touch and touch more, there is a high probability of human problems.
2. Nginx has little dependence on network stability. Theoretically, Nginx can be connected if the ping succeeds and the webpage access is normal. this is a major advantage of Nginx! Nginx can also distinguish between the intranet and the Internet. if it is a node with both the intranet and the Internet, it is equivalent to a single machine with a backup line. LVS is more dependent on the network environment, currently, the server is in the same CIDR block and LVS uses direct to distribute traffic. The effect is guaranteed. In addition, LVS needs to apply for at least one more ip address from the publisher for Visual IP. it seems that it cannot use its own IP address as the VIP address. To be a good LVS administrator, you must follow up and learn a lot about network communication, so it is no longer as simple as an HTTP.
3. Nginx installation and configuration are relatively simple, and testing is also very convenient, because it can basically print out errors using logs. It takes a long time to install, configure, and test LVS. LVS relies heavily on the network. in many cases, failure to complete the configuration is due to network problems rather than configuration problems, it will be much more troublesome to solve the problem.
4. Nginx can also withstand high loads and stability, but its load and stability are poor. LVS has several levels: Nginx handles all traffic, so it is limited by machine I/O and configuration; it is still difficult to avoid bugs.
5. Nginx can detect internal faults on the server, such as status code returned by the server to process webpages, timeout, and so on. In addition, it will resubmit the request with an error returned to another node. Currently, ldirectd in LVS can also be monitored based on internal server conditions, but the principle of LVS makes it unable to resend requests. For example, if a user is uploading a file and the node that handles the upload fails during the upload process, Nginx will cut the upload to another server and re-process it, and LVS will be disconnected directly, if you upload a large file or a very important file, the user may be annoyed.
6. asynchronous processing of requests by Nginx can help the node server reduce the load. If apache is used for external services, when many narrow-band connections occur, the apache server will occupy a large amount of memory and cannot be released. if one more Nginx is used as the apache Proxy, these narrow-band connections will be blocked by Nginx, apache does not pile up too many requests, which reduces the resource usage. This also applies to squid. even if squid is configured as not cached, it is of great help to apache.
7. Nginx supports http, https, and email (fewer email functions). LVS supports more applications than Nginx. In terms of use, generally the frontend should adopt LVS, that is, the DNS should point to the LVS balancer. the advantages of LVS make it very suitable for this task. Important ip addresses are recommended to be hosted by LVS, such as the ip address of the database and the ip address of the webservice server. these ip addresses will become more and more usable over time. if the ip address is changed, the fault will occur one after another. Therefore, it is the most secure to hand over these important ip addresses to LVS for hosting. The only drawback of this operation is that the number of VIP addresses is large. Nginx can be used as an LVS node machine. first, Nginx functions can be used, and second, Nginx performance can be used. Of course, squid can also be used directly at this layer. squid features are much weaker than Nginx, and performance is inferior to Nginx. Nginx can also be used as a middle-layer proxy. basically, Nginx has no rival in this layer. The only thing that can shake Nginx is lighttpd. However, lighttpd is not fully capable of Nginx yet, the configuration is not so clear and easy to read. In addition, the IP address of the middle-layer proxy is also important, so the middle-layer proxy also has a VIP and LVS is the most perfect solution. The specific application has to be analyzed. if it is a relatively small website (with a daily PV of less than 10 million), Nginx can be used. if there are many machines, DNS round-robin can be used, LVS consumes a large number of machines. when large websites or important services are not worried about, LVS should be used more.
Currently, the use of network load balancing is based on different stages as the scale of the website increases:
Phase 1: Use Nginx or HAProxy for single-point load balancing. in this phase, the server scale is just out of the billing server and single database mode and requires a certain amount of load balancing, however, it is still relatively small, and there is no professional maintenance team for maintenance or large-scale website deployment. In this way, Nginx or HAproxy is the first choice. at this time, these items are easy to configure and can be configured over layer-7 using the HTTP protocol. This is the first choice.
Stage 2: as the network service expands, Nginx with single points cannot meet the requirements. LVS or commercial Array is the primary choice, and Nginx is used as the node of LVS or Array, the specific LVS or Array options are based on the company's size and budget. The application delivery function of Array is very powerful. I have used it in a project, and the price/performance ratio is much higher than that of F5, first choice for commercial use! However, at this stage, the related talents cannot keep up with the business improvement, so purchasing commercial load balancing has become the only way to go.
Stage 3: network services have become a mainstream product. at this time, with the further expansion of the company's popularity, the capability and quantity of relevant talents have also increased. at this time, no matter whether it is developed to suit the customization of its own products, as for cost reduction, the open-source LVS has become the first choice. at this time, LVS will become the mainstream.
The ideal basic architecture is: Array/LVS-Nginx/Haproxy-Squid/Varnish-AppServer.
This blog post reposted from http://www.ha97.com/5646.html
The above section introduces (summary) the advantages and disadvantages of the Nginx/LVS/HAProxy server load balancer software, including some content, and hopes to help those who are interested in the PHP Tutorial.