LVS-DR cluster: direct connection routing cluster theoretical knowledge + experimental deployment pictures one by one analysis principle!

DR mode diagram

Simple topology diagram

Insert picture description here
In order to facilitate the principle analysis, put the Client and the cluster machine on the same network, and the route of the data packet flow is 1-2-3-4
Insert picture description here
Insert picture description here
Insert picture description here

Insert picture description here
Insert picture description here

Detailed network principle

Insert picture description here

Problems encountered by ARP in DR

Insert picture description here

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

LVS-DR load balancing cluster construction

Network environment configuration

A scheduler: VM1:192.168.100:23 Gateway: not required or 192.168.100.1
Two WEB server cluster pool: 192.168.100.24 Gateway: not required or 192.168.100.1
192.168.100.25 Gateway: not required or 192.168.100.1
An NFS shared server: 192.168.100.21 192.168.100.1
Virtual VIP: 192.168.100.88
other: VM1 NIC is in host-only mode The IP of the laptop VM1 is: 192.168.100.1

Scheduler configuration: 192.168.100.23

If you need yum -y install net-tools for minimal installation,
we will use the ifconfig command, all servers must be installed

1】配置虚拟IP地址(VIP)
[root@localhost ~]# cd /etc/sysconfig/network-scripts/
[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.88
NETMASK=255.255.255.255

[root@localhost network-scripts]# ifup ifcfg-ens33:0
[root@localhost network-scripts]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.23  netmask 255.255.255.0  broadcast 192.168.32.255
        .....
        
ens33:0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.100.88  netmask 255.255.255.0  broadcast 192.168.32.255
        ether 00:0c:29:9b:a7:cc  txqueuelen 1000  (Ethernet)

#【2】调整/proc响应参数  对于 DR 群集模式来说,由于 LVS 负载调度器和各节点需要共用 VIP 地址,
#应该关闭 Linux 内核的重定向参数响应
服务器不是一台路由器,那么它不会发送重定向,所以可以关闭该功能
[root@localhost network-scripts]# 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 network-scripts]# sysctl -p     
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.ens33.send_redirects = 03】配置负载分配策略
[root@localhost /]# ipvsadm -v                            #检查内核是否支持

[root@localhost ~]#yum -y install ipvsadm        
[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.88:80 -s rr
[root@localhost ~]# ipvsadm -a -t 192.168.100.88:80 -r 192.168.100.24:80 -g
[root@localhost ~]# ipvsadm -a -t 192.168.100.88:80 -r 192.168.100.25:80 -g 
[root@localhost network-scripts]# ipvsadm-save > /opt/ipvsadm

[root@localhost ~]# systemctl start ipvsadm
[root@localhost network-scripts]# systemctl enable ipvsadm

Configure storage server: 192.168.100.21

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


###最好先启动rpcbind,不然有时会报错
[root@localhost ~]# systemctl restart rpcbind        
[root@localhost ~]# systemctl start nfs

[root@localhost ~]# mkdir /opt/51xit /opt/52xit
[root@localhost ~]# echo "51是我" >/opt/51xit/index.html                 
[root@localhost ~]# echo "我是52" >/opt/52xit/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)


 ###最好先重启rpcbind,不然有时会报错
[root@localhost ~]# systemctl restart rpcbind
[root@localhost ~]# systemctl restart nfs
[root@localhost ~]# systemctl enable nfs
[root@localhost ~]# systemctl enable rpcbind

Configure the node server: 192.168.100.24

1】配置虚拟IP地址
[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.88
NETMASK=255.255.255.255
ONBOOT=yes


[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ifconfig
lo:0: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.100.10  netmask 255.255.255.255
        loop  txqueuelen 1000  (Local Loopback)

##添加本地访问路由,这个是一个脚本,相当于开机自动执行 route add -host 192.168.100.88 dev lo:0
[root@localhost network-scripts]# vi /etc/rc.local 
/sbin/route add -host 192.168.100.88 dev lo:0

##手动先敲,敲完不能restart network,不然这个本地路由会消失,你需要重新添加
[root@localhost network-scripts]# route add -host 192.168.100.88 dev lo:0

[root@localhost network-scripts]# route -n
Destination     Gateway           Genmask        Flags    Metric  Ref  Use  Iface
0.0.0.0        192.168.100.1      0.0.0.0         UG       100    0   0    ens33
192.168.100.0     0.0.0.0        255.255.255.0     U       100    0   0    ens33
192.168.100.88    0.0.0.0        255.255.255.255  UH        0     0        lo


【2】调整/proc响应参数
[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】安装httpd 挂载测试页
[root@localhost ~]# showmount -e 192.168.100.21 
Export list for 192.168.100.21:
/opt/52xit 192.168.100.0/24
/opt/51xit 192.168.100.0/24

[root@localhost ~]# yum -y install httpd
[root@localhost ~]# mount 192.168.100.21:/opt/51xit /var/www/html/
[root@localhost ~]# vi /etc/fstab 
192.168.100.21:/opt/51xit /var/www/html/ nfs defaults,_netdev 0 0

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd

#登录192.168.100.24测试网站是否正常#

Configure the node server: 192.168.100.25

1】配置虚拟IP地址
[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.88
NETMASK=255.255.255.255
ONBOOT=yes

[root@localhost network-scripts]# ifup lo:0
[root@localhost network-scripts]# ifconfig

lo:0: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 192.168.100.10  netmask 255.255.255.255
        loop  txqueuelen 1000  (Local Loopback)
[root@localhost network-scripts]# vi /etc/rc.local 
/sbin/route add -host 192.168.100.10 dev lo:0

[root@localhost network-scripts]# route add -host 192.168.100.88 dev lo:0

[root@localhost network-scripts]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.100.1   0.0.0.0         UG    100    0        0 ens33
192.168.100.0   0.0.0.0         255.255.255.0   U     100    0        0 ens33
192.168.100.88  0.0.0.0         255.255.255.255 UH    0      0        0 lo

【2】调整/proc响应参数
[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

【2】安装httpd 挂载测试页
[root@localhost ~]# showmount -e 192.168.100.21    
Export list for 192.168.100.44:
/opt/accp  (everyone)
/opt/bdqn (everyone)

[root@localhost ~]# yum -y install httpd
[root@localhost ~]# mount 192.168.100.21:/opt/52xit /var/www/html/
[root@localhost ~]# vi /etc/fstab 
192.168.100.21:/opt/52xit /var/www/html/ nfs defaults,_netdev 0 0
  

[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd

#登录192.168.100.43测试网站是否正常#

Access test

Insert picture description here
Insert picture description here

Experiment troubleshooting


####RPC--注册问题###
[root@localhost ~]# showmount -e
clnt_create: RPC: Program not registered

解决方案:
[root@localhost ~]# systemctl stop nfs       
[root@localhost ~]# systemctl stop rpcbind
[root@localhost ~]# systemctl start rpcbind	###再次启动
[root@localhost ~]# systemctl start nfs
[root@localhost ~]# showmount -e
Export list for localhost.localdomain:
/opt/52xit 20.0.0.0/24
/opt/51xit 20.0.0.0/24


######问题: /etc/sysconfig/ipvsadm: No such ...ry####
解决方案:ipvsadm --save > /etc/sysconfig/ipvsadm
[root@localhost opt]# systemctl status ipvsadm.service 	###查看ipvsadm是否工作正常
● ipvsadm.service - Initialise the Linux Virtual Server
   Loaded: loaded (/usr/lib/systemd/system/ipvsadm.service; enabled; vendor preset: disabled)
   Active: active (exited) since Mon 2020-09-21 23:47:17 EDT; 19min ago
  Process: 18092 ExecStart=/bin/bash -c exec /sbin/ipvsadm-restore < 
  /etc/sysconfig/ipvsadm (code=exited, status=0/SUCCESS)
 Main PID: 18092 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/ipvsadm.service



#####问题:TCP  127.0.0.1:80 rr		###添加虚拟服务器数据异常###

[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  127.0.0.1:80 rr		###添加虚拟服务器数据异常
  -> 192.168.100.21:80            Route   1      0          0         
  -> 192.168.100.22:80            Route   1      0          0 


###如何解决,清空重新添加###
ipvsadm -C
ipvsadm -A -t 192.168.100.100:80 -s rr
ipvsadm -a -t 192.168.100.100:80 -r 192.168.100.22:80 -g -w 1
ipvsadm -a -t 192.168.100.100:80 -r 192.168.100.23:80 -g -w 1
ipvsadm --save > /etc/sysconfig/ipvsadm

Guess you like

Origin blog.csdn.net/weixin_48190891/article/details/108751893