当前位置:网站首页>部署LVS-DR群集
部署LVS-DR群集
2022-08-04 18:08:00 【世上无难事754】
部署LVS-DR群集
LVS-DR数据包流向分析
为方便进行原理分析,将Client与群集机器放在同一网
络中数据包流经的路线为1-2-3-4

1、Client向目标VIP发出请求,Director(负载均衡器)接收
IP包头及数据帧头信息

2、Director根据负载均衡算法选择RealServer_1,不修改也不封装IP报文,而是将数据帧的MAC地址改为RealServer1的MAC地址,然后在局域网上发送

3、RealServer_1收到这个帧,解封装后发现目标lP与本机匹配(RealServer事先绑定了VP),于是处理这个报文。随后重新封装报文,发送到局域网

4、Client将收到回复报文。Clienti认为得到正常的服务,而不会知道是哪一台服务器处理的
LVS-DR中的ARP问题
在LVS-DR负载均衡集群中,负载均衡器与节点服务器都要配置相同的VIP地址
数据包流向分析:
(1)客户端发送请求到Director Server(负载均衡器),请求的数据报文(源IP是CIP,目标IP是IP)到达内核空间。
(2)Director Server Real Server
在同一个网络中,数据通过二层数据链路层来传输。
(3)内核空间判断数据包的目标IP是本机VIP,此时IPVS(IP虚拟服务器)比对数据包请求的服务是否是集群服务,是集群服务就重新封装数据包。修改源MAC地址为Director Server的MAC地址,修改目标MAC地址为Real Server的MAC地址,源IP地址与目标IP地址没有改变,然后将数据包发送给Real Server。
(4)到达Real Server的请求报文的MAC地址是自身的MAC地址,就接收此报文。数据包重新封装报文(源IP地址为VIP,目标IP为CIP),将响应报文通过1。接口传送给物理网卡然后向外发出。
(5)Real Server直接将响应报文传送到客户端。
DR模式的特点:
(1)Director Server和Real Server必须在同一个物理网络中。
(2)Real Server
可以使用私有地址,也可以使用公网地址。如果使用公网地址,可以通过互联网对RIP进行直接访问。
(3)Director Server作为群集的访问入口,但不作为网关使用。
(4)所有的请求报文经由Director Server,但回复响应报文不能经过Director Server.
(5)Real Server的网关不允许指向Director Server IP,即Real
Server:发送的数据包不允许经过 Director Server。
(6)Real Server上的lo接口配置VIP的IP地址。
LVS-DR中的ARP问题
1、在局域网中具有相同的P地址,势必会造成各服务器ARP通信的紊乱
当ARP广播发送到LVS-DR集群时,因为负载均衡衡器和节点服务器都是连接到相同的网路上,它们都会接收到ARP广播
只有前端的负载均衡器进行响应,其他节点服务器不应该响应ARP广播

2、对节点服务器进行处理,使其不响应针对VIP的ARP请求
使用虚接口lo:0承载VIP地址
设置内核参数arp_ignore=1:系统只响应目的IP为本地IP的ARP请求
3、RealServeri返回报文(源P是VIP)经路由器转发,重新封装报文时
需要先获取路由器的MAC地址
发送ARP请求时,Linux默认使用IP包的源P地址(即VIP)作为ARP请
求包中的源P地址,而不使用发送接口的P地址
4、路由器收到ARP请求后,将更新ARP表项
原有的W4P对应Director的MAC地址会被更新为P对应RealServer的MAC地址
5、问题
路由器根据ARP表项,会将新来的请求报文转发给RealServer,导致
Director的VIP失效
解决方法
对节点服务器进行处理,设置内核参数arp announce:=2:系统不使用IP包的源地址来设置ARP请求的源地址,而选择发送接口的P地址
1、arp ingore=1
防止网关路由器发送ARP广播时调度器和节点服务器都进行响应,这个会导致ARP缓存表混乱,不对非本地物理网卡IP的ARP请求响应,因为VIP是承载lo:0
2、arp announce=2
系统不使用响应的数据的源IP地址(VIP),而使用发送报文的物理网卡IP地址作为ARP请求的报文的源IP地址,这样可以防止网关路由器接受到的源IP地址为VIP的ARP请求报文后又更新ARP缓存表,导致外网再发送请求时,数据包到达不了调度器

