标签:lvs
为了简化模拟过程,所有的机器全部在一个网段下,客户机的IP是192.168.1.10,Load Balancer同样提供一个对外可见的VIP192.168.1.11,其DIP与真实服务器在一个不分段的局域网中,可以使用交换机或者集线器连接,网关全部指向192.168.1.1。当然,你的真实服务器也可以使用其他路由器提供的互联网服务,只需要把网关指向它即可。
补充:
主机路由:就是去往某个主机地址如何配置路由
/sbin/route add -host 192.168.2.13 dev eth2
/sbin/route add -host 202.81.11.91 dev lo
1、在Load Balancer上运行以下脚本:
#!/bin/bash
#---------------mini-rc.lvs_dr-director------------------------
#set ip_forward OFF for lvs-dr director (1 on, 0 off)
#(there is no forwarding in the conventional sense for LVS-DR)
cat /proc/sys/net/ipv4/ip_forward
echo "0" >/proc/sys/net/ipv4/ip_forward
#director is not gw for realservers: leave icmp redirects on
echo ‘setting icmp redirects (1 on, 0 off) ‘
echo "1" >/proc/sys/net/ipv4/conf/all/send_redirects
cat /proc/sys/net/ipv4/conf/all/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/default/send_redirects
cat /proc/sys/net/ipv4/conf/default/send_redirects
echo "1" >/proc/sys/net/ipv4/conf/eth0/send_redirects
cat /proc/sys/net/ipv4/conf/eth0/send_redirects
#setup DIP
/sbin/ifconfig eth0 192.168.1.101 netmask 255.255.255.0 up
#add ethernet device and routing for VIP 192.168.1.11
/sbin/ifconfig eth0:0 192.168.1.11 netmask 255.255.255.0 up
/sbin/route add -host 192.168.1.11 dev eth0:0
#listing ifconfig info for VIP 192.168.1.11
/sbin/ifconfig eth0:0
#check VIP 192.168.1.11 is reachable from self (director)
/bin/ping -c 1 192.168.1.11
#listing routing info for VIP 192.168.1.11
/bin/netstat -rn
#setup_ipvsadm_table
#clear ipvsadm table
/sbin/ipvsadm -C
#installing LVS services with ipvsadm
#add telnet to VIP with round robin scheduling
/sbin/ipvsadm -A -t 192.168.1.11:80 -s rr
#forward telnet to realserver using direct routing with weight 1
/sbin/ipvsadm -a -t 192.168.1.11:80 -r 192.168.1.102:80 -g -w 1
#check realserver reachable from director
ping -c 1 192.168.1.102
#forward telnet to realserver using direct routing with weight 1
/sbin/ipvsadm -a -t 192.168.1.11:80 -r 192.168.1.103:80 -g -w 1
#check realserver reachable from director
ping -c 1 192.168.1.103
#displaying ipvsadm settings
/sbin/ipvsadm
#not installing a default gw for LVS_TYPE vs-dr
#---------------mini-rc.lvs_dr-director------------------------
2、在第一台Real Server上运行以下脚本:
#!/bin/bash
#----------mini-rc.lvs_dr-realserver------------------
#setup IP
/sbin/ifconfig eth0 192.168.1.102 broadcast 192.168.1.255 netmask 255.255.255.0
#installing default gw 192.168.1.1 for vs-dr
/sbin/route add default gw 192.168.1.1
#showing routing table
/bin/netstat -rn
#checking if DEFAULT_GW 192.168.1.1 is reachable
ping -c 1 192.168.1.1
#set_realserver_ip_forwarding to OFF (1 on, 0 off).
echo "0" >/proc/sys/net/ipv4/ip_forward
cat /proc/sys/net/ipv4/ip_forward
#looking for DIP 192.168.1.101
ping -c 1 192.168.1.101
#looking for VIP (will be on director)
ping -c 1 192.168.1.11
#install_realserver_vip
/sbin/ifconfig lo:0 192.168.1.11 broadcast 192.168.1.11 netmask 0xffffffff up
#ifconfig output
/sbin/ifconfig lo:0
#installing route for VIP 192.168.1.11 on device lo:0
/sbin/route add -host 192.168.1.11 dev lo:0
#listing routing info for VIP 192.168.1.11
/bin/netstat -rn
#hiding interface lo:0, will not arp
echo "1" >/proc/sys/net/ipv4/conf/all/hidden
cat /proc/sys/net/ipv4/conf/all/hidden
echo "1" >/proc/sys/net/ipv4/conf/lo/hidden
cat /proc/sys/net/ipv4/conf/lo/hidden
#----------mini-rc.lvs_dr-realserver------------------
2、在第二台Real Server上运行以下脚本:
#!/bin/bash
#----------mini-rc.lvs_dr-realserver------------------
#setup IP
/sbin/ifconfig eth0 192.168.1.103 broadcast 192.168.1.255 netmask 255.255.255.0
#installing default gw 192.168.1.1 for vs-dr
/sbin/route add default gw 192.168.1.1
#showing routing table
/bin/netstat -rn
#checking if DEFAULT_GW 192.168.1.1 is reachable
ping -c 1 192.168.1.1
#set_realserver_ip_forwarding to OFF (1 on, 0 off).
echo "0" >/proc/sys/net/ipv4/ip_forward
cat /proc/sys/net/ipv4/ip_forward
#looking for DIP 192.168.1.101
ping -c 1 192.168.1.101
#looking for VIP (will be on director)
ping -c 1 192.168.1.11
#install_realserver_vip
/sbin/ifconfig lo:0 192.168.1.11 broadcast 192.168.1.11 netmask 0xffffffff up
#ifconfig output
/sbin/ifconfig lo:0
#installing route for VIP 192.168.1.11 on device lo:0
/sbin/route add -host 192.168.1.11 dev lo:0
#listing routing info for VIP 192.168.1.11
/bin/netstat -rn
#hiding interface lo:0, will not arp
echo "1" >/proc/sys/net/ipv4/conf/all/hidden
cat /proc/sys/net/ipv4/conf/all/hidden
echo "1" >/proc/sys/net/ipv4/conf/lo/hidden
cat /proc/sys/net/ipv4/conf/lo/hidden
#----------mini-rc.lvs_dr-realserver------------------
脚本执行方法请参考VS/NAT模式。
运行完成后,访问VIP(http://192.168.1.11),查看结果,第一个客户机显示:
第二个客户机显示:
注意事项:
1、基本上大部分搭载着unices和Microsoft OS的服务器都可以在VS/DR模式下作为真实服务器使用。
2、Load Balancer和所有的Real Server在物理上必须有一个网卡通过不分断的局域网相连。
3、调度器上的VIP地址对外可见;真实服务器必须将VIP绑定到Nor-ARP网卡上,它对外不可见,只是用于欺骗真实服务器用于处理目标地址为VIP的网络请求。
4、在VS/DR模式下,无需使用ip_forward功能,因此为了安全考虑,关闭了该功能。
5、真实服务器不再使用调度器作为网关,因此打开调度器的ICMP重定向。
4、你的真实服务器上必须已部署好http服务器,并为缺省主页写入不同的内容以测试调度器调度结果。
本文出自 “比尔linux运维笔记” 博客,请务必保留此出处http://chenshoubiao.blog.51cto.com/6159058/1884470
标签:lvs
原文地址:http://chenshoubiao.blog.51cto.com/6159058/1884470