三臺服務器
Real server 1: 10.10.10.51
Real server 2: 10.10.10.52
LVS Directory: 10.10.10.53/192.168.12.53
VIP1: 10.10.10.111 #用於測試同網段下使用LVS
VIP2: 192.168.12.111 #用於測試跨網段下使用LVS
RS1 和 RS2 默認網關指向Directory
所有服務器關閉selinux 和 iptableshtml
Real server 1linux
yum install httpd -y echo "Real Server 1" > /var/www/html/index.html service httpd start
Real server 2瀏覽器
yum install httpd -y echo "Real Server 2" > /var/www/html/index.html service httpd start
Directorbash
測試CIP和VIP在不一樣網段服務器
yum install ipvsadm -y ifconfig eth1:0 192.168.12.111/32 up echo "1" > /proc/sys/net/ipv4/ip_forward ipvsadm -A -t 192.168.12.111:http -s rr ipvsadm -a -t 192.168.12.111:http -r 10.10.10.51:http -m ipvsadm -a -t 192.168.12.111:http -r 10.10.10.52:http -m
瀏覽器打開http://192.168.12.111,按CRTL+F5刷新,查看效果tcp
測試CIP和VIP在相同網段ide
ifconfig eth0:0 10.10.10.111/32 up ipvsadm -A -t 10.10.10.111:80 -s rr ipvsadm -a -t 10.10.10.111:80 -r 10.10.10.51 -m ipvsadm -a -t 10.10.10.111:80 -r 10.10.10.52 -m
經過tcpdump tcp port 80 發現RS能夠接收到請求包,可是返回數據直接經過ARP請求發送給CLIENT,形成同網段下數據沒法經過Director修改IP包後在返回給CLIENT。請求失敗。測試
real server手動指定Client路由到Director
server
route add -host 10.10.10.147 gw 10.10.10.111
瀏覽器打開http://10.10.10.111,按CRTL+F5刷新,查看效果htm