Load balancing cluster LVS—DR deployment

Load balancing cluster LVS—DR deployment

LVS—DR working principle

  • Overview of DR mode

1. Load balancing cluster working mode-direct routing
2. Referred to as DR mode, it adopts a semi-open network structure, which is similar to the structure of TUN mode, but the nodes are not scattered everywhere, but are located on the same physical network as the scheduler
3. The load scheduler is connected to each node server through the local network, without the need to establish a dedicated IP tunnel

Deploy LVS-DR mode

Install nfs and rpcbind on yum on the nfs machine and
then create the web directory

[root@nfs ~]# rpm -qa | grep nfs
nfs-utils-1.3.0-0.48.el7.x86_64
libnfsidmap-0.25-17.el7.x86_64
nfs4-acl-tools-0.3.3-15.el7.x86_64
[root@nfs ~]# rpm -qa | grep rpcbindrpcbind-0.2.0-42.el7.x86_64
[root@nfs ~]# mkdir /web1
[root@nfs ~]# mkdir /web2
[root@nfs ~]# echo  "</h1>this is web1.</h1>" > /web1/index.html
[root@nfs ~]# echo  "</h1>this is web2.</h1>" > /web2/index.html
[root@nfs ~]# echo /web1/index.html /web1/index.html
[root@nfs ~]# vi /etc/exports
[root@nfs ~]# systemctl restart nfs
[root@nfs ~]# systemctl restart rpcbind
[root@nfs ~]# showmount -e
Export list for nfs:
/web2 (everyone)
/web1 (everyone)

Mount first on the web1 machine

[root@web1 ~]# mount 192.168.100.13:/web1 /var/www/html/
[root@web1 ~]# systemctl start httpd
[root@web1 ~]# curl http://localhost
</h1>this is web1.</h1>

Write shell script

[root@web1 ~]# vi web1.sh
#!/bin/bash
#lvs dr 模式
ifconfig lo:0 192.168.100.200 broadcast 192.168.100.200 netmask 255.255.255.255 up
route add -host 192.168.100.200 dev lo:0
echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p &> /dev/null

Insert picture description here
[root@web1 ~]# ifconfig
Insert picture description here
[root@web1 ~]# route -n
Insert picture description here
web2
install ipvsadm on the scheduler with web1

[root@lvs ~]# modprobe ip_vs
[root@lvs ~]# cat /proc/net/ip_vs
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port Forward Weight ActiveConn InActConn
[root@lvs ~]# yum -y install ipvsadm
编写shell脚本
[root@lvs ~]# vi dr.sh
#!/bin/bash
#lvs 调度器
ifconfig ens33:0 192.168.100.200 broadcast 192.168.100.200 netmask 255.255.255.255 up
route add -host 192.168.100.200 dev ens33:0
ipvsadm -C
ipvsadm -A -t 192.168.100.200:80 -s rr
ipvsadm -a -t 192.168.100.200:80 -r 192.168.100.11:80 -g
ipvsadm -a -t 192.168.100.200:80 -r 192.168.100.12:80 -g
ipvsadm -Ln

Insert picture description here
Enter the virtual ip on the web page http://192.168.100.200
Insert picture description here
[root@lvs ~]# ipvsadm -Lnc
IPVS connection entries
pro expire state source virtual destination
TCP 14:49 ESTABLISHED 192.168.100.3:56090 192.168.100.200:80 192.168.100.11 :80
TCP 01:57 FIN_WAIT 192.168.100.3:56089 192.168.100.200:80 192.168.100.12:80
Insert picture description here

Enter the virtual ip http://192.168.100.200 on the client
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_50346902/article/details/110878160