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

   日期:2020-09-24     浏览:96    评论:0    
核心提示:通过一张张图走进DRDR模式图解简单拓扑图网络原理详解DR中ARP遇到的问题LVS-DR 负载均衡集群搭建网络环境配置调度器配置:192.168.100.23配置存储服务器:192.168.100.21配置节点服务器:192.168.100.24配置节点服务器:192.168.100.25访问测试DR模式图解简单拓扑图为方便进行原理分析,将Client与群集机器放在同一网络中,数据包流经的路线为1-2-3-4网络原理详解DR中ARP遇到的问题LVS-DR 负载均衡集群

通过一张张图走进DR

  • DR模式图解
      • 简单拓扑图
      • 网络原理详解
      • DR中ARP遇到的问题
  • LVS-DR 负载均衡集群搭建
      • 网络环境配置
      • 调度器配置:192.168.100.23
      • 配置存储服务器:192.168.100.21
      • 配置节点服务器:192.168.100.24
      • 配置节点服务器:192.168.100.25
      • 访问测试
      • 实验排错

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)
[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

配置存储服务器: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

配置节点服务器: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测试网站是否正常#

配置节点服务器: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测试网站是否正常#

访问测试


实验排错


####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
 
打赏
 本文转载自:网络 
所有权利归属于原作者,如文章来源标示错误或侵犯了您的权利请联系微信13520258486
更多>最近资讯中心
更多>最新资讯中心
0相关评论

推荐图文
推荐资讯中心
点击排行
最新信息
新手指南
采购商服务
供应商服务
交易安全
关注我们
手机网站:
新浪微博:
微信关注:

13520258486

周一至周五 9:00-18:00
(其他时间联系在线客服)

24小时在线客服