分类: LINUX
2008-04-28 22:12:13
3、配置realserver脚本
[root@test5 chang]#vi realserver
#!/bin/sh
VIP=192.168.8.11
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add -host $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
如果有多个realserver直接添加就可以了,之后启动此脚本就可以了。
测试:分别启动realserver上的httpd服务
在realserver1 执行 echo "This is realserver1" >> /var/www/html/index.html
在realserver2 执行 echo "This is realserver2" >> /var/www/html/index.html
打开IE浏览器输入 应该可以分别看到: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上执行,目的使realserver忽略arp响应,并设定vip.