The difference between lvs and nginx

 Both lvs and nginx can be used as multi-machine load schemes. They have their own advantages and disadvantages. In the production environment, the actual situation needs to be carefully analyzed and used.

    First, the advantages of lvs:

    1. Strong anti-load capability, because the logic of lvs working mode is very simple, and the work is at the fourth layer of the network layer, only for request distribution, no traffic, so there is basically no need to think too much about efficiency. LVS generally rarely fails, and even if it fails, it is usually caused by problems in other places (such as memory, CPU, etc.) that cause problems with LVS.

    2. Configurable, this is usually a big disadvantage and also a big advantage, because there are not too many configurable options, so in addition to adding or removing servers, it is not necessary to touch it frequently, which greatly reduces the chance of human error .

    3. The work is stable. Because of its strong anti-load capacity in the province, high stability is also a matter of course. In addition, various lvs have a complete dual-machine hot backup solution, so there is no need to worry about the balancer itself. If there is a fault, lvs will automatically judge, so the overall system is very stable.

    4. No traffic, lvs only distributes requests, and traffic does not go out from itself, so it can be used for some line diversion purposes. No traffic also keeps the balancer's IO performance from being affected by heavy traffic.

    5.lvs can basically support all applications, because the green work is in the 4th layer, so it can do load balancing for almost all applications, including http, database, chat room, etc.

    In addition: lvs is not completely able to identify node failures. For example, in the wlc allocation mode, one node in the cluster is not configured with vip, which will make the entire cluster unusable. In this case, using the wrr allocation method will lose a machine. This issue is still under further testing. Therefore, it is better to be more careful when using lvs.

    Second, the results of the comparison between nginx and lvs:

    1. Nginx works at the seventh layer of the network, so it can implement a diversion strategy for the http application itself, such as domain name, directory structure, etc. In contrast, lvs does not have such a function, so nginx can rely on this alone. The use of occasions is much more than that of lvs; but these useful functions of nginx make it more adjustable than lvs, so it is often necessary to touch and touch. Judging from the second advantage of lvs, there are many touches. There is also a greater chance of human-induced problems.

    2. Nginx is less dependent on the network. In theory, as long as the ping is successful and the webpage access is normal, nginx can be connected. At the same time, nginx can distinguish between internal and external networks. If it is a node that has both internal and external networks, it is equivalent to a single machine. The backup line is used; lvs is more dependent on the network environment. At present, the server is in the same network segment and the lvs uses the direct method to divide the traffic, so the effect can be guaranteed. In addition, note that lvs needs to apply for at least one more ip from the host to be a visual ip. It seems that the ip of the province cannot be used as a VIP. To be a good lvs administrator, you really have to follow up and learn a lot of knowledge about network communication, it is no longer as simple as an http.

    3. The installation and configuration of nginx is relatively simple, and it is also very convenient to test, because it can basically print out errors in logs. The installation, configuration and testing of lvs will take a long time, because as mentioned above, lvs is relatively dependent on the network, and many times the failure to configure successfully is due to network problems rather than configuration problems. If there is a problem, it should be solved accordingly will be more troublesome.

    4. nginx can also withstand high load and is stable, but the load degree is very poor and the stability is poor. There are several levels of lvs: nginx handles all traffic, so it is limited by machine IO and configuration; its own bugs are still unavoidable; nginx There is no ready-made dual-machine hot backup solution, so running on a single machine is still relatively risky, and it is difficult to say everything on a single machine.

    5. nginx can detect internal server failures, such as status codes, timeouts, etc. returned by the server processing web pages, and resubmit requests that return errors to another node. At present, ldirectd in lvs can also support monitoring for the internal situation of the server, but the principle of lvs makes it impossible to resend the request. To resend the request, for example, the user is uploading a file, and the node processing the upload happens to fail during the upload process, nginx will switch the upload to another server for reprocessing, and the lvs will be cut off directly. If it is Users may get annoyed by uploading a large file or a very important file.

    6. The asynchronous processing of requests by nginx can help the node server to reduce the load. If you use Apache to directly serve external services, when there are many narrowband links, the Apache server will occupy a lot of memory and cannot be released. If more than one nginx is used as the Apache proxy, These narrowband links will be blocked by nginx, and Apache will not accumulate too many requests, thus reducing a considerable amount of memory usage. Using squid for this has the same effect, even if squid itself is configured not to cache, it will still help you a lot with Apache. lvs does not have these functions, so it cannot be compared.

    7. nginx can support http and Email (the function of Email is estimated to be less used), and the applications supported by lvs will be more than nginx in this regard.

    In terms of use, generally the front-end strategy should be lvs, that is, the point of dns should be the lvs equalizer, and the advantage of lvs is that it is very suitable for this task.

    Important IP addresses are best managed by lvs, such as the IP of the database, the IP of the webservice server, etc. These IP addresses will be used more and more over time. If the IP is replaced, failures will follow. Therefore, it is safest to hand over these important IPs to lvs hosting. The only disadvantage of this is that the number of VIPs will be more.

    Nginx can be used as an lvs node machine. One is to use the functions of nginx, and the other is to use the performance of nginx. Of course, squid can also be used directly at this level. The function of squid is much weaker than that of nginx, and its performance is also inferior to nginx.

    Nginx can also be used as a middle-level proxy. At this level, nginx is basically unmatched. The only one that can shake nginx is lighttpd. However, lighttpd has not yet achieved the full function of nginx, and the configuration is not so clear and easy to read. In addition, the IP of the middle-level agent is also important, so it is the most perfect solution for the middle-level agent industry to have a VIP and lvs.

    nginx can also be used as a static server for web pages.

    The specific application has to be analyzed in detail. If it is a relatively small website (daily pv < 10 million), it is completely fine to use nginx. If there are many machines, you can use dns polling, and lvs consumes a lot of machines. ; For large websites or important services, consider using lvs when the machine is not worried.

    illustrate:

    Use nginx+keepalived to achieve load balancing to solve single-point and high-traffic concurrency problems. Why use nginx instead of lvs?

    7 reasons:

    1. High concurrent connections: The official test can support 50,000 concurrent connections, and it runs to 20,000 to 30,000 concurrent connections in the actual production environment.

    2. Less memory consumption: under 30,000 concurrent connections, only 10 nginx processes that are opened consume 150M of memory (150*10=150M).

    3. The configuration file is very simple: the style is as easy to understand as the program.

    4. Low cost: nginx is open source software and can be used for free. The purchase of F5 big-ip, netscaler and other hardware load balancing switches requires more than 100,000 to hundreds of thousands of yuan.

            (The reason for using nginx for Layer 7 load balancing?)

    5. Support rewrite rewrite rules: HTTP requests can be divided into different backend server groups according to different domain names and urls.

    6. Built-in health check function: If a web server at the back end of nginx proxy goes down, it will not affect front-end access.

    7. Save bandwidth: support gzip compression, you can add the header header cached locally by the browser.

    Further explanation:

    keepalived is a high-reliability running software for implementing vrrp backup routing under linux. The service mode based on keepalived design can truly achieve seamless ip transfer in an instant when the primary server and the backup server fail.

    Nginx is an http server based on the epoll model in the linux2.6 kernel. Different from the Apache process derivation mode, the nginx process is based on the master+slave multi-process model, and it has a very stable sub-process management function. In the master process allocation mode, the master process never performs business processing, but only distributes tasks, so as to achieve high survival reliability of the master process. All business signals of the slave process are sent by the master process, and all time-out tasks of the slave entering the city will be Terminated by the master, it belongs to the blocking character model.

    The server ip liveness detection is done by keepalived itself. The two servers are configured as keepalived in a master-slave relationship with each other. If one of the machines fails, the other party can take over the ip.

    The server IP of keepalived is managed through its configuration file, and depends on its own process to determine the survival status of the server. If online maintenance of the server process is required, it is only necessary to stop the keepalived service process of the maintained machine, and the other one The server can take over all the applications of the server.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326218432&siteId=291194637