LVS load balancing cluster ---------- DR (direct routing) mode

Load balancing-DR mode

  • This time I mainly introduce the DR mode in load balancing.
    Direct routing (Direct Routing) is referred to as DR mode; it adopts a semi-open network structure, which is similar to the structure of the TUN mode, but the nodes are not scattered everywhere, but are located in the scheduler. The same physical network; the load scheduler and each node server are connected through the local network, without the need to establish a dedicated IP tunnel.

Insert picture description here

Network environment deployment

  • This time, we will use eNsp topology diagram + 5 virtual machines to build the demonstration
    Insert picture description here

  • Node server cluster
    1, an LVS scheduler (vm1 connection mode)
    change ip: 192.168.100.21/24 gateway: 192.168.100.1 restart the network card;

    2.
    Change the ip of the two node servers (vm1 connection mode) : 192.168.100.22/24 gateway: 192.168.100.1 and restart the network card;
    change the ip: 192.168.100.23/24 gateway: 192.168.100.1 and restart the network card;

    3. One NFS shared storage (vm1 connection mode)
    change ip: 192.168.100.24/24 gateway: 192.168.100.1 and restart the network card;

  • Client
    1. A virtual machine (client) of a windows system (vm2 connection mode) to
    change the URL of the network adapter ip: 192.168.200.100/24 ​​Gateway: 192.168.200.1

  • Real machine
    1. Change vm1 network card (used to connect to CRT) on real machine ,
    change ip: 192.168.100.2/24 Gateway: 192.168.100.1

  • Turn off the firewall, core protection of all virtual machines, and install local yum sources

Start configuring LVS — DR mode

Configure the LVS scheduler (192.168.100.21)

