Home >Operation and Maintenance >Nginx >The difference between nginx and lvs

The difference between nginx and lvs

(*-*)浩
(*-*)浩Original
2019-06-04 16:53:104293browse

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

The difference between nginx and lvs

Advantages of lvs:

1. Strong load resistance, because the logic of how lvs works is very simple, and It works at layer 4 of the network layer and is only used for request distribution. There is no traffic, so there is basically no need to think too much about efficiency. LVS generally rarely fails. Even if it does, it is usually caused by problems elsewhere (such as memory, CPU, etc.).

2. Configurability, this is usually a major disadvantage but also a major advantage, because there are not many configurable options, so except for adding or removing servers, you do not need to touch it often, which greatly Reduces the chance of human error.

3. Stable work, because the province has strong load resistance, so high stability is natural. In addition, various LVS have complete dual-machine hot backup solutions, so there is no need to worry about the equalizer itself. What problems may occur? If a node fails, LVS will automatically identify it, so the overall system is very stable.

4. No traffic, lvs only distributes requests, and the traffic does not go out from itself, so you can use it to do some line diversion. There is no traffic and the IO performance of the equalizer is not affected by large traffic.

5.lvs can basically support all applications. Because green work is on layer 4, it can load balance almost all applications, including http, databases, chat rooms, etc.

In addition: lvs is not completely able to identify node failures. For example, in the wlc allocation mode, if a node in the cluster is not configured with VIP, the entire cluster will be unusable. In this case, the wrr allocation method will be lost. a machine. This issue is currently still under further testing. So it’s better to be more careful when using LVS.

The results of comparison between nginx and lvs:

1.nginx works on the 7th layer of the network, so it can implement diversion strategies for the http application itself, such as For domain names, directory structures, etc., in comparison, lvs does not have such functions, so nginx can be used in far more situations than lvs based on this alone; but these useful functions of nginx make it more adjustable than LVS, so you often have to touch it. Judging from the second advantage of LVS, the more you touch it, the greater the chance of human problems.

2.nginx has less dependence on the network. In theory, as long as ping is successful and webpage access is normal, nginx can be connected. nginx can also distinguish between internal and external networks. If it is a node that has both internal and external networks , which is equivalent to a single machine having a backup line; LVS is more dependent on the network environment. At present, the server is in the same network segment and LVS uses direct mode to distribute traffic, so the effect is better guaranteed. Also note that LVS needs to apply for at least one IP from the hosting provider to be used as a visual IP. It seems that IPs from the same province cannot be used as VIP. To be a good LVS administrator, you really need to follow up and learn a lot of knowledge about network communication. It is no longer as simple as http.

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

4.nginx can also withstand high loads and is stable, but the load 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 also It is still unavoidable; nginx does not have a ready-made dual-machine hot backup solution, so running on a single machine is still relatively risky, and it is difficult to say anything about a single machine.

5.nginx can detect internal server failures, such as status codes, timeouts, etc. returned by the server processing web pages, and will resubmit requests that return errors to another node. Currently, ldirectd in lvs can also support monitoring the internal conditions of the server, but the principle of lvs prevents it from resending requests. Regarding resending the request, for example, if 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 lvs will be directly disconnected. If Users may be annoyed by uploading a large or important file.

6.nginx’s asynchronous processing of requests can help the node server reduce the load. If you use Apache to provide direct external services, then when there are many narrowband links, the Apache server will occupy a large amount of memory and cannot be released. Use more than one If nginx acts as an Apache proxy, these narrowband links will be blocked by nginx, and too many requests will not accumulate on Apache, thus reducing a considerable amount of memory usage. Using Squid has the same effect in this regard. Even if Squid itself is configured not to cache, it will still be of great help to Apache. LVS does not have these functions, so it cannot be compared.

nginx can also be used as a mid-level proxy. At this level, nginx has basically no rivals. The only one that can shake nginx is lighttpd. However, lighttpd is not yet able to achieve the full functions of nginx, and the configuration is not so clear and easy to read. . In addition, the IP address of the middle-level agent is also important, so having a VIP and LVS for the middle-level agent industry is the most perfect solution.

The specific application needs to be analyzed in detail. If it is a relatively small website (daily pv

For more Nginx related technical articles, please visit the Nginx usage tutorial column to learn!

The above is the detailed content of The difference between nginx and lvs. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn