6四、Heartbeat V2基於heartbeat-ldirectord實現LVS高可用實戰

一、涉及機器html

192.168.130.61 node1.ha.com Directordnode

192.168.130.62 node2.ha.com Directordlinux

192.168.130.63 node3.ha.com RScurl

192.168.130.64 node4.ha.com RSide


二、安裝heartbeat V2測試

rpm -ivh https://mirrors.aliyun.com/epel/6Server/x86_64/Packages/e/epel-release-6-8.noarch.rpm網站

yum -y install net-snmp-libs libnet PyXML libtool-ltdlui

rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpmurl


三、配置hearbeat V2spa

openssl rand -hex 16

c20954be14c956fc9dec4f8b6565da34


cp /usr/share/doc/heartbeat-2.1.4/{authkeys,ha.cf} /etc/ha.d/


cd /etc/ha.d

echo -e "auth 2\n2 sha1 c20954be14c956fc9dec4f8b6565da34" >> authkeys

chmod 600 authkeys 


grep -v ^# ha.cf | grep -v ^$

logfile /var/log/ha-log

keepalive 1

deadtime 10

warntime 5

initdead 120

udpport 694

mcast eth0 225.0.0.1 694 1 0

auto_failback on

node node1.ha.com node2.ha.com

ping 192.168.130.2

compression     bz2

compression_threshold 2

crm on


scp -p authkeys ha.cf node2.ha.com:/etc/ha.d/

service iptables stop

chkconfig iptables off

sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

setenforce 0


四、安裝配置httpd、ipvsadm及heartbeat-ldirectord

echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf 

sysctl -p


yum -y install httpd

yum -y install ipvsadm

yum install heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm

chkconfig ldirectord off

cp /usr/share/doc/heartbeat-ldirectord-2.1.4/ldirectord.cf /etc/ha.d/


 grep -v ^# /etc/ha.d/ldirectord.cf 


checktimeout=3

checkinterval=1

autoreload=yes

logfile="/var/log/ldirectord.log"

quiescent=yes


virtual=192.168.130.15:80

        real=192.168.130.63:80 gate

        real=192.168.130.64:80 gate

        fallback=127.0.0.1:80 gate

        service=http

        request=".health.html"

        receive="OK"

        scheduler=rr

        #persistent=600

        #netmask=255.255.255.255


/etc/ha.d/ldirectord.cf root@node2.ha.com:/etc/ha.d


echo "<h1>網站正在維護</h1>" > /var/www/html/index.html


service httpd start

chkconfig httpd on

service ipvsadm stop

service ipvsadm off



五、安裝配置RS

yum -y install httpd

echo "<h1> RS1 <h1>" >> /var/www/html/index.html

service httpd start

chkconfig httpd on


echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore     

echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore    

echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce 

echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce    

ifconfig lo:0 192.168.130.15 netmask 255.255.255.255 broadcast 192.168.130.15 up

route add -host 192.168.130.15 dev lo:0


echo "OK" > /var/www/html/.health.html

echo "<h1>node1.ha.com</h1>" > /var/www/html/index.html

echo "<h1>node2.ha.com</h1>" > /var/www/html/index.html



六、基於heartbeat-gui配置heartbeat V2


須要安裝xmanager和xsell


yum -y install pygtk2-libglade

rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpm 


啓用heartbeat-gui的機器須要設置hacluster的密碼

passwd hacluster


service heartbeat start

chkconfig heartbeat on


yum -y install xorg-x11-xauth dejavu-lgc-sans-fonts

hb_gui &

1.png2.png3.png4.png5.png


七、測試

兩臺RS都正常的狀況下

[root@host ~]# curl 192.168.130.15

<h1>node1.ha.com</h1>

[root@host ~]# curl 192.168.130.15

<h1>node2.ha.com</h1>

[root@host ~]# curl 192.168.130.15

<h1>node1.ha.com</h1>

[root@host ~]# curl 192.168.130.15

<h1>node2.ha.com</h1>


停掉一臺RS的狀況下

[root@host ~]# curl 192.168.130.15

<h1>node1.ha.com</h1>

[root@host ~]# curl 192.168.130.15

<h1>node1.ha.com</h1>


兩臺RS都停掉的狀況下

[root@host ~]# curl 192.168.130.15

<h1>網站正在維護</h1>

[root@host ~]# curl 192.168.130.15

<h1>網站正在維護</h1>

相關文章
相關標籤/搜索