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

边栏推荐
- 2018年南海区小学生程序设计竞赛详细答案
- Matlab画图1
- 数仓相关,总结
- 【web自动化测试】Playwright快速入门,5分钟上手
- How does EasyCVR call the double-speed playback of device recording through the interface?
- mood swings
- 当项目中自动格式化插件Prettier和ESLint冲突报错时如何解决
- "Involution" Index Analysis Based on AHP
- 电源测试系统-ATE电源测试系统-ACDC电源模块测试系统NSAT-8000
- 阿里云国际版使用ROS搭建WordPress教程
猜你喜欢
关于ETL的两种架构(ETL架构和ELT架构)
How does the intelligent video surveillance platform EasyCVR use the interface to export iframe addresses in batches?
After EasyCVR is locally connected to the national standard device to map the public network, the local device cannot play and cascade the solution
企业即时通讯软件有哪些功能?对企业有什么帮助?
"No title"
图解LeetCode——899. 有序队列(难度:困难)
The Industrial Metaverse Brings Changes to Industry
[Web Automation Test] Quick Start with Playwright, 5 minutes to get started
2022年五一数学建模C题讲解
Develop those things: How to obtain the traffic statistics of the monitoring site through the EasyCVR platform?
随机推荐
火灾报警联网FC18中CAN光端机常见问题解答和使用指导
Thrift installation configuration
谷歌开源芯片 180 纳米制造工艺
哈夫曼树(暑假每日一题 15)
企业调查相关性分析案例
数据库SqlServer迁移PostgreSql实践
数仓建模面试
基于 eBPF 的 Kubernetes 可观测实践
链表的经典入门LeetCode题目
localstorage本地存储的方法
leetcode 14. 最长公共前缀
报道称任天堂在2023年3月前不会推出任何新硬件产品
LeetCode 899. Ordered Queues
敏捷开发项目管理的一些心得
框架整合(二)- 使用Apache ShardingSphere实现数据分片
Matlab drawing 1
Go 言 Go 语,一文看懂 Go 语言文件操作
工业元宇宙对工业带来的改变
darknet source code reading notes-02-list.h and lish.c
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