LVS

LVS is Linux Virtual Server, L4 load balancing implementation, high performance, stable and reliable, has become part of the Linux kernel, a famous open source project of Chinese Zhang Wensong

Architecture

Enter image description

Workflow

  • User > Loadbalance Director(包括一组LVS,master机/backup机互做Keepalived高可用) > RealServer集群 > SharedStorage
  • LoadBalancer provides external services through VIP. After the master goes down, the backup drifts the VIP to itself through the ARP protocol and takes over as the actual Director

Module composition

  • IPVS Kernel Scheduling Module: Deployed in Director, exposes VIP to the outside world, and forwards traffic to RealServer
  • Ipvsadm user space management module: deployed in Director, configure lvs scheduling mode and specify back-end services

IPVS load balancing mechanism

  • VS/NAT
  • VS/TUN
  • VS/DR: Best performance, but requires Director and Realserver to be on the same network segment

load balancing algorithm

static class

  • RR: Round Robin scheduler
  • WRR: Weighted Round Robin Weighted Round Robin Scheduling
  • SH: SourceIP Hash source address hash scheduling
  • DH: Destination Hash destination address hash scheduling

dynamic class

  • LC: Least Connections minimum number of links scheduling
  • WLC: Weighted Least Connection weighted minimum number of links scheduling
  • SED: Shortest Expection Delay minimum expected delay
  • NQ: Never Queue idle server scheduling
  • LBLC:locality based least connection
  • LBLCR:locality based least connection with replication

VS/DR mode configuration example

IP convention

  • CIP: User IP
  • VIP: Director's IP for external users
  • DIP: Director's IP for back-end business machines
  • RIP: business machine IP
### 网络约定 ###
# 192.168.0.99(VIP)、192.168.0.100(DIP)
# 192.168.0.101(RealServer1)

sudo yum install -y ipvsadm

## Director配置IP ##
ifconfig eth0:0 192.168.0.99/32 broadcast 192.168.0.99 up #网卡绑定VIP
route add -host 192.168.0.99 dev eth0:0 #网卡增加路由
echo 1>/proc/sys/net/ipv4/ip_forward #启动IP包转发

## Director配置IPVS调度规则 ##
ipvsadm -C #ipvsadm重置
ipvsadm -A -t 192.168.0.99:80 -s rr #添加VIP
ipvsadm -a -t 192.168.0.99:80 -r 192.168.0.101:80 -g #添加RealServer记录(-g为VS/DR模式)
ipvsadm -L -n #启动LVS服务并罗列规则

## RealServer配置 ##
ifconfig lo:0 192.168.0.99/32 broadcast 192.168.0.99 up #回环设备绑定VIP
route add -host 192.168.0.99 dev lo:0 #回环设备增加路由
echo 1 >/proc/sys/net/ipv4/conf/lo/arp_ignore #禁用ARP
echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore #禁用ARP
echo 2 >/proc/sys/net/ipv4/conf/lo/arp_announce #禁用ARP
echo 2 >/proc/sys/net/ipv4/conf/all/arp_announce #禁用ARP

## 访问服务 ##
curl 192.168.0.99:80

Keepalived

sudo yum install -y keepalived
{{o.name}}
{{m.name}}

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324132559&siteId=291194637
LVS
LVS
lvs
LVS
LVS