当前位置:网站首页>部署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)]

边栏推荐
- asp dotnet core 通过图片统计 csdn 用户访问
- 关于ETL的两种架构(ETL架构和ELT架构)
- 谷歌开源芯片 180 纳米制造工艺
- C#爬虫之通过Selenium获取浏览器请求响应结果
- 智能视频监控平台EasyCVR如何使用接口批量导出iframe地址?
- 离线同步odps到mysql 中文乱码是因为?mysql已是utf8mb4
- 【web自动化测试】Playwright快速入门,5分钟上手
- 基于层次分析法的“内卷”指数分析
- "No title"
- Develop those things: How to obtain the traffic statistics of the monitoring site through the EasyCVR platform?
猜你喜欢

基于激励的需求响应计划下弹性微电网的短期可靠性和经济性评估(Matlab代码实现)

《中国综合算力指数》《中国算力白皮书》《中国存力白皮书》《中国运力白皮书》在首届算力大会上重磅发出

After EasyCVR is locally connected to the national standard device to map the public network, the local device cannot play and cascade the solution

斯坦福:未来的RGB LED可以贴在你的皮肤上

报道称任天堂在2023年3月前不会推出任何新硬件产品

Flask framework implementations registered encryption, a Flask enterprise class learning 】 【

什么是网站监控,网站监控软件有什么用?

从-99打造Sentinel高可用集群限流中间件

ptables基本语法使用规则

Investigation and Research Based on the Involution Behavior of College Students
随机推荐
力扣学习---0804
2019年海淀区青少年程序设计挑战活动小学组复赛试题详细答案
Hezhou Cat1 4G module Air724UG is configured with RNDIS network card or PPP dial-up, and the development board is connected to the Internet through the RNDIS network card (taking the RV1126/1109 devel
EasyCVR如何通过接口调用设备录像的倍速回放?
群友求助,一周没有搞定的需求,3分钟就解决了?
谁能解答?从mysql的binlog读取数据到kafka,但是数据类型有Insert,updata,
ptables基本语法使用规则
网络靶场监控系统的安全加固纪实(1)—SSL/TLS对日志数据加密传输
Thrift IDL示例文件
FE01_OneHot-Scala应用
JS兼容问题总结
Flask framework implementations registered encryption, a Flask enterprise class learning 】 【
斯坦福:未来的RGB LED可以贴在你的皮肤上
【无标题】
离线同步odps到mysql 中文乱码是因为?mysql已是utf8mb4
Go language Go language, understand Go language file operation in one article
Cholesterol-PEG-Maleimide,CLS-PEG-MAL,胆固醇-聚乙二醇-马来酰亚胺一种修饰性PEG
Understanding of margin collapse and coincidence
当项目中自动格式化插件Prettier和ESLint冲突报错时如何解决
CAS:474922-26-4,DSPE-PEG-NH2,DSPE-PEG-amine,磷脂-聚乙二醇-氨基供应