当前位置:网站首页>Deploy LVS-DR cluster [experimental]
Deploy LVS-DR cluster [experimental]
2022-08-04 05:35:00 【LEE_ September】
部署LVS-DR群集【实验】
文章目录
1.LVS-DR数据包流向分析
① 为方便进行原理分析,将client与群集机器放在同一网络中,数据包流经的路线为1-2-3-4
② client 向目标VIP发出请求,Director(负载均衡器)接收
③ Director根据负载均衡算法选择RealServer_1,不修改也不封装IP报文,而是将数据帧的MAC地址改为RealServer_1的MAC地址,然后在局域网上发送
④RealServer_1收到这个帧,解封装后发现目标IP与本机匹配(RealServer事先绑定 了VIP),于是处理这个报文.随后重新封装报文,发送到局域网
⑤ Client将收到回复报文.Client认为得到正常的服务,而不会知道是哪一台服务器处理的
个人小结:
1.Client向目标VIP发出请求,Director(负载均衡器)接收
源IP是Client的IP,源MAC地址是Client的MAC
目标IP是Director的VIP,目标MAC地址是Director的MAC地址
2.DirectorReal servers are selected according to the load balancing algorithm,不修改也不封装IP报文,而是将MAC地址改为真实服务器的MAC地址
源IP是Client的IP,源MAC是Director的MAC地址
目标IP是VIP,目标MAC是真实服务器的MAC地址
3.服务器收到后,Decapsulate the discovery targetIP与本机匹配(事先绑定了VIP),然后重新封装报文
源IP是VIP,源MAC是服务器的MAC
目标IP是Client的IP,目标MAC是Client的MAC
4.Client收到回复报文,Get normal service but won't know which server handles it
2.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 地址
3.LVS-DR中的ARP问题
问题一:
在局域网中具有相同的IP地址,势必会造成各服务器ARP通信的紊乱
● 当ARP广播发送到LVS-DR集群时,因为负载均衡器和节点服务器都是连接到相同的网络上,它们都会接收到ARP广播
● 只有前端的负载均衡器进行响应,其他节点服务器不应该响应ARP广播
解决方法:
● 使用虚接口lo:0承载VIP地址
● 设置内核参数arp_ ignore=1: 系统只响应目的IP为本地IP的ARP请求
问题二:
1.RealServer返回报文(源IP是VIP)经路由器转发,重新封装报文时,需要先获取路由器的MAC地址发送ARP请求时,Linux默认使用IP包的源IP地址(即VIP) 作为ARP请求包的源IP地址,而不使用发送接口的IP地址
2.路由器收到ARP请求后,将更新ARP表项
3.原有的VIP对应Director的MAC地址会被更新为VIP对应RealServer的MAC地址
所以,路由表根据ARP表项,会将新来的请求报文转发给RealServer,导致Director的VIP失效
解决方法:
对节点服务器进行处理,设置内核参数==arp_ announce=2:==系统不使用IP包的源地址来设置ARP请求的源地址,而选择发送接口的IP地址
① arp ingore=1
防止网关路由器发送ARP广播时调度器和节点服务器都进行响应,这
个会导致ARP缓存表混乱,不对非本地物理网卡IP的ARP请求响应,
因为wIP是承载lo:0
② arp announce=2
系统不使用响应的数据的源IP地址(VIP),Instead, use the physical network that sends the message
卡IP地址作为ARP请求的报文的源IP地址,This prevents gateway routers
received sourceIP地址为WIP的ARP请求报文后又更新ARP缓存表,cause outside
When the network sends the request again,数据包到达不了调度器
4.DR模式 LVS负载均衡群集部署
4.1所需环境
LVS负载均衡调节器(DR服务器): ens33: 192.168.36.40
Web1 节点服务器:192.168.36.30
Web2 节点服务器:192.168.36.20
客户端 win10:192.168.36.11
VIP地址: 192.168.36.200
#All machines have firewall and core protection turned off
[[email protected] ~]# systemctl stop firewalld
[[email protected] ~]# systemctl disable firewalld
[[email protected] ~]# setenforce 0
4.2配置负载调度器
4.2.1安装ipvsadm工具
[[email protected] ~]# yum install -y ipvsadm.x86_64
4.2.2配置虚拟IP
[[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
#All original content is deleted,添加以下内容
NAME=ens33:0
DEVICE=ens33:0
IPADDR=192.168.36.200
NETMASK=255.255.255.0
4.2.3重启网络服务、启动网卡
[[email protected] network-scripts]# systemctl restart network
[[email protected] network-scripts]# ifup ens33:0
4.2.4调整/proc响应参数
对于 DR 群集模式来说,由于 LVS 负载调度器和各节点需要共用 VIP 地址,应该关闭 Linux 内核的重定向参数响应服务器不是一台路由器,那么它不会发送重定向,所以可以关闭该功能
[[email protected] ~]# 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] ~]# sysctl -p
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
4.2.5加载模块
[[email protected] ~]# modprobe ip_vs
[[email protected] ~]# 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
4.2.6配置负载分配策略,并启动服务
[[email protected] ~]# ipvsadm-save >/etc/sysconfig/ipvsadm
[[email protected] ~]# systemctl start ipvsadm.service
4.2.7清空ipvsadm,并添加策略
添加真实服务器 -a 指定VIP地址及TCP端口 -t 指定RIP地址及TCP端口 -r 指定DR模式 -g
[[email protected] ~]# ipvsadm -C
[[email protected] ~]# ipvsadm -A -t 192.168.36.200:80 -s rr
[[email protected] ~]# ipvsadm -a -t 192.168.36.200:80 -r 192.168.36.30:80 -g
[[email protected] ~]# ipvsadm -a -t 192.168.36.200:80 -r 192.168.36.20:80 -g
4.2.8.启动ipvsadm,查看配置,保存
[[email protected] ~]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP director:http rr
-> 192.168.36.20:http Route 1 0 0
-> 192.168.36.30:http Route 1 0 0
[[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 192.168.36.200:80 rr
-> 192.168.36.20:80 Route 1 0 0
-> 192.168.36.30:80 Route 1 0 0
[[email protected] ~]# ipvsadm-save >/etc/sysconfig/ipvsadm
4.3配置web1节点服务器
4.3.1安装httpd并开启,创建一个站点文件
[[email protected] ~]# yum install -y httpd
[[email protected] ~]# systemctl restart httpd
[[email protected] ~]# echo "<h1>八百标兵奔北坡</h1>" > /var/www/html/index.html
4.3.2添加回环网卡
修改回环网卡名,IP地址,子网掩码
[[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
IPADDR=192.168.36.200
NETMASK=255.255.255.255
NETWORK=127.0.0.0
[[email protected] network-scripts]# systemctl restart network
4.3.3设置路由
[[email protected] network-scripts]# route add -host 192.168.36.200 dev lo:0
4.3.4添加到变量开机执行命令
[[email protected] network-scripts]# vim /etc/rc.d/rc.local
#添加以下内容
/usr/sbin/route add -host 192.168.36.200 dev lo:0
#给与执行权限
[[email protected] network-scripts]# chmod +x /etc/rc.d/rc.local
4.3.5调整proc响应参数
添加系统只响应目的IP为本地IP的ARP请求
系统不使用原地址来设置ARP请求的源地址,而是物理mac地址上的IP
[[email protected] network-scripts]# vim /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
4.4配置web2节点服务器
4.4.1安装httpd并开启,创建一个站点文件
[[email protected] ~]# yum install httpd -y
[[email protected] ~]# systemctl start httpd
[[email protected] ~]# echo "<h1>炮兵并排北边跑</h1>" > /var/www/html/index.html
4.4.2添加回环网卡
修改回环网卡名,IP地址,子网掩码
[[email protected] network-scripts]# 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
IPADDR=192.168.36.200
NETMASK=255.255.255.255
NETWORK=127.0.0.0
[[email protected] network-scripts]# systemctl restart network
4.4.3设置路由
[[email protected] network-scripts]# route add -host 192.168.36.200 dev lo:0
4.4.4添加到变量开机执行命令
[[email protected] network-scripts]# vim /etc/rc.d/rc.local
#添加以下内容
/usr/sbin/route add -host 192.168.36.200 dev lo:0
#给与执行权限
[[email protected] network-scripts]# chmod +x /etc/rc.d/rc.local
4.4.5调整 proc 响应参数
[[email protected] network-scripts]# vim /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
4.5win10客户机浏览器访问
边栏推荐
猜你喜欢
触觉智能分享-SSD20X实现升级显示进度条
3面头条,花7天整理了面试题和学习笔记,已正式入职半个月
[One step in place] Jenkins installation, deployment, startup (complete tutorial)
MySQL日志篇,MySQL日志之binlog日志,binlog日志详解
7.16 Day22---MYSQL(Dao模式封装JDBC)
Unity Visual Effect Graph入门与实践
What is the salary of a software testing student?
【一步到位】Jenkins的安装、部署、启动(完整教程)
在被面试官说了无数次后,终于潜下心来整理了一下JVM的类加载器
Can 't connect to MySQL server on' localhost3306 '(10061) simple solutions
随机推荐
canal实现mysql数据同步
利用Jenkins实现Unity自动化构建
4.1 声明式事务之JdbcTemplate
Unity DOTS学习教程汇总
Cannot read properties of null (reading 'insertBefore')
C Expert Programming Chapter 4 The Shocking Fact: Arrays and Pointers Are Not the Same 4.3 What is a Declaration and What is a Definition
擎朗智能全国研发创新中心落地光谷:去年曾获2亿美元融资
DP4398:国产兼容替代CS4398立体声24位/192kHz音频解码芯片
腾讯136道高级岗面试题:多线程+算法+Redis+JVM
应届生软件测试薪资大概多少?
Redis common interview questions
Use Patroni callback script to bind VIP pit
编程大杂烩(四)
MySQL log articles, binlog log of MySQL log, detailed explanation of binlog log
(Kettle) pdi-ce-8.2 连接MySQL8.x数据库时驱动问题之终极探讨及解决方法分析
企业需要知道的5个 IAM 最佳实践
C Expert Programming Chapter 4 The Shocking Fact: Arrays and pointers are not the same 4.4 Matching declarations to definitions
8.03 Day34---BaseMapper查询语句用法
JS basics - forced type conversion (error-prone, self-use)
渗透测试(PenTest)基础指南