LVS Nginx haproxy Contrast

Source: Internet
Author: User
Tags email protocols node server haproxy nginx load balancing

Specific application needs to be specific analysis, if it is small and medium-sized Web applications, such as the daily PV less than 10 million, with Nginx can be completely; if there are many machines, you can use DNS polling, LVS consumes more machines or more, large web sites or important services, and the server is relatively long, You can consider using LVS. One is through the hardware to carry out, the common hardware has more expensive F5 and array and other commercial load balancer, its advantage is that there is a professional maintenance team to maintain these services, the disadvantage is that the cost is too large, so for the smaller network services for the moment there is no need to use The other is Linux-based, open-source, free load balancing software similar to Nginx/lvs/haproxy, which is implemented at the software level, so it's very inexpensive. At present, the structure of the Web site architecture is generally more reasonable: the Web front-end uses nginx/haproxy+keepalived as the load balancer, and the backend uses the MySQL database as a master and read-write separation, using the lvs+keepalived architecture. Of course, according to the specific needs of the project plan.



############################################################# "Nginx article" ########################################## ################

The advantages of Nginx are:

Work on the 7 layer of the network, can be targeted at the HTTP application to do some diversion strategy, such as for the domain name, directory structure, its regular rules than haproxy more powerful and flexible, which is the main reason for its widespread popularity, nginx alone this can be used more than LVS.     ①nginx to the stability of the network is very small, in theory can ping through the load function, this is one of its advantages; Contrary to the network stability of LVS is relatively large, which I have deep experience;     ②nginx installation and configuration is relatively simple, easy to test, it is basically able to print out the error log. LVS configuration, testing will take a relatively long time, LVS on the network dependence is relatively large.     ③ can bear high load pressure and stability, in the case of hardware is not poor generally can support tens of thousands of times the concurrency, the load is relatively smaller than LVS.     ④nginx can detect the internal faults of the server through the port, such as the status code returned by the server, timeout, and so on, and will resubmit the request to another node, but the disadvantage is that the URL is not supported for detection. For example, the user is uploading a file, and processing the upload node just in the upload process failure, Nginx will upload to another server to re-processing, and LVS directly broken off, if it is to upload a large file or very important files, users may be dissatisfied.     ⑤nginx is not just a good load balancer/reverse proxy software, it is also a powerful Web application server. Lnmp is also a very popular web architecture in recent years and has a good stability in high-traffic environments.     ⑥nginx is now becoming more mature as a Web reverse-acceleration cache, faster than a traditional squid server, and can be considered as a reverse proxy accelerator.     ⑦nginx can be used as a middle-class reverse proxy, this level nginx basically no opponent, the only can compare Nginx only lighttpd, but lighttpd at present has not done nginx full function , the configuration is not so clear and easy to read, the community data is far from Nginx active.     ⑧nginx is also available as a static Web page and image server, which also has no opponents in performance. The Nginx community is very active and there are many third-party modules. The drawbacks of NginxYes:     nginx only supports HTTP, HTTPS, and email protocols, so it's a disadvantage if it's smaller than the scope of application.      health checks on back-end servers, which are only supported through ports, are not supported for detection by URLs. Direct hold of session is not supported, but can be solved by ip_hash


######################################################### "LVs article" ################################################ ###############


LVS is a high-performance, highly available load-balancing server implemented using a Linux kernel cluster with good scalability (Scalability), Reliability (reliability), and

Manageability (manageability).

LVS is a high-performance, high-availability load-balancing server implemented using a Linux kernel cluster with good scalability (Scalability), Reliability (reliability), and manageability (manageability).    The advantages of LVS are: ① anti-load capacity, is working in the Network 4 layer only for distribution, no traffic generated, this feature also determines its load balancer software in the most powerful performance, memory and CPU resource consumption is low.    ② low-profile, which is a disadvantage is also an advantage, because there is not much to configure things, so do not need too much contact, greatly reducing the chance of human error.    Stable work, because of its own resistance to load is very strong, the self has a complete two-machine hot-standby program, such as Lvs+keepalived, but we in the implementation of the project is the most used or lvs/dr+keepalived.    ③ no traffic, LVS only distributes the request, and the traffic does not go out from it, which guarantees that the performance of the Equalizer IO will not be affected by large traffic. ④ has a wide range of applications because LVS works on Layer 4, so it can load balance almost all applications, including HTTP, databases, online chat rooms, and more.    The disadvantage of LVS is: the software itself does not support regular expression processing, can not do static and dynamic separation, and now many sites in this area have a strong demand, this is the advantage of nginx/haproxy+keepalived. If it is a large web site application, lvs/dr+keepalived implementation is more complex, especially after the Windows Server machine, if the implementation and configuration and maintenance process is more complex, relatively speaking, nginx/haproxy+ Keepalived is a lot easier.


#################################################### "Happronxy" ############################################ ##################

