The difference between nginx and lvs
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.
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

Starting an Nginx server requires different steps according to different operating systems: Linux/Unix system: Install the Nginx package (for example, using apt-get or yum). Use systemctl to start an Nginx service (for example, sudo systemctl start nginx). Windows system: Download and install Windows binary files. Start Nginx using the nginx.exe executable (for example, nginx.exe -c conf\nginx.conf). No matter which operating system you use, you can access the server IP
