配置lvs的dr模式(临时的网卡):
分发器的eth0是192.168.137.61 ,之后是分发器的配置:
ifconfig eth0:0 192.168.137.200 netmask 255.255.255.255 broadcast 192.168.137.200 up
ipvsadm -A -t 192.168.137.200:80 -s rr
ipvsadm -a -t 192.168.137.200:80 -r 192.168.137.62 -g
ipvsadm -a -t 192.168.137.200:80 -r 192.168.137.63 -g
real server1的eth0是192.168.137.62,之后是该机器的配置:
ifconfig lo:0 192.168.137.200 netmask 255.255.255.255 broadcast 192.168.137.200 up
route add -host 192.168.137.200 dev lo:0
real server2的eth0是192.168.137.63,之后是该机器的配置:
ifconfig lo:0 192.168.137.200 netmask 255.255.255.255 broadcast 192.168.137.200 up
route add -host 192.168.137.200 dev lo:0
route -n 查看路由设置
ip tun配置lvs,实验成功:
二.ip隧道的实验原理
1. 首先client发送请求[package]给VIP
2. VIP收到package后,会根据LVS设置的LB算法选择一个合适的realserver;并把client发送的package包装到一个新的IP包里面;新的IP包的dst是realserver的IP
3. realserver收到这个package后判断dst ip是自己,然后解析出来的package的dst是vip;会检测我们的网卡是否绑定了vip的地址,如果绑了就会处理这个包,如果没有就直接丢弃
在转发的机器上:
ifconfig eth0:1 192.168.137.201 netmask 255.255.255.255 broadcast 192.168.137.201 up
echo '0' > /proc/sys/net/ipv4/ip_forward
ipvsadm -A -t 192.168.137.201:80 -s wlc
ipvsadm -a -t 192.168.137.201:80 -r 192.168.137.62 -i
在real server上
echo '0' > /proc/sys/net/ipv4/ip_forward
# insert it if it is compiled as module
modprobe ipip
ifconfig tunl0 192.168.137.201 netmask 255.255.255.255 broadcast 192.168.137.201 up
echo "1" >/proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/tunl0/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
echo '0' > /proc/sys/net/ipv4/conf/tunl0/rp_filter
echo '0' > /proc/sys/net/ipv4/conf/all/rp_filter
ifconfig tunl0 192.168.137.201 netmask 255.255.255.255 broadcast 192.168.137.201 up