Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the concept and usage of LVS

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

What is the concept and use of LVS, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.

Introduction and use of LVS

1. What is LVS?

The full name of LVS is Linux Virtual Server, that is, Linux virtual server. It is an open source project of Dr. Zhang Wensong of our country. In linux memory 2.6, it has become part of the kernel, and previous kernel versions need to recompile the kernel.

Video detailed explanation

What can LVS do?

LVS is mainly used for multi-server load balancing. It works in the network layer and can achieve high-performance, high-availability server cluster technology. It is cheap and can combine many low-performance servers to form a super server. It is easy to use, easy to configure, and has a variety of load balancing methods. It is stable and reliable, even if one of the servers in the cluster does not work properly, it does not affect the overall effect. In addition, the scalability is also very good.

three。 working principle

As shown in the figure above, LVS can be divided into three parts:

1.Load Balancer:

This is the core of LVS, which is like the Controller of our website's MVC model. It is responsible for distributing customer requests to different servers in the next layer for processing according to a certain algorithm, and does not do specific business processing itself. In addition, this layer can also be used to monitor the status of the next layer. If a server in the next layer does not work properly, it will automatically remove it and add it when it is restored. This layer consists of one or more Director Server.

2.Server Array:

This layer is responsible for specific business. It can be composed of WEB Server, mail Server, FTP Server, DNS Server and so on. Note that in fact, the upper Director Server can also be used as Real server.

3.Shared Storage:

The main purpose is to improve the data of the upper layer and keep the data consistent for the upper layer.

4. Video detailed explanation

four。 Load balancing mechanism

As we said earlier, LVS works at the network layer. Compared with other load balancing solutions, such as DNS domain name rotation resolution, application layer load scheduling, client scheduling and so on, its efficiency is very high. LVS achieves load balancing by controlling IP. IPVS is its concrete implementation module. The main function of IPVS: install it on Director Server and virtualize an IP (VIP) for external access in Director Server. The user visits the VIP, arrives at the Director Server,Director Server, selects a Real Server according to certain rules, and then returns the data to the client after processing. These steps give rise to some specific problems, such as how to select a specific Real Server,Real Server if the data is returned to the client, and so on. IPVS has three mechanisms for this:

1.VS/NAT (Virtual Server via Network Address Translation)

That is, the network address flipping technology to realize the virtual server. When the request comes, the program processed on Diretor server changes the destination address (virtual IP address) in the data packet to a specific Real Server, and the port to the port of Real Server, and then sends the message to Real Server. After Real Server processes the data, it needs to return to Diretor Server, and then Diretor server changes the source address and source port in the packet to the address and port of VIP, and finally sends the data out. From this, we can see that users' requests and returns have to go through Diretor Server, and if there is too much data, Diretor Server will certainly be overwhelmed.

2.VS/TUN (Virtual Server via IP Tunneling)

That is, IP tunnel technology to achieve virtual server. It is basically the same as VS/NAT, but Real server returns data directly to the client without going through Diretor server, which greatly reduces the pressure on Diretor server.

3.VS/DR (Virtual Server via Direct Routing)

That is, the direct routing technology is used to realize the virtual server. Unlike the previous two methods, its packet forwarding method is different. VS/DR sends the request to Real Server by rewriting the MAC address of the request message, while Real Server returns the response directly to the customer, eliminating the IP tunnel overhead in VS/TUN. This method has the highest performance among the three load scheduling mechanisms, but both Director Server and Real Server must have a network card connected to the same physical network segment.

five。 Load scheduling algorithm

We all know that Director Server has to choose different Real server, so if it chooses Real Server to achieve load balancing, IPVS implements eight scheduling methods. Specific algorithms can be found on the official website or Baidu, which are not listed here. Official website: www.linuxvirtualserver.org.

VI. Specific configuration operations

First of all, we have three machines here, the IP is 192.168.132.30 (Diretor server), 192.168.132.64 (Real server 1), 192.168.132.68 (real server 2). On real server 1 and 2, the web service has been configured, and we assume that another virtual IP for external access is 192.168.132.254 (VIP). In addition, ipvsadm has been installed on Diretor server.

Let's VS/DR describe the configuration process in detail.

The configuration above Diretor server:

/ / first, bind a virtual IP (also known as VIP) to Director Server, which is used to provide services:

Ifconfig eth0:0 192.168.132.254 broadcast 192.168.132.254 netmask 255.255.255.255 up

/ / specify a route to the device eth0:0

Route add-host 192.168.132.254 dev eth0:0

/ / enable packet forwarding in the system

Echo "1" > / proc/sys/net/ipv4/ip_forward

/ / be aware of the previous settings of ipvsadm

Ipvsadm-C

/ / add a new virtual IP record 192.168.132.254 with a duration of 120 seconds

Ipvsadm-A-t 192.168.132.254 ipvsadm 80-s rr-p 120

/ / add a two-day IP record to the newly added virtual real server record.-g means using VS/DR mode.

Ipvsadm-a-t 192.168.132.254 ipvsadm 80-r 192.168.132.64 ipvsadm-a-t 192.168.132.254 80-r 192.168.132.68 80-g

/ / enable LVS service ipvsadm

Configuration on two real server:

/ bind a virtual IP address on the loopback device and set its subnet mask to 255.255.255.255 to keep interworking with the virtual IP on the Director Server /

Ifconfig lo:0 192.168.132.254 broadcast 192.168.132.254 netmask 255.255.255.255 uproute add-host 192.168.132.254 dev lo:0// disable native ARP request echo "1" > / proc/sys/net/ipv4/conf/lo/arp_ignoreecho "1" > / proc/sys/net/ipv4/conf/all/arp_ignoreecho "2" > / proc/sys/net/ipv4/conf/lo/arp_announceecho "2" > / proc/ Sys/net/ipv4/conf/all/arp_announce

Then on other client machines, visit http://192.168.132.254/, and you can see the results.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report