VIP 192.168.3.240
DR1 192.168.3.128/4.128
DR2 192.168.3.129/4.129
realserver 192.168.3.130
realserver 192.168.3.131



tar -xf heartbeat-2.1.3.tar.gz

   11  cd heartbeat-2.1.3
   12  ls
   13  ./ConfigureMe configure --disable-swig --disable-snmp-subagent
   14  make
   15  make install
   16  cp doc/ha.cf doc/haresources doc/authkeys /etc/ha.d/
   17  cp ldirectord/ldirectord.cf /etc/ha.d/
   18  groupadd -g 694 haclient
   19  useradd -u 694 -g haclient hacluster
yum install perl-MailTools
yum install libnet
yum install ipvsadm


[root@DR1 ~]# grep -v -E '^#|^$' /etc/ha.d/ldirectord.cf
checktimeout=20
checkinterval=10
fallback=127.0.0.1:80
autoreload=yes
logfile="/var/log/ldirectord.log"
quiescent=yes
virtual=192.168.3.240:80
        real=192.168.3.130:80 gate
        real=192.168.3.131:80 gate
        fallback=127.0.0.1:80 gate
        service=http
        request="index.html"
        scheduler=rr
        protocol=tcp
[root@DR1 ~]# grep -v -E '^#|^$' /etc/ha.d/authkeys  权限600 DR2一样
auth 1
1 crc
[root@DR1 ~]# grep -v -E '^#|^$' /etc/ha.d/ha.cf
logfile /var/log/ha-log
bcast   eth1
logfacility     local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
auto_failback on
node    DR1
node    DR2
ping 192.168.1.7[root@DR1 ~]# grep -v -E '^#|^$' /etc/ha.d/haresources
DR1 IPaddr::192.168.3.240/24/eth0 ldirectord
--------------------------------------------------------------------------------

[root@DR2 ~]# grep -v -E '^#|^$' /etc/ha.d/ldirectord.cf
checktimeout=20
checkinterval=10
fallback=127.0.0.1:80
autoreload=yes
logfile="/var/log/ldirectord.log"
quiescent=yes
virtual=192.168.3.240:80
        real=192.168.3.130:80 gate
        real=192.168.3.131:80 gate
        fallback=127.0.0.1:80 gate
        service=http
        request="index.html"
        scheduler=rr
        protocol=tcp
[root@DR2 ~]# grep -v -E '^#|^$' /etc/ha.d/authkeys
auth 1
1 crc
[root@DR2 ~]# grep -v -E '^#|^$' /etc/ha.d/ha.cf
logfile /var/log/ha-log
bcast   eth1
logfacility     local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
auto_failback on
node    DR1
node    DR2
ping 192.168.1.7
[root@DR2 ~]# grep -v -E '^#|^$' /etc/ha.d/haresources
DR1 IPaddr::192.168.3.240/24/eth0 ldirectord

---------------------------------------------------------------------------
[root@realserver1 ~]# cat /etc/init.d/lvsrs
#!/bin/bash
VIP=192.168.3.240
./etc/init.d/functions
case "$1" in
start)
echo "start lvs of real server"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 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
;;
stop)
/sbin/ifconfig lo:0 down
echo "shutdown lvs firector server"
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 "USage:$0 {start|stop}"
exit 1
esac


[root@realserver2 ~]# cat /etc/init.d/lvsrs
#!/bin/bash
VIP=192.168.3.240
./etc/init.d/functions
case "$1" in
start)
echo "start lvs of real server"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 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
;;
stop)
/sbin/ifconfig lo:0 down
echo "shutdown lvs firector server"
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 "USage:$0 {start|stop}"
exit 1
esac


[zhoutao@WorkSpace ~]$ while true ; do curl 192.168.3.240 `sleep 1`; done
130
131
130
131
130
131
130


[root@realserver1 ~]# /etc/init.d/httpd stop
停止 httpd:                                               [确定]
[zhoutao@WorkSpace ~]$ while true ; do curl 192.168.3.240 `sleep 1`; done
131
131
131
131
131
131
131
131
[root@realserver1 ~]# /etc/init.d/httpd start
启动 httpd:                                               [确定]
[zhoutao@WorkSpace ~]$ while true ; do curl 192.168.3.240 `sleep 1`; done
130
131
130
131
130
131
130
131
130
--------------------------------------------------------------------------

