VS/DR: 即(Virtual Server via Direct Routing)
也就是用直接路由技术实现虚拟服务器。它的连接调度和管理与VS/NAT和VS/TUN中的一样,但它的报文转发方法又有不同,VS/DR通过改写请求报文的MAC地址,将请求发送到Real Server,而Real Server将响应直接返回给客户,免去了VS/TUN中的IP隧道开销。这种方式是三种负载调度机制中性能最高最好的,但是必须要求Director Server与Real Server都有一块网卡连在同一物理网段上。
例子
DIP:172.28.95.220
VIP:172.28.95.245
RIP:172.28.95.221(222)
负载调度器:
[root@LVS-GS001 ipvsadm-1.24]# ifconfig eth1:1 172.28.95.245 netmask 255.255.255.0 up
[root@LVS-GS001 ipvsadm-1.24]# ifconfig
eth1 Link encap:Ethernet HWaddr 00:15:5D:C7:83:7D
inet addr:172.28.95.220 Bcast:172.28.95.255 Mask:255.255.240.0
eth1:1 Link encap:Ethernet HWaddr 00:15:5D:C7:83:7D
inet addr:172.28.95.245 Bcast:172.28.95.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:9 Base address:0xc000
[root@LVS-GS001 ipvsadm-1.24]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
[root@LVS-GS001 ipvsadm-1.24]# ipvsadm --help
[root@LVS-GS001 ipvsadm-1.24]# ipvsadm --set 30 5 60 #--set tcp tcpfin udp set connection timeout values
[root@LVS-GS001 ipvsadm-1.24]# ipvsadm -A -t 172.28.95.245:80 -s wrr -p 20 #-A add virtual service with options #-s scheduler one of rr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq,the default scheduler is wlc.
[root@LVS-GS001 ipvsadm-1.24]# 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.28.95.245:80 wrr persistent 20
[root@LVS-GS001 ipvsadm-1.24]# ipvsadm -a -t 172.28.95.245:80 -r 172.28.95.221:80 -g -w 1
[root@LVS-GS001 ipvsadm-1.24]# ipvsadm -a -t 172.28.95.245:80 -r 172.28.95.222:80 -g -w 1
[root@LVS-GS001 ipvsadm-1.24]# 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.28.95.245:80 wrr persistent 20
-> 172.28.95.222:80 Route 1 0 0
-> 172.28.95.221:80 Route 1 0 0
Real-Server:
[root@RealServer001 ~]# ifconfig lo:221 172.28.95.245:80 netmask 255.255.255.255 up
[root@RealServer001 ~]# echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
[root@RealServer001 ~]# echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
[root@RealServer001 ~]# echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
[root@RealServer001 ~]# echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce