在每台web server的/etc/init.d目录下放置realserver脚本,这里主备节点同时也作为web server使用。
# vim /etc/init.d/realserver
#!/bin/bash
# chkconfig: 2345 20 80
# description: lvs_dr_realserver
#指定虚拟IP
VIP=192.168.2.254
host=`/bin/hostname`
case "$1" in
start)
# Start LVS-DR real server on this machine.
/sbin/ifconfig lo down
/sbin/ifconfig lo up
#修改相关内核参数
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
/sbin/ifconfig lo:0 $VIP netmask 255.255.255.255 up
/sbin/route add -host $VIP dev lo:0
;;
stop)
# Stop LVS-DR real server loopback device(s).
/sbin/ifconfig lo:0 down
;;
status)
# Status of LVS-DR real server.
islothere=`/sbin/ifconfig lo:0 | grep $VIP`
isrothere=`netstat -rn | grep "lo" | grep $VIP`
if [ ! "$islothere" -o ! "$isrothere" ];
then
# Either the route or the lo:0 device
# not found.
echo "LVS-DR real server Stopped."
else
echo "LVS-DR Running."
fi
;;
*)
# Invalid entry.
echo "$0: Usage: $0 {start|status|stop}"
exit 1
;;
esac
# chmod +x /etc/init.d/lvs
# chmod +x /etc/init.d/realserver
# service heartbeat start //主备LVS调度器上执行
# /etc/init.d/lvs start //主备LVS调度器上执行
# /etc/init.d/realserver start //真实web服务器上执行
# chkconfig --level 35 heartbeat on
# echo “/etc/init.d/lvs start” >> /etc/rc.local //开机启动
# echo “/etc/init.d/realserver start” >> /etc/rc.local //开机启动
三、测试
配置已经测试过了,但是不同系统环境可能会出一些意料之外的事情。
