实验平台:virtualbox 4.12
操作系统:RHEL5.4
实验拓扑:
- [root@R1 ~]#yum install httpd -y
- [root@R1 ~]#echo '<h1>Realserver1</h1> <body bgcolor=red</body>' > /var/www/html/index.html
- [root@R2 ~]#yum install httpd -y
- [root@R2 ~]#echo '<h1>Realserver2</h1> <body bgcolor=red</body>' > /var/www/html/index.html
- [root@node1 ~]# yum install ipvsadm -y
- [root@node2 ~]# yum install ipvsadm -y
- #!/bin/bash
- . /etc/rc.d/init.d/functions
- VIP=192.168.56.20
- RIP1=192.168.56.11
- RIP2=192.168.56.12
- PORT=80
- case "$1" in
- start)
- /sbin/ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up
- /sbin/route add -host $VIP dev eth0:1
- echo 1 > /proc/sys/net/ipv4/ip_forward
- # 清除已有的iptables配置
- /sbin/iptables -F
- /sbin/iptables -Z
- # 清除已有的ipvsadm 规则
- /sbin/ipvsadm -C
- # 添加VIP
- /sbin/ipvsadm -A -t $VIP:80 -s wlc
- # 在Directory下添加Realserver
- /sbin/ipvsadm -a -t $VIP:80 -r $RIP1 -g -w 1
- /sbin/ipvsadm -a -t $VIP:80 -r $RIP2 -g -w 2
- /bin/touch /var/lock/subsys/ipvsadm &> /dev/null
- ;;
- stop)
- echo 0 > /proc/sys/net/ipv4/ip_forward
- /sbin/ipvsadm -C
- /sbin/ifconfig eth0:1 down
- /sbin/route del $VIP
- /bin/rm -f /var/lock/subsys/ipvsadm
- echo "ipvs is stopped..."
- ;;
- status)
- if [ ! -e /var/lock/subsys/ipvsadm ]; then
- echo "ipvsadm is stopped ..."
- else
- echo "ipvs is running ..."
- ipvsadm -L -n
- fi
- ;;
- *)
- echo "Usage: $0 {start|stop|status}"
- ;;
- esac
- [root@node1 ~]#chmod a+x /etc/init.d/ipvsadm.sh
- [root@node1 ~]# vim /etc/ha.d/haresources
- node1.a.org 192.168.56.20/24/eth0/192.168.56.255 ipvs
[root@node1 ~]# scp /etc/ha.d/haresources node2:/etc/ha.d/
- #vim /etc/init.d/realserver.sh
- #!/bin/bash
- # Script to start LVS DR real server.
- # description: LVS DR real server
- . /etc/rc.d/init.d/functions
- VIP=192.168.56.20
- 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 broadcast $VIP netmask 255.255.255.255 up
- /sbin/route add -host $VIP dev lo:0
- ;;
- stop)
- /sbin/ifconfig lo:0 down
- 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
- ;;
- status)
- # Status of LVS-DR real server.
- islothere=`/sbin/ifconfig lo:0 | grep $VIP`
- isrothere=`netstat -rn | grep "lo:0" | 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 real server Running."
- fi
- ;;
- *)
- # Invalid entry.
- echo "$0: Usage: $0 {start|status|stop}"
- exit 1
- ;;
- esac
- [root@R1 ~]# chmod a+x /etc/init.d/rs.sh
- [root@R1 ~]# scp /etc/init.d/rs.sh 192.168.56.12:/etc/init.d/
- [root@node1 ~]# /etc/init.d/heartbeat start
- [root@node1 ~]# ssh node2 -- '/etc/init.d/heartbeat start'
- [root@node1 ~]# /etc/init.d/ipvs start
- [root@R1 ~]# /etc/init.d/rs.sh start
- [root@R2 ~]# /etc/init.d/rs.sh start