LVS load balancing NAT, DR - Notes

Has only been tested in a virtual machine LAN on the server I understand the VIP should be set to the IP public network scheduler in order to resolve, just do not know right, did a few servers for my test. .

 

VS / NAT: Network Address Translation mode, data traffic inbound / outbound through distributor (scheduler)

1, since the NAT mode, out of the data for the scheduler, thus the real back-end servers to support fewer

2, the scheduling (Dip) Vip and the need to work in different networks

3, the gateway addresses of all the real servers must point to Dip

4, the scheduler needs dual card, enable the routing forwarding

 

The following is a virtual machine Procedure:

Scheduler: 192.168.26.130

Nx1: 192.168.26.129

nginx2: 192.168.26.128

 

First, the scheduler operation:

1. Add a IP on the network card

# ip addr add dev ens33 192.168.1.100/24(或添加一张物理网卡为桥接模式)

2. Turn on Route Forwarding

# vim /etc/sysctl.conf

net.ipv4.ip_forward = 1

# sysctl -p

Temporary open

# echo 1 > /proc/sys/net/ipv4/ip_forward

3. Install ipvsadm and defined distribution strategy

ipvsadm tool introduced

# yum -y install ipvsadm

# ipvsadm -C //清除所有规则

# ipvsadm -A -t 192.168.1.100:80 -s rr

-A add a scheduler

-s specifies the scheduling algorithm (rr is round-robin scheduling algorithm notes at the end)

-a Adds a real server to a scheduler

-t TCP transport protocol

-m mode using LVS-NAT

-r real server

# ipvsadm -a -t 192.168.1.100:80 -r 192.168.26.128 -m

# ipvsadm -a -t 192.168.1.100:80 -r 192.168.26.129 -m

Then the real web server is disposed rearward of, the scheduler must specify an IP gateway

1. Install nginx

.....

2. Add the Gateway

# route add default gw 192.168.26.130

If there is no route command to install it

# yum install net-tools

Do load balancing two configuration must be the same, and I am here just to distinguish the next, and then use the same network scheduler VIP client access

 

# ipvsadm -L -n --stats

 

1. Conns (connections scheduled) has forwarded the number of connections

2. InPkts (incoming packets) into a number of packets

3. OutPkts (outgoing packets) the packet number

4. InBytes (incoming bytes) into the flow (bytes)

5. OutBytes (outgoing bytes) the flow (bytes)

The above is a simple test LVS NAT mode.

Principle VS / NAT mode is that: when the scheduler receives Client request, the scheduler destination IP packet is converted to VIP by the Real Server RIP selected to achieve distribution requirements Gateway at the RS DIP scheduler.

Characterized by: a simple configuration, all inbound, outbound packets have been dispenser. When a large amount of data, the distribution network bottlenecks may occur! Thus a small number of RS supports.

 

 

VS / DR: direct routing mode, only the data flow inbound through distributor

Scheduler and real servers on the same network segment

Principle VS / DR model is: when a client sends a request to the VIP, a scheduler according to the VIP, a Real-server selection in real back-end server, and the request packet to the selected client Real-server, and finally select the Real-server package to reply directly to the client.

Features: scheduler solves the bottleneck problem lvs-NAT mode.

The following experimental procedure:

Scheduler: 192.168.26.130

Nx1: 192.168.26.129

nginx2: 192.168.26.128

 

Two RS server:

# ip addr add dev lo 192.168.26.123/32                                   
  //在lo接口上绑定VIP

# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore                 
 //non-arp:避免出现IP冲突

# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce          
 //RS以适当IP传输数据(让RS用VIP回复数据)

 

Because LVS and real server is configured with VIP, client or gateway device may arp learned mac LVS and real server, but also IP conflict occurs, and can not achieve load balancing. To prevent this from happening, and by the kernel parameter arp_ignore arp_announce configuration, only VIP LVS request response arp suppress arp real server requests and sending responses VIP free arp. (ARP can also be used to suppress the arptables)

nginx configuration process is skipped, just change points are indistinguishable on the line

 

Scheduler Operation:

# ip addr add dev lo 192.168.26.123/32

# yum -y install ipvsadm

