LVS-DR群集:直连路由群集理论知识+实验部署 图片一张一张分析原理!

DR模式图解

简单拓扑图

在这里插入图片描述
为方便进行原理分析,将Client与群集机器放在同一网络中,数据包流经的路线为1-2-3-4
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

网络原理详解

在这里插入图片描述

DR中ARP遇到的问题

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

LVS-DR 负载均衡集群搭建

网络环境配置

一台调度器: VM1:192.168.100:23 网关:不需要或者 192.168.100.1
二台WEB服务器集群池: 192.168.100.24 网关:不需要或者 192.168.100.1
192.168.100.25 网关:不需要或者 192.168.100.1
一台NFS共享服务器: 192.168.100.21 192.168.100.1
虚拟VIP: 192.168.100.88
其他: VM1网卡为仅主机模式 笔记本VM1 IP为:192.168.100.1

调度器配置:192.168.100.23

如果你是最小化安装 需要 yum -y install net-tools
我们要使用ifconfig这条命令,所有服务器全都要装

1】配置虚拟IP地址(VIP)
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[[email protected] network-scripts]# vi ifcfg-ens33:0
NAME=ens33:0
DEVICE=ens33:0
ONBOOT=yes
IPADDR=192.168.100.88
NETMASK=255.255.255.255

[[email protected] network-scripts]# ifup ifcfg-ens33:0
[[email protected] 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 内核的重定向参数响应
服务器不是一台路由器,那么它不会发送重定向,所以可以关闭该功能
[[email protected] 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

#生效
[[email protected] 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】配置负载分配策略
[[email protected] /]# ipvsadm -v                            #检查内核是否支持

[[email protected] ~]#yum -y install ipvsadm        
[[email protected] ~]# modprobe ip_vs                 
[[email protected] ~]# cat /proc/net/ip_vs
[[email protected] ~]#yum -y install ipvsadm

[[email protected] ~]# ipvsadm -A -t 192.168.100.88:80 -s rr
[[email protected] ~]# ipvsadm -a -t 192.168.100.88:80 -r 192.168.100.24:80 -g
[[email protected] ~]# ipvsadm -a -t 192.168.100.88:80 -r 192.168.100.25:80 -g 
[[email protected] network-scripts]# ipvsadm-save > /opt/ipvsadm

[[email protected] ~]# systemctl start ipvsadm
[[email protected] network-scripts]# systemctl enable ipvsadm

配置存储服务器:192.168.100.21

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


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

[[email protected] ~]# mkdir /opt/51xit /opt/52xit
[[email protected] ~]# echo "51是我" >/opt/51xit/index.html                 
[[email protected] ~]# echo "我是52" >/opt/52xit/index.html

[[email protected] ~]# vi /etc/exports
/opt/51xit 192.168.100.0/24(rw,sync)
/opt/52xit 192.168.100.0/24(rw,sync)


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

配置节点服务器:192.168.100.24

1】配置虚拟IP地址
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-lo ifcfg-lo:0
[[email protected] network-scripts]# vi ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.100.88
NETMASK=255.255.255.255
ONBOOT=yes


[[email protected] network-scripts]# ifup lo:0
[[email protected] 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
[[email protected] network-scripts]# vi /etc/rc.local 
/sbin/route add -host 192.168.100.88 dev lo:0

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

[[email protected] 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响应参数
[[email protected] 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


#生效
[[email protected] network-scripts]# sysctl -p

【3】安装httpd 挂载测试页
[[email protected] ~]# 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

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

[[email protected] ~]# systemctl start httpd
[[email protected] ~]# systemctl enable httpd

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

配置节点服务器:192.168.100.25

1】配置虚拟IP地址
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-lo ifcfg-lo:0
[[email protected] network-scripts]# vi ifcfg-lo:0
DEVICE=lo:0
IPADDR=192.168.100.88
NETMASK=255.255.255.255
ONBOOT=yes

[[email protected] network-scripts]# ifup lo:0
[[email protected] 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)
[[email protected] network-scripts]# vi /etc/rc.local 
/sbin/route add -host 192.168.100.10 dev lo:0

[[email protected] network-scripts]# route add -host 192.168.100.88 dev lo:0

[[email protected] 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响应参数
[[email protected] 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

[[email protected] network-scripts]# sysctl -p

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

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

[[email protected] ~]# systemctl start httpd
[[email protected] ~]# systemctl enable httpd

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

访问测试

在这里插入图片描述
在这里插入图片描述

实验排错


####RPC--注册问题###
[[email protected] ~]# showmount -e
clnt_create: RPC: Program not registered

解决方案:
[[email protected] ~]# systemctl stop nfs       
[[email protected] ~]# systemctl stop rpcbind
[[email protected] ~]# systemctl start rpcbind	###再次启动
[[email protected] ~]# systemctl start nfs
[[email protected] ~]# 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
[[email protected] 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		###添加虚拟服务器数据异常###

[[email protected] ~]# 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

猜你喜欢

转载自blog.csdn.net/weixin_48190891/article/details/108751893

相关文章