[1] Configure virtual IP address (VIP)

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# ll
[root@localhost network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[root@localhost network-scripts]# vi ifcfg-ens33:0
 
NAME=ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.100.100
NETMASK=255.255.255.255

[root@localhost network-scripts]# ifup ens33:0
[root@localhost network-scripts]# ip addr                ####查看 lo:0 接口上设的IP是否出现(我这是最小化安装的)

[2] Adjust /proc response parameters For DR cluster mode, since the LVS load scheduler and each node need to share the VIP address, the redirection parameter of the Linux kernel should be turned off. The response server is not a router, then it will not send redirection , So you can turn off this feature (response optimization)

[root@localhost ~]# vi /etc/sysctl.conf
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0

[root@localhost ~]# sysctl -p                   ####查看是否生效
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 0

[3] Configure load distribution strategy

[root@localhost /]# ipvsadm -v
[root@localhost ~]# modprobe ip_vs
[root@localhost ~]# cat /proc/net/ip_vs
[root@localhost ~]# yum -y install ipvsadm
[root@localhost ~]# ipvsadm -A -t 192.168.100.100:80 -s rr                #### 可以 ipvsadm -ln 查看下
[root@localhost ~]# ipvsadm -a -t 192.168.100.100:80 -r 192.168.100.22:80 -g -w 1
[root@localhost ~]# ipvsadm -a -t 192.168.100.100:80 -r 192.168.100.23:80 -g -w 1
[root@localhost ~]# ipvsadm-save > /opt/ipvsadm  

[root@localhost ~]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.100.100:80 rr
  -> 192.168.100.22:80            Route   1      0          0         
  -> 192.168.100.23:80            Route   1      0          0 

Configure NFS shared storage (192.168.100.24)

rpm -q nfs-utils    ###如果没装,yum -y install nfs-utils
rpm -q rpcbind      ###如果没装,yum -y install rpcbind

[root@localhost ~]# mkdir /opt/51xue /opt/52xue
[root@localhost ~]# echo 'i am superman 51xue' > /opt/51xue/index.html
[root@localhost ~]# echo 'you are pig 52xue' > /opt/52xue/index.html
[root@localhost ~]# vi /etc/exports                          #####添加下面二行(共享出去)
/opt/51xit 192.168.100.0/24 (rw,sync)           
/opt/52xit 192.168.100.0/24 (rw,sync)

[root@localhost ~]# systemctl start rpcbind
[root@localhost ~]# systemctl enable rpcbind
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# showmount -e
Export list for localhost.localdomain:
/opt/52xue 192.168.100.0/24
/opt/51xue 192.168.100.0/24

Configure the node server (192.168.100.22)

[1] Configure virtual IP address

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vi ifcfg-lo:0

DEVICE=lo:0
IPADDR=192.168.100.10
NETMASK=255.255.255.255
ONBOOT=yes

[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ip addr                   ####我是最小化安装
看看 lo:0 接口上设的IP是否出现

[root@localhost network-scripts]# vi /etc/rc.local 
/sbin/route add -host 192.168.100.100 dev lo:0                 ####在末尾添加

[root@localhost network-scripts]# route add -host 192.168.100.100 dev lo:0
( -bash: route: command not found     #### 出现这个报错就 yum -y install net-tools 安装这个工具)

[2] Adjust /proc response parameters

[root@localhost network-scripts]# vi /etc/sysctl.conf

net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2

[root@localhost network-scripts]# sysctl -p                    ####查看是否生效
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2

[3] Install httpd mount test page

[root@localhost ~]# yum -y install httpd
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# yum -y install nfs-utils
[root@localhost ~]# mount 192.168.100.24:/opt/51xue /var/www/html/
[root@localhost ~]# df -Th                       ####查看挂载情况
[root@localhost ~]# vi /etc/fstab 
192.168.100.24:/opt/51xue /var/www/html nfs defaults,_netdev 0 0        ###开机自动挂载,注意格式对齐
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# systemctl enable nfs

[root@localhost ~]# showmount -e 192.168.100.24        ####如果还没发布,请到存储服务器发布下,exportfs -rv(如果报错就是配置出错了)
Export list for 192.168.100.24:
/opt/52xue 192.168.100.0/24
/opt/51xue 192.168.100.0/24
  • Log in to 192.168.100.22 to test whether the website is normal.
    Real machine test:
    Insert picture description here
    client test:
    Insert picture description here

Configure the node server (192.168.100.23)

[1] Configure virtual IP address

[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[root@localhost network-scripts]# cp ifcfg-lo ifcfg-lo:0
[root@localhost network-scripts]# vi ifcfg-lo:0

DEVICE=lo:0
IPADDR=192.168.100.100
NETMASK=255.255.255.255
ONBOOT=yes

[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ip addr              ####我是最小化安装
看看 lo:0 接口上设的IP是否出现

[root@localhost network-scripts]# vi /etc/rc.local 
/sbin/route add -host 192.168.100.100 dev lo:0                ####在末尾添加

[root@localhost network-scripts]# route add -host 192.168.100.100 dev lo:0
( -bash: route: command not found     #### 出现这个报错就 yum -y install net-tools 安装这个工具)

[2] Adjust /proc response parameters

[root@localhost network-scripts]# vi /etc/sysctl.conf

net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2

[root@localhost network-scripts]# sysctl -p                 ####查看是否生效

   ...............

[3] Install httpd mount test page

[root@localhost ~]# yum -y install httpd
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
[root@localhost ~]# yum -y install nfs-utils
[root@localhost ~]# mount 192.168.100.24:/opt/52xue /var/www/html/
[root@localhost ~]# df -Th                       ####查看挂载情况
[root@localhost ~]# vi /etc/fstab 
192.168.100.24:/opt/52xue /var/www/html nfs defaults,_netdev 0 0        ###开机自动挂载,注意格式对齐
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# systemctl enable nfs

[root@localhost ~]# showmount -e 192.168.100.24     
Export list for 192.168.100.24:
/opt/52xue 192.168.100.0/24
/opt/51xue 192.168.100.0/24
  • Log in to 192.168.100.23 to test whether the website is normal.
    Real machine test:
    Insert picture description here
    client test:
    Insert picture description here

Client test LVS load balancing

Insert picture description here
Insert picture description here

  • Real machine test
    Insert picture description here
    Insert picture description here

Guess you like

Origin blog.csdn.net/XCsuperman/article/details/108744813