直接路由模式lvs

配置基于IP隧道模式Lvs集群
1.升级linux内核(参考http://blog.sina.com.cn/u/4964dd65010009x3这篇文章)
2.下载ipvsadm管理程序
http://www.linuxvirtualserver.org/software/
注意对应自己的内核版本
ipvsadm-1.24.tar.gz
tar zxvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24
make
make install
3.配置lvs server
vim /etc/init.d/tunlvs.sh
#!/bin/sh
# description: start LVS of Directorserver
VIP=192.168.25.41(注意,lvs server那台机器2个ip,一个是vip,一个是本身ip例如192.168.25.42)
RIP1=192.168.25.44
RIP2=192.168.25.45
#RIPn=192.168.0.n
GW=192.168.25.254

/etc/rc.d/init.d/functions

case "$1" in
start)
echo " start LVS of DirectorServer"
# set the Virtual IP Address
/sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.0 up
/sbin/route add -host $VIP dev tunl0
#Clear IPVS table
/sbin/ipvsadm -C
#set LVS
/sbin/ipvsadm -A -t $VIP:80 -s rr
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g -w 1
/sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g -w 1
#/sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -g -w 1
#Run LVS
/sbin/ipvsadm
#end

;;
stop)
echo "close LVS Directorserver"
ifconfig tunl0 down
/sbin/ipvsadm -C
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
4.配置real server
vim /etc/init.d/tunlvs.sh
#!/bin/sh
# ghb in 20060812
# description: Config realserver tunl port and apply arp patch
VIP=192.168.25.43

/etc/rc.d/init.d/functions

case "$1" in
start)
echo "Tunl port starting"
ifconfig tunl0 $VIP netmask 255.255.255.0 broadcast $VIP up
/sbin/route add -host $VIP dev tunl0
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
sysctl -p

;;
stop)
echo "Tunl port closing"
ifconfig tunl0 down
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac

注意:一定要关闭real server的防火墙,否则lvs server无法分发

这样我们就可以通过apache来测试,3台机器上分别配置apache,这样就可以来测试。分别启动以上脚本和apache服务

一个官方的文档:写的不错:)http://www.ultramonkey.org/papers/lvs_tutorial/html/

 

你可能感兴趣的:(LVS)