马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
目次
1 DR模式原理
2 DR模式哀求复兴过程
3 实验情况
4 开始实验
4.1 设置实验情况
4.2 Router 设置路由转发
4.3 LVS 设置转发规则
4.4 办理vip相应题目
4.5 Web1设置
4.6 Web2设置
5 测试结果
1 DR模式原理
- 当用户向负载平衡调理器(Director Server)发起哀求,调理器将哀求发往至内核空间
- PREROUTING链起首会汲取到用户哀求,判定目标IP确定是本机IP,将数据包发往INPUT链
- IPVS是工作在INPUT链上的,当用户哀求到达INPUT时,IPVS会将用户哀求和本身已界说好的集群服务举行比对,假如用户哀求的就是界说的集群服务,那么此时IPVS会强行修改数据包里的目标IP地点及端口,并将新的数据包发往POSTROUTING链
- POSTROUTING链汲取数据包后发现目标IP地点刚好是本身的后端服务器,那么此时通过选路,将数据包终极发送给后端的服务器
2 DR模式哀求复兴过程
1、客户端向目标VIP发送哀求:客户端发起HTTP/HTTPS等协议的哀求,目标地点为假造IP(VIP)。
2、负载平衡器汲取并处置处罚哀求:负载平衡器汲取到哀求后,会根据预设的负载平衡计谋(如轮询、权重、最少毗连数等),选择一个符合的后端服务器举行转发。
3、数据包转发至后端服务器:负载平衡器不会更改IP报文的内容,而是将数据包的目标MAC地点更改为所选后端服务器的MAC地点,然后将数据包发送到后端服务器地点的网络。
4、后端服务器处置处罚哀求和返回相应:后端服务器汲取到数据包后,查抄其目标IP地点是否与本身绑定的VIP类似,假如是,则处置处罚该哀求。将相应报文通过lo接口传送给物理网卡然后向外发出。处置处罚完成后,后端服务器将相应数据包直接发回给客户端
5、客户端将收到复兴报文。客户端以为得到正常的服务,而不会知道是哪一台服务器处置处罚的
3 实验情况
序号 源 目标1 192.168.239.200/24
mac:client
172.25.254.200/24
mac:Router-eth0
2 192.168.239.200/24
mac:Router-eth1
172.25.254.200/24
mac:LVS
3 192.168.239.200/24
mac:LVS
172.25.254.200/24
mac:web1
4 172.25.254.200/24
mac:web1-eth0
172.25.254.100/24
mac:Router-eth1
5 172.25.254.200/24
mac:Router-eth0
172.25.254.100/24
mac:client
4 开始实验
4.1 设置实验情况
- # Client
- [root@client ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
- [connection]
- id=eth0
- type=ethernet
- interface-name=eth0
- [ipv4]
- address1=192.168.239.200/24,192.168.239.100
- method=manual
- # Router
- [root@router ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
- [connection]
- id=eth0
- type=ethernet
- interface-name=eth0
- [ipv4]
- address1=192.168.239.100/24
- method=manual
- [root@router ~]# cat /etc/NetworkManager/system-connections/eth1.nmconnection
- [connection]
- id=eth1
- type=ethernet
- interface-name=eth1
- [ipv4]
- address1=172.25.254.100/24
- method=manual
- # LVS 配置
- [root@LVS ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
- [connection]
- id=eth0
- type=ethernet
- interface-name=eth0
- [ipv4]
- address1=172.25.254.50/24,172.25.254.100
- method=manual
- # web1
- [root@web1 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
- [connection]
- id=eth0
- type=ethernet
- interface-name=eth0
- [ipv4]
- address1=172.25.254.10/24,172.25.254.100
- method=manual
- # web2
- [root@web2 ~]# cat /etc/NetworkManager/system-connections/eth0.nmconnection
- [connection]
- id=eth0
- type=ethernet
- interface-name=eth0
- [ipv4]
- address1=172.25.254.20/24,172.25.254.100
- method=manual
复制代码
4.2 Router 设置路由转发
- # 虚拟机本身是不开启路由功能的,要想开启请在内核中开启路由转发功能
- [root@mysql-03 test]# sysctl -a | grep ip_forward
- net.ipv4.ip_forward = 0
- net.ipv4.ip_forward_update_priority = 1
- net.ipv4.ip_forward_use_pmtu = 0
- [root@mysql-03 test]# echo net.ipv4.ip_forward = 1 >> /etc/sysctl.conf
- [root@router ~]# sysctl -p
- net.ipv4.ip_forward = 1
复制代码 4.3 LVS 设置转发规则
- # 给环回接口填上
- [root@LVS test]# ip addr add 172.25.254.200/32 dev lo
- # 设置转发规则
- [root@LVS test]# ipvsadm -A -t 172.25.254.200:80 -s wrr
- [root@LVS test]# ipvsadm -a -t 172.25.254.200:80 -r 172.25.254.10 -w 1 -g
- [root@LVS test]# ipvsadm -a -t 172.25.254.200:80 -r 172.25.254.20 -w 1 -g
- # 查看规则
- [root@LVS ~]# ipvsadm -Ln
- IP Virtual Server version 1.2.1 (size=4096)
- Prot LocalAddress:Port Scheduler Flags
- -> RemoteAddress:Port Forward Weight ActiveConn InActConn
- TCP 172.25.254.200:80 wrr
- -> 172.25.254.10:80 Route 1 0 5
- -> 172.25.254.20:80 Route 1 0 6
复制代码
4.4 办理vip相应题目
DR 模子中各主机上均必要设置 VIP ,办理地点辩论的方式有三种:
- (1)在前端网关做静态绑定
- (2)在各RS利用arptables
- (3)在各RS修改内核参数,来限定arp相应和告示的级别
限定相应级别 :arp_ignore
- 0:默认值,表现可利用当地恣意接口上设置的恣意地点举行相应
- 1:仅在哀求的目标IP设置在本田主机的汲取到哀求报文的接口上时,才给予相应
限定告示级别 :arp_announce
- 0:默认值,把本机全部接口的全部信息向每个接口的网络举行告示
- 1:只管制止将接口信息向非直接毗连网络举行告示
- 2:必须制止将接口信息向非本网络举行告示
4.5 Web1设置
- # 增加VIP
- [root@web1 test]# ip addr add 172.25.254.200/32 dev lo
- # 查看网关是否指向路由器
- [root@web1 test]# route -n
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 0.0.0.0 172.25.254.100 0.0.0.0 UG 100 0 0 eth0
- 172.25.254.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
- [root@web1 test]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
- [root@web1 test]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
- [root@web1 test]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
- [root@web1 test]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
复制代码 4.6 Web2设置
- # 增加VIP
- [root@web2 test]# ip addr add 172.25.254.200/32 dev lo
- # 查看网关是否指向路由器
- [root@web2 test]# route -n
- Kernel IP routing table
- Destination Gateway Genmask Flags Metric Ref Use Iface
- 0.0.0.0 172.25.254.100 0.0.0.0 UG 100 0 0 eth0
- 172.25.254.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
- [root@web2 test]# echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
- [root@web2 test]# echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
- [root@web2 test]# echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
- [root@web2 test]# echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
复制代码
5 测试结果
- [root@client ~]# for i in {1..10}
- > do
- > curl 172.25.254.200
- > done
- this is web1
- this is web2
- this is web1
- this is web2
- this is web1
- this is web2
- this is web1
- this is web2
- this is web1
- this is web2
复制代码
|