LVS-DR实验
在192.168.35.10这台负载均衡设备上
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-ens33 ifcfg-ens33:0
[[email protected] network-scripts]# vim ifcfg-ens33:0
DEVICE="ens33:0"
ONBOOT="yes"
IPADDR=192.168.35.180
NETMASK=255.255.255.255
[[email protected] network-scripts]# systemctl restart netstart
改内核参数
[[email protected] network-scripts]# vim /etc/sysctl.conf
加在行尾
net.ipv4.ip_forward = 0
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
查看一下版本
[[email protected] network-scripts]# modprobe ip_vs
[[email protected] network-scripts]# 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
[[email protected] network-scripts]# yum install -y ipvsadm
[[email protected] network-scripts]# ipvsadm-save > /etc/sysconfig/ipvsadm
[[email protected] network-scripts]# systemctl start ipvsadm.service
清空一下
[[email protected] network-scripts]# ipvsadm -C
[[email protected] network-scripts]# ipvsadm -A -t 192.168.35.180:80 -s rr
[[email protected] network-scripts]# ipvsadm -a -t 192.168.35.180:80 -r 192.168.35.7:80 -g
[[email protected] network-scripts]# ipvsadm -a -t 192.168.35.180:80 -r 192.168.35.8:80 -g
查看一下是否连接成功
[[email protected] network-scripts]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP localhost.localdomain:http rr
-> 192.168.35.7:http Route 1 0 0
-> 192.168.35.8:http Route 1 0 0
打开192.168.35.7和192.168.35.8的机器
[[email protected] ~]# cd /etc/sysconfig/network-scripts/
[[email protected] network-scripts]# cp ifcfg-lo ifcfg-lo:0
[[email protected] network-scripts]# vim ifcfg-lo:0
DEVICE=lo:0
ONBOOT=yes
IPADDR=192.168.35.180
NETMASK=255.255.255.255
[[email protected] network-scripts]# systemctl restart network
[[email protected] network-scripts]# route add -host 192.168.35.180 dev lo:0
查看一下
[[email protected] network-scripts]# route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default gateway 0.0.0.0 UG 100 0 0 ens33
192.168.35.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
localhost.local 0.0.0.0 255.255.255.255 UH 0 0 0 lo
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
[[email protected] network-scripts]# vim /etc/sysctl.conf
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
刷新一下
[[email protected] network-scripts]# sysctl -p

.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
刷新一下
[[email protected] network-scripts]# sysctl -p
[外链图片转存中...(img-2KCOsSp5-1659442314519)]

边栏推荐
- Thrift installation configuration
- PT100铂热电阻三种测温方法介绍
- 工业元宇宙对工业带来的改变
- Introduction of three temperature measurement methods for PT100 platinum thermal resistance
- 企业调查相关性分析案例
- EasyCVR调用云端录像API接口返回错误且无录像文件生成,是什么原因?
- The Industrial Metaverse Brings Changes to Industry
- Google Earth Engine APP - one-click online viewing of global images from 1984 to this year and loading an image analysis at the same time
- 群友求助,一周没有搞定的需求,3分钟就解决了?
- 关于大学生内卷的文献综述
猜你喜欢

Matlab画图1

2019 Haidian District Youth Programming Challenge Activity Elementary Group Rematch Test Questions Detailed Answers

LVS+Keepalived群集

About the two architectures of ETL (ETL architecture and ELT architecture)

A group of friends asked for help, but the needs that were not solved in a week were solved in 3 minutes?

合宙Cat1 4G模块Air724UG配置RNDIS网卡或PPP拨号,通过RNDIS网卡使开发板上网(以RV1126/1109开发板为例)

Flink/Scala - Storing data with RedisSink

2019年海淀区青少年程序设计挑战活动小学组复赛试题详细答案

(ECCV-2022)GaitEdge:超越普通的端到端步态识别,提高实用性

Thrift IDL示例文件
随机推荐
How does EasyCVR call the double-speed playback of device recording through the interface?
LeetCode 899. 有序队列
buuctf(探险1)
mysql cdc 为什么需要RELOAD 这个权限?这个权限在采集数据的过程中的作用是什么?有哪
华为云计算HCIE之oceanstor仿真器的安装教程
【STM32】STM32单片机总目录
CAS:385437-57-0,DSPE-PEG-Biotin,生物活性分子磷脂-聚乙二醇-生物素
Investigation and Research Based on the Involution Behavior of College Students
A group of friends asked for help, but the needs that were not solved in a week were solved in 3 minutes?
clickhouse 上下线表
darknet源码阅读笔记-02-list.h和lish.c
不论你是大众,科班和非科班,我这边整理很久,总结出的学习路线,还不快卷起来
leetcode/有效的回文串,含有不需要判断回文的字符
leetcode 13. 罗马数字转整数
Boosting之GBDT原理
【web自动化测试】Playwright快速入门,5分钟上手
CAN光纤转换器CAN光端机解决消防火灾报警
asp dotnet core 通过图片统计 csdn 用户访问
从-99打造Sentinel高可用集群限流中间件
使用bash语句,清空aaa文件夹下的所有文件