LVS introduction and NAT mode configuration and implementation of Linux Enterprise load cluster

1, Introduction to LVS
1.LVS(Linux Virtual Server), load scheduler, kernel integration
2.LVS architecture
The server cluster system based on LVS architecture consists of three parts: Loader balancer (load balancing layer), server array (middle server group layer) and shared storage (data shared storage layer).

3. Working principle of LVS

  • When users visit www.sina.com com. Cn, the user data passes through the layer by layer network, and finally enters the LVS server network card through the switch, and enters the kernel network layer.
  • After entering preouting, through route search, it is determined that the destination VIP is the local IP address, so the data packet enters the INPUT chain.
  • IPVS works on the INPUT chain. It will judge whether the request is an IPVS service according to the accessed vip+port. If so, call the registered IPVS HOOK function to carry out IPVS related main processes, forcibly modify the relevant data of the data packet, and send the data packet to the POSTROUTING chain.
  • After receiving the data packet on POSTROUTING, the data packet is finally sent to the back-end server through routing according to the target IP address (back-end server)

4.LVS scheduling algorithm
There are two methods: static method and dynamic method
4.1 static method: schedule only according to the algorithm itself

  • RR: roundrobin, polling, commonly used
  • WRR: Weighted RR, which is commonly used for weighted polling
  • SH: Source Hashing, which implements session sticky and source IP address hash; The request from the same IP address is always sent to the RS selected for the first time, so as to realize session binding
  • DH: Destination Hashingï¼› The hash of the target address is polled and scheduled to the RS for the first time, and the subsequent requests to the same target address are always forwarded to the RS selected for the first time. The typical use scenario is load balancing in the forward proxy cache scenario, such as Web cache

4.2 dynamic method: it is mainly scheduled according to the current load state and scheduling algorithm of each rs. the RS with smaller Overhead=value will be scheduled

  • LC: least connections is suitable for long connection applications. 2. WLC: Weighted LC, the default scheduling method, is more commonly used
  • SED: short expectation delay. The initial connection has high weight first. Only active connections are checked, and inactive connections are not considered
  • NQ: Never Queue, first round of uniform distribution, subsequent SED
  • LBLC: locality based LC, dynamic DH algorithm, usage scenario: implement forward proxy and Web Cache according to load status
  • LBLCR: LBLC with Replication, LBLC with Replication function, solve the problem of LBLC load imbalance, from replication with negative load to RS with light load, and realize Web Cache, etc

5. Three working modes

  • NAT mode
  • DR mode
  • TUN mode

2, LVS-NAT mode of LVS working mode
1.LVS-NAT working mode: in essence, it is a multi-target DNAT, which modifies the target IP and Port in the request message to RIP and Port of RS

  • RIP and DIP shall be on the same IP network, and private network address shall be used; The gateway of RS should point to DIP
  • Both request message and response message must be forwarded through Director, which is easy to become the bottleneck of the system
  • Support PORT mapping and modify the target PORT of the request message
  • VS must be a Linux system, and RS can be any OS system

    2.NAT mode configuration and Implementation
    2.1 experimental platform
Client: 192.168.0.6/24
LVS:
	eth0: Host only,192.168.0.10/24
	eth1: NAT,10.0.0.8/24
RS1: 10.0.0.7/24	GW:10.0.0.8/24
RS2: 10.0.0.9/24	GW:10.0.0.8/24

2.2 experimental steps
(1) Experimental environment configuration

  • Install http service for RS1 and RS2 and test the Web page. Refer to this blog configuration, click here , set RS1 and RS2 gateways
#/Added in / etc / sysconfig / network scripts / ifcfg-ens33 to configure
GATEWAY=10.0.0.8
systemctl restart network
route -n #View route
  • Client configuration
#/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=192.168.0.6
ONBOOT=yes
PREFIX=24

systemctl restart network
route -n #View route
  • Configure eth0 and eth1 for LVS and install ipvsadm
#/etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
NAME=eth0
BOOTPROTO=static
IPADDR=192.168.0.10
ONBOOT=yes
PREFIX=24

#/etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
NAME=eth1
BOOTPROTO=static
IPADDR=10.0.0.8
ONBOOT=yes
PREFIX=24

#Modify / etc / sysctl Conf, otherwise, when LVS returns a response, you cannot connect from LVS to the internet
net.ipv4.ip_forward = 1 #Enable IP control IP packet forwarding
#Command view
sysctl -p

(2) Configuration mode and scheduling algorithm on LVS server

#eth0/VIP,-A: add, - t:tcp protocol, - s: scheduling algorithm WRR (weighted polling)
ipvsadm -A -t 192.168.0.10:80 -s wrr
#RS1 and RS2 in the management cluster, - m:NAT mode, - w: weight
ipvsadm -a -t 192.168.0.10:80 -r 10.0.0.7 -m -w 3
ipvsadm -a -t 192.168.0.10:80 -r 10.0.0.9 -m -w 2

ipvsadm -Ln

(3) Save the mode and scheduling algorithm rules on the LVS server, which is valid after startup

ipvsadm -Sn > /etc/sysconfig/ipvsadm
systemctl enable --now ipvsadm.service

Please refer to the blog Click here
Make progress in your study. If you make mistakes, please criticize and correct them

Keywords: Linux Operation & Maintenance network server

Added by Z3roDowner on Sat, 29 Jan 2022 17:30:41 +0200