Haproxy is characterized by:     ①haproxy is also supported virtual host. The advantages of     ②haproxy can be supplemented with some of Nginx's shortcomings, such as supporting session retention, cookie guidance, and the ability to detect the status of the backend server by obtaining the specified URL.     ③haproxy similar to LVS, itself is just a load balancer software, simply from the efficiency of haproxy will be better than nginx load balancing speed, in concurrent processing is better than nginx.     ④haproxy supports the TCP protocol load-balancing forwarding, can load balance MySQL read, the backend of the MySQL node detection and load balancing, you can use lvs+ keepalived load balancer for MySQL master and slave.     ⑤haproxy Load Balancing strategy is very many, the Haproxy load balancing algorithm now has the following 8 kinds:     roundrobin, which means simple polling, This is not much to say, this is the load-balancing basic have,     STATIC-RR, said according to the weight, recommended attention;     leastconn, indicating that the minimum number of connectors to deal with first , it is suggested that the     source, according to the request source IP, this is similar to Nginx's ip_hash mechanism, we use it as a method to solve the session problem, we suggest to pay attention to;     ri, which represents the URL parameter according to the request ' Balance url_param '  requires according to the requested Uri;    rl_param  AN URL PARAMETER NAME;    HDR (name), which indicates that each HTTP request is locked according to the HTTP request header;     rdp-cookie (name), which indicates that each TCP request is locked and hashed according to the cookie (name).

######################################################## "nginx contrast LVs" ######################################## #################

  nginx work in the 7 layer of the network, so it can be targeted at the HTTP application itself to do the shunt strategy, such as for the domain name, directory structure, compared to LVS does not have such a function, so nginx alone this can be used on more occasions than LVS But Nginx is useful for these functions to make it more adjustable than LVS, so often to touch touch, touch more, the probability of human problems will be large.     nginx dependence on network stability is small, in theory, as long as the ping, Web Access is normal, nginx can be connected, this is a big advantage of Nginx! Nginx at the same time can also distinguish between internal and external network, if the node has both internal and external network, the equivalent of a single machine has a backup line, LVS is more dependent on the network environment, at present, the server in the same network segment and LVS using direct mode shunt, the effect is more guaranteed. In addition, the LVS need to apply to the custodian at least one more IP to do visual ip, it seems to be unable to use their own IP to do VIP. To do a good job of the LVS administrator, do have to follow up learning a lot about network communication knowledge, it is no longer an HTTP so simple.     nginx installation and configuration is relatively simple and easy to test, because it basically can print out the error log. LVS installation and configuration, testing will take a long time, LVS on the network rely on a large number of times can not be configured to succeed is because of network problems rather than configuration problems, the problem to solve also the corresponding will be more troublesome.     nginx is also able to withstand high loads and stability, but the load and stability of the LVS there are several levels: Nginx processing all traffic so limited by the machine IO and configuration, and its own bugs are still unavoidable.     nginx can detect internal failures of the server, such as the status code returned by the server, timeout, and so on, and will resubmit the request to the other node with the wrong return. At present,  LDIRECTD in LVS can also support monitoring the internal conditions of the server, but the principle of LVS makes it impossible to re-send requests. For example, the user is uploading a file, and processing the upload node just in the upload process failure, Nginx will upload to another server re-processing, and LVS is directly broken off, if it is to upload a large file or very important files, users may be annoyed.     nginx asynchronous processing of requests can help the node server offload load, if using Apache direct external service, then there are a lot of narrow-band links when the Apache server will occupy a large amount of   memory and can not be released, using more than one nginx to do Apache agent, these narrow-band links will be blocked by Nginx, Apache will not accumulate too many requests, This reduces the amount of resource usage. This use squid also has the same effect, even if the squid itself is configured to not cache, the Apache still has a lot of help.     nginx can support HTTP, HTTPS, and email (email is less powerful), and LVS supports more applications than nginx. In use, the general front-end strategy should be the LVS, that is, the DNS point should be the LVS equalizer, the advantages of LVS make it very suitable for this task. Important IP address, preferably by the LVS hosting, such as database  IP, WebService server IP and so on, these IP addresses over time, the use of polygons will become larger, if the replacement of IP will follow. So it is most secure to hand over these important IPs to  lvs, the only drawback is that the number of VIPs required will be more.     nginx can be used as the LVS node machine, one can use Nginx function, and the other is the performance of Nginx can be used. Of course, this level can also directly use the function of Squid,squid is weaker than Nginx, performance is also inferior to nginx. Nginx can also be used as a middle-class agent, this level nginx basically no opponent, the only one can shake Nginx only     lighttpd, but lighttpd at present has not been able to do   Nginx full function, configuration is not so clear and easy to read. In addition, the middle-level proxy IP is also important, so the middle-level agent also has a VIP and LVs is the most perfect solution. Specific application also have to be specific analysis, if it is relatively small site (PV less than 10 million), with Nginx can be completely, if the machine is also a lot, you can use DNS polling, LVS the cost of the machine is more; large web sites or important services, machines do not worry about the time, You should consider using LVs a lot.






























This article is from the "Brick Blog" blog, please be sure to keep this source http://wsxxsl.blog.51cto.com/9085838/1893144

LVS Nginx haproxy Contrast

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.