LVS無論NAT及DR模式,均要求LVS server和real server在同一個網段內,NAT需要把lvs server當作各個realserver的默認網關,DR模式采用修改mac地址直接從數據鏈路層轉發、要求必須在同一個物理網段內
LVS-NAT的實驗
網絡拓撲:
? ?采用青云1個Router、1個公網IP、1個受管私網、3臺私網內VM搭建(1臺LVS、2臺Realserver),vm中防火墻均關閉,Router上綁定公網ip、配置端口轉發策略,把80端口轉向LVS的ip:80,青云中防火墻打開下行tcp 80端口
環境:??CentOS 6.4 x64
過程:
一? ?LB?
1??首先安裝ipvsadm
2??開啟ip_forward
? ?echo "1" >/proc/sys/net/ipv4/ip_forward?
3??編寫lvs 規則
? ?#vim lvsnat.sh
? ? ipvsadm -C
? ? ipvsadm -A -t lvs_ip:80 -s rr?
? ? ipvsadm -a -t lvs_ip:80 -r web1_ip:80 -m
? ? ipvsadm -a -t lvs_ip:80 -r web2_ip:80 -m
4??執行規則
? ?sh lvsnat.sh
5??使用ipvsadm -l 可以看到
??[root@localhost ~]# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
??-> RemoteAddress:Port? ?? ?? ???Forward Weight ActiveConn InActConn
TCP??lvs_ip:http rr
??-> web1_ip:http? ?? ?? ?? ?Masq? ? 1? ?? ?0? ?? ?? ? 0? ?? ?? ?
??-> web2_ip:http? ?? ?? ?? ?Masq? ? 1? ?? ?0? ?? ?? ? 0
二 Real Server
? ?Real server 只需要把網關指向lvs_ip 就可以了,開啟apache 測試
route add default gw lvs_ip
刪除webserver中原來默認路由:route del default gw 192.168.100.1
參考文章:http://www.importnew.com/11229.html
===================================
采用公私鑰免密碼登陸server
bogon:~ cyber$ chmod 600 /Users/cyber/Documents/kp-0zv7sbt7
bogon:~ cyber$ ssh -i /Users/cyber/Documents/kp-0zv7sbt7 root@117.121.10.49
?