測試:分別啟動realserver上的httpd服務(wù) 在realserver1 執(zhí)行 echo "This is realserver1" >> /var/www/html/index.html 在realserver2 執(zhí)行 echo "This is realserver2" >> /var/www/html/index.html 打開IE瀏覽器輸入http://192.168.8.11 應(yīng)該可以分別看到:This is realserver1 和 This is realserver2. 二、配置基于隧道模式Lvs集群 1.配置LVS directorserver 腳本 [root@test7 chang]#vi TunLVS #!/bin/sh VIP=192.168.8.11 RIP1=192.168.8.5 RIP2=192.168.8.6 /etc/rc.d/init.d/functions case "$1" in start) echo "Start Lvs of DirectorServer" #set vip server /sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255 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 -i /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -i #Run Lvs /sbin/ipvsadm ;; stop) echo "Close Lvs DirectorServer " ifconfig tunl0 down /sbin/ipvsadm -C ;; *) echo "Usage: $0 {start|stop}" exit 1 esac 2. 配置realserver [root@test5 chang]# #!/bin/sh VIP=192.168.8.11 /etc/rc.d/init.d/functions case "$1" in start) echo "tunl port starting" /sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255 up /sbin/route add -host $VIP dev tunl0 echo "1" > /proc/sys/net/ipv4/ip_forward 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 "Usege: $0 {start|stop}" exit 1 esac 此腳本分別在realserver上執(zhí)行,目的使realserver忽略arp響應(yīng),并設(shè)定vip. 三、配置基于高可用Lvs+heartbeat 確定LVS使用DR或/tun模式,請對照上面的配置,本例使用DR模式 1.配置LVS directorserver 腳本 #!/bin/sh VIP=192.168.8.11 RIP1=192.168.8.6 RIP2=192.168.8.5 /etc/rc.d/init.d/functions case "$1" in start) echo "start LVS of DirectorServer" #Set the Virtual IP Address /sbin/ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up /sbin/route add -host $VIP dev eth0:1 #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 /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g #Run Lvs /sbin/ipvsadm ;; stop) echo "close LVS Directorserver" /sbin/ipvsadm -C ;; *) echo "Usage: $0 {start|stop}" exit 1 esac 2. realserver端同樣使用上面的配置文件就可以。 |
|