# ipvsadm -C

# ipvsadm -A -t 192.168.26.123:80 -s rr

# ipvsadm -a -t 192.168.26.123:80 -r 192.168.26.129 -g

# ipvsadm -a -t 192.168.26.123:80 -r 192.168.26.128 -g

# ipvsadm -Ln

 

 

LVS scheduling algorithm:

LVS scheduling algorithm is used to decide how to choose the back end of RealServer

 

1. round-robin (Round Robin) (referred to as rr)

Scheduler through the "round-robin" scheduling algorithm external requests sequentially assigned to the cluster in turn in the real server, which equally treats each server, regardless of the actual number of connections on the server and the system load.

2. Weighted round robin (Weighted Round Robin) (referred WRR)

Scheduler through the "weighted round-robin" scheduling algorithm to schedule the access request depending on the processing capability of the real server. This will ensure a strong processing capacity of the server can handle more traffic. Queries scheduler may automatically load the real server, and dynamically adjusts the weight.

3. Least Connections (Least Connections) (LC)

Scheduler through the "minimum connection" scheduling algorithm dynamically network requests on a minimum number of links to the server schedule established. If the real server cluster systems have similar performance, the use of "minimum connection" scheduling algorithm can better balance the load.

4. Weighted Least link (Weighted Least Connections) (WLC)

Is large, the dispatcher uses the difference in performance server cluster system "Weighted Least link" scheduling algorithm to optimize load balancing performance, the server having a higher weight value will bear a greater proportion of negative active connection

Load. Queries scheduler may automatically load the real server, and dynamically adjusts the weight.

LVS's default scheduling algorithm.

The locality-based minimum link (Locality-Based Least Connections) (LBLC)

"Locality-Based Least Connections" scheduling algorithms for load balancing target IP address, the key for Cache cluster system. The algorithm to find the IP address of the target according to the most recently used destination IP address request

Server, if the server is available and is not overloaded, send a request to the server; if the server does not exist, or if the server is overloaded and have half the workload in the server, with the "minimum link"

The principle of selecting a server available, send a request to the server.

6. Based on Locality minimum band replication link (Locality-Based Least Connections with Replication) (LBLCR)

"Take copy of Locality-Based Least Connections" load balancing scheduling algorithm is also for the destination IP address, the key for Cache cluster system. It differs from the LBLC algorithm is that it wants to maintain a target from

IP addresses to a set of mapping server and LBLC algorithm maintains a mapping from a target IP address to a server. The algorithm to find the IP address of the target server group corresponding to the target IP address request, according to

"Minimum connection" elected by a server from a server group, if the server is not overloaded, send a request to the server; if the server is overloaded, according to "minimum connection" a principle selected from the cluster

Server, and the server group is added to the server, send a request to the server. Meanwhile, when the server group for some time not been modified, the busiest server is removed from the server group, in order to reduce the complexity

Degree system.

7. destination address hash (Destination Hashing) (DH)

"Target address hash" scheduling algorithm in accordance with the request destination IP address as the hash key (Hash Key) to find the corresponding server from the list of hash static allocation, if the server is overloaded and not available, the request is sent to the server, or null otherwise.

8. The source address hash (Source Hashing) (SH)

"Source address hash" scheduling algorithm according to the source IP address of the request, as the hash key (Hash Key) to find the corresponding server from the list of hash static allocation, if the server is overloaded and not available, the request is sent to the server, or null otherwise.

9. shortest expected delay (Shortest Expected Delay Scheduling SED) (SED)

Based wlc algorithm. This must be the example

ABC three machines are weights 123, 123 are also connections. So if you use WLC algorithm, then a new request comes in it may give any one of ABC. We will make such a calculation algorithm after using sed

A(1+1)/1

B(1+2)/2

C(1+3)/3

Based on the calculation result, the connection to C.

10. The minimum queue scheduling (Never Queue Scheduling NQ) (NQ)

No need to queue. If the number of connected realserver = 0 is assigned directly past, no operation is performed sed

 

 

Published 60 original articles · won praise 9 · views 30000 +

Guess you like

Origin blog.csdn.net/qq_44697035/article/details/104907093