本文主要是介绍LVS DR模型,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在LVS DR模型中:
Realserver中有eth0和lo接口,lo接口上配置的是VIP地址,要设置来自 director向后端realserver转发请求时,通过lo接口接进来,它还要从lo出去,lo又没办法出去,所以lo就将响应通过eth0转发出去,能通过eth0转发出去的条件是,eth0(DIP)必须指向一个网关,这个网关可以连向互联网。Eth0必须把网关指向能够到达CIP的网关。
CIP -- VIP --- DIP --- RS(lo -->eth0)--router --CIP
LVS-DR模型:
Director两个地址:VIP, DIP
RS有两个地址:VIP, RIP
禁止RS响应对VIP的ARP广播请求:
LVS-DR:直接路由
Directory配置VIP
# cat /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
IPADDR=172.16.100.200
NETMASK=255.255.255.0
GATEWAY=172.16.100.2
IPV6INIT=no
USERCTL=no
[root@localhost ~]#
配置路由:
# route add -host 172.16.100.200 dev eth0:0
RS服务器上千万记得不能先配置VIP地址,必须等关掉arp广播才可以配置
配置RS1服务器,首先关闭ARP报文功能:
# sysctl -w net.ipv4.conf.eth0.arp_announce=2
# sysctl -w net.ipv4.conf.all.arp_announce=2
# sysctl -w net.ipv4.conf.eth0.arp_ignore=1
# sysctl -w net.ipv4.conf.all.arp_ignore=1
或者
echo 1 >/proc/sys/net/ipv4/conf/all/arp_ignore
这样的形式都可以的
配置VIP地址:
#ifconfig lo:0 172.16.100.200 broadcast 172.16.100.200(与director一样) netmask 255.255.255.255 up
# route add -host 172.16.100.200 dev lo:0
配置RS2服务器:
# sysctl -w net.ipv4.conf.eth0.arp_announce=2
# sysctl -w net.ipv4.conf.all.arp_announce=2
# sysctl -w net.ipv4.conf.eth0.arp_ignore=1
# sysctl -w net.ipv4.conf.all.arp_ignore=1
#ifconfig lo:0 172.16.100.200 broadcast 172.16.100.200(与director一样) netmask 255.255.255.255 up
# route add -host 172.16.100.200 dev lo:0
LVS-Directory配置:
# ipvsadm -A -t 172.16.100.200:80 -s wlc
# ipvsadm -a -t 172.16.100.200:80 -r172.16.100.101 -g -w 2
# ipvsadm -a -t 172.16.100.200:80 -r172.16.100.102 -g -w 1
# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.16.100.200:80 wlc
-> 172.16.100.101:80 Route 2 0 0
-> 172.16.100.102:80 Route 1 0 0
[root@localhost ~]#
通过浏览器访问:
http://172.16.100.200(虚拟地址)就可以访问到RS1 和RS2 两台服务器
这篇关于LVS DR模型的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!