LVS/DR配置笔记

DR模式配置
系统:   Redhat 内核:2.6.18-92
虚拟服务IP: 10.7.12.243
Server1: 10.7.12.26(负载服务器)
Realserver: 10.7.11.120(集群服务器)
安装2个虚拟机,网络适配器模式是brige桥模式。
在负载服务器上,配置LVS(DR模式),做web服务器的集群。实现最终用户访问虚拟IP,负载服务器,将请求分发到集群下的服务器,由集群服务器轮流提供web服务。
Redhat 的内核版本已经集成了ipvsadm功能模块,所以不需要安装,直接使用即可。
 
如果要用高版本的ipvsadm, 到 http://www.linuxvirtualserver.org/software/  
在/usr/src文件夹下:

安装ipvsadm-1.24
1, wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
2,创建一个连接文件:ln -sv /usr/src/kernels/2.6.18-92.el5-i686/ /usr/src/linux
3,解压:tar zxvf ipvsadm-1.24.tar.gz
4,安装:cd ipvsadm-1.24; make; 然后 make install
5,执行ipvsadm,检验ipvsadm 是否被正确安装 

执行ipvsadm的结果是:

 

 

[root@localhost ipvsadm-1.24]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

应该是安装成功了! 均衡器脚本:

#!/bin/bash # description: start LVS of DirectorServer

#GW=192.168.1.250 # website director vip. SNS_VIP=10.7.12.243 SNS_RIP1=10.7.12.26 SNS_RIP2=10.7.11.120

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

logger $0 called with $1

case "$1" in

start)            # set squid vip            #/sbin/ipvsadm --set 30 5 60            /sbin/ifconfig eth0:0 $SNS_VIP broadcast $SNS_VIP netmask 255.255.255.255 up            /sbin/route add -host $SNS_VIP dev eth0:0            /sbin/ipvsadm -C                       /sbin/ipvsadm -A -t $SNS_VIP:80 -s wrr -p 1            #/sbin/ipvsadm -A -t $SNS_VIP:80 -s rr            /sbin/ipvsadm -a -t $SNS_VIP:80 -r $SNS_RIP1:80 -g -w 1            #/sbin/ipvsadm -a -t $SNS_VIP:80 -r $SNS_RIP1 -g            /sbin/ipvsadm -a -t $SNS_VIP:80 -r $SNS_RIP2:80 -g -w 1            #/sbin/ipvsadm -a -t $SNS_VIP:80 -r $SNS_RIP2 -g            /sbin/ipvsadm            touch /var/lock/subsys/ipvsadm >/dev/null 2>&1            ;; stop)            /sbin/ipvsadm -C            /sbin/ipvsadm -Z      route del  $SNS_VIPdev eth0            ifconfig eth0:0 down          

           rm -rf /var/lock/subsys/ipvsadm >/dev/null 2>&1            echo "ipvsadm stoped"            ;;

status)

           if [ ! -e /var/lock/subsys/ipvsadm ];then                 echo "ipvsadm stoped"                 exit 1            else                 echo "ipvsadm OK"            fi            ;;

*)           echo "Usage: $0 {start|stop|status}"            exit 1 esac

exit 0

 

RealServer服务器脚本
#!/bin/bash
# description: Config realserver lo and apply noarp

SNS_VIP=10.7.12.243

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

case "$1" in
start)
       ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP up
       /sbin/route add -host $SNS_VIP dev lo:0
       echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
       echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
       echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
       echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
       sysctl -p >/dev/null 2>&1
       echo "RealServer Start OK"

       ;;
stop)
       ifconfig lo:0 down
       route del $SNS_VIP >/dev/null 2>&1
       echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
       echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
       echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
       echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
       echo "RealServer Stoped"
       ;;
*)
       echo "Usage: $0 {start|stop}"
       exit 1
esac

exit 0


 
 
 
在客户端反复访问:http:.//10.7.12.243如果能轮流显示出 10.7.12.26和10.7.11.120的http测试文件,即LVS(DR模式)配置完成。
 
 
 
参照:http://blog.163.com/kelly_lei/blog/static/42200562201122334140273/
 

你可能感兴趣的:(集群,LVS)