知乎专栏 |
VS/DR方式是通过改写请求报文中的MAC地址部分来实现的。
Director和RealServer必需在物理上有一个网卡通过不间断的局域网相连。
Director
VIP:172.16.0.1
neo@ubuntu:~$ sudo ifconfig eth0 172.16.0.1/16 or ifconfig eth0 172.16.0.x netmask 255.255.0.0 broadcast 172.16.0.255 up ifconfig eth0:0 172.16.0.1 netmask 255.255.255.255 broadcast 172.16.0.1 up sudo sysctl -w net.ipv4.ip_forward=1
ipvsadm
#!/bin/bash ipvsadm -C ipvsadm -A -t 172.16.0.1:80 -s wlc ipvsadm -a -t 172.16.0.1:80 -r 172.16.0.10 -g ipvsadm -a -t 172.16.0.1:80 -r 172.16.0.20 -g ipvsadm -a -t 172.16.0.1:80 -r 172.16.0.30 -g
script
ifconfig eth0 172.16.0.x netmask 255.255.0.0 broadcast 172.16.0.255 up ifconfig eth0:0 172.16.0.1 netmask 255.255.255.255 broadcast 172.16.0.1 up echo 1 > /proc/sys/net/ipv4/ip_forward
RealServer
Ubuntn
neo@master:~$ sudo sysctl -w net.ipv4.ip_forward=1 net.ipv4.ip_forward = 1 neo@master:~$ sudo sysctl -w net.ipv4.conf.lo.arp_ignore=1 net.ipv4.conf.lo.arp_ignore = 1 neo@master:~$ sudo sysctl -w net.ipv4.conf.lo.arp_announce=2 net.ipv4.conf.lo.arp_announce = 2 neo@master:~$ sudo sysctl -w net.ipv4.conf.all.arp_ignore=1 net.ipv4.conf.all.arp_ignore = 1 neo@master:~$ sudo sysctl -w net.ipv4.conf.all.arp_announce=2 net.ipv4.conf.all.arp_announce = 2 neo@master:~$ neo@master:~$ sudo ifconfig lo:0 172.16.0.1 netmask 255.255.255.255 broadcast 172.16.0.1 up neo@master:~$ sudo route add -host 172.16.0.1 dev lo:0
script
sudo sysctl -w net.ipv4.ip_forward=1 sudo sysctl -w net.ipv4.conf.lo.arp_ignore=1 sudo sysctl -w net.ipv4.conf.lo.arp_announce=2 sudo sysctl -w net.ipv4.conf.all.arp_ignore=1 sudo sysctl -w net.ipv4.conf.all.arp_announce=2 sudo ifconfig lo:0 172.16.0.1 netmask 255.255.255.255 broadcast 172.16.0.1 up sudo route add -host 172.16.0.1 dev lo:0
redhat
echo 1 > /proc/sys/net/ipv4/ip_forward echo 1 > /proc/sys/net/ipv4/conf/all/hidden echo 1 > /proc/sys/net/ipv4/conf/lo/hidden ifconfig lo:0 172.16.0.1 netmask 255.255.255.255 broadcast 172.16.0.1 up
test
neo@ubuntu:~$ sudo tcpdump -i eth0|grep "172.16.0.1"
ifconfig
neo@ubuntu:~$ ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:C2:FC:D7 inet addr:172.16.0.250 Bcast:172.16.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:fec2:fcd7/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8566 errors:0 dropped:0 overruns:0 frame:0 TX packets:11544 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:726365 (709.3 KiB) TX bytes:2638735 (2.5 MiB) Interrupt:177 Base address:0x1400 eth0:0 Link encap:Ethernet HWaddr 00:0C:29:C2:FC:D7 inet addr:172.16.0.1 Bcast:255.255.255.255 Mask:0.0.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:177 Base address:0x1400 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) neo@ubuntu:~$
ipvsadm
neo@ubuntu:~$ sudo ipvsadm IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 172.16.0.1:www wlc -> 172.16.0.20:www Route 1 0 0 -> 172.16.0.10:www Route 1 0 0 neo@ubuntu:~$
ifconfig
neo@ubuntu:~$ ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:CC:CF:A2 inet addr:172.16.0.20 Bcast:172.16.255.255 Mask:255.255.0.0 inet6 addr: fe80::20c:29ff:fecc:cfa2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:1897 errors:0 dropped:0 overruns:0 frame:0 TX packets:1511 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:229334 (223.9 KiB) TX bytes:205973 (201.1 KiB) Interrupt:177 Base address:0x1400 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 b) TX bytes:0 (0.0 b) lo:0 Link encap:Local Loopback inet addr:172.16.0.1 Mask:255.255.255.255 UP LOOPBACK RUNNING MTU:16436 Metric:1 neo@ubuntu:~$