[root@DR2 ~]# /etc/init.d/heartbeat stop
Stopping High-Availability services:
                                                           [确定]
heartbeat[1222]: 2012/03/20_04:26:26 WARN: node dr2: is dead
heartbeat[1222]: 2012/03/20_04:26:26 info: Dead node dr2 gave up resources.
heartbeat[1222]: 2012/03/20_04:26:26 info: Link dr2:eth1 dead
------------------------------

[root@DR2 ~]# /etc/init.d/heartbeat start
Starting High-Availability services:
                                                           [确定]
[root@DR1 ~]# tail -f /var/log/ha-log

heartbeat[1222]: 2012/03/20_04:28:06 info: Heartbeat restart on node dr2
heartbeat[1222]: 2012/03/20_04:28:06 info: Link dr2:eth1 up.
heartbeat[1222]: 2012/03/20_04:28:06 info: Status update for node dr2: status init
heartbeat[1222]: 2012/03/20_04:28:06 info: Status update for node dr2: status up
harc[2306]:     2012/03/20_04:28:06 info: Running /etc/ha.d/rc.d/status status
harc[2323]:     2012/03/20_04:28:06 info: Running /etc/ha.d/rc.d/status status
heartbeat[1222]: 2012/03/20_04:28:07 info: Status update for node dr2: status active
harc[2339]:     2012/03/20_04:28:07 info: Running /etc/ha.d/rc.d/status status
heartbeat[1222]: 2012/03/20_04:28:08 info: remote resource transition completed.
heartbeat[1222]: 2012/03/20_04:28:08 info: dr1 wants to go standby [foreign]
heartbeat[1222]: 2012/03/20_04:28:08 info: standby: dr2 can take our foreign resources
heartbeat[2355]: 2012/03/20_04:28:08 info: give up foreign HA resources (standby).
heartbeat[2355]: 2012/03/20_04:28:08 info: foreign HA resource release completed (standby).
heartbeat[1222]: 2012/03/20_04:28:08 info: Local standby process completed [foreign].
heartbeat[1222]: 2012/03/20_04:28:09 WARN: 1 lost packet(s) for [dr2] [10:12]
heartbeat[1222]: 2012/03/20_04:28:09 info: remote resource transition completed.
heartbeat[1222]: 2012/03/20_04:28:09 info: No pkts missing from dr2!
heartbeat[1222]: 2012/03/20_04:28:09 info: Other node completed standby takeover of foreign resources.


DR2上heartbeat[4759]: 2012/03/20_04:28:07 info: Status update for node dr1: status active
heartbeat[4759]: 2012/03/20_04:28:07 info: Link 192.168.1.7:192.168.1.7 up.
heartbeat[4759]: 2012/03/20_04:28:07 info: Status update for node 192.168.1.7: status ping
harc[4768]:     2012/03/20_04:28:07 info: Running /etc/ha.d/rc.d/status status
heartbeat[4759]: 2012/03/20_04:28:07 info: Comm_now_up(): updating status to active
heartbeat[4759]: 2012/03/20_04:28:07 info: Local status now set to: 'active'
heartbeat[4759]: 2012/03/20_04:28:08 info: remote resource transition completed.
heartbeat[4759]: 2012/03/20_04:28:08 info: remote resource transition completed.
heartbeat[4759]: 2012/03/20_04:28:08 info: Local Resource acquisition completed. (none)
heartbeat[4759]: 2012/03/20_04:28:08 info: dr1 wants to go standby [foreign]
heartbeat[4759]: 2012/03/20_04:28:09 info: standby: acquire [foreign] resources from dr1
heartbeat[4787]: 2012/03/20_04:28:09 info: acquire local HA resources (standby).
heartbeat[4787]: 2012/03/20_04:28:09 info: local HA resource acquisition completed (standby).
heartbeat[4759]: 2012/03/20_04:28:09 info: Standby resource acquisition done [foreign].
heartbeat[4759]: 2012/03/20_04:28:09 info: Initial resource acquisition complete (auto_failback)
heartbeat[4759]: 2012/03/20_04:28:09 info: remote resource transition completed.