Thursday, August 27, 2009

High Availability HTTP use HeartBeat

I/ Install heartBeat

I set 2 systems as cluster servers on this example. The environment of 2 systems are like below. They have 2 NICs.

(1) www1.test.vn [eth0:192.168.0.21] [eth1:10.0.0.21]
(2) www2.test.vn [eth0:192.168.0.22] [eth1:10.0.0.22]

[1] Install HeartBeat first. It's necessary to do this on both systems.

[root@www1 ~]# yum -y install heartbeat #install heartbeat by yum
[root@www1 ~]# vi /etc/ha.d/authkey # create certificates

auth 1
1 crc

[root@www1 ~]# chmod 600 /etc/ha.d/authkeys

[2] Config for a server of (1).

[root@www1 ~]# vi /etc/ha.d/ha.cf

crm on
# debug log
debugfile /var/log/ha-debug
# log file
logfile /var/log/ha-log
# the way of output to syslog
logfacility local0
# keepalive
keepalive 2
# deadtime
deadtime 30
# deadping
deadping 40
# warntime
warntime 10
# initdead
initdead 60
# port
udpport 694
# interface and IP address of another Host
ucast eth1 10.0.0.22
# auto failback
auto_failback on
# node name (the name of "uname -n")
node www1.test.vn node www2.test.vn respawn root /usr/lib/heartbeat/pingd -m 100 -d 5s -a default_ping_set

[3] Config for a server of (2). The different point is only the section of ucast.

[root@www1 ~]#vi /etc/ha.d/ha.cf
crm on
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
deadping 40
warntime 10
initdead 60
udpport 694
# interface and IP address of another Host

ucast eth1 10.0.0.21
auto_failback on
node www1.test.vn
node www2.test.vn
respawn root /usr/lib/heartbeat/pingd -m 100 -d 5s -a default_ping_set

[4] Start HeartBeat on both server.

[root@www1 ~]#/etc/rc.d/init.d/heartbeat start
Starting High-Availability services: [ OK ]
[root@www1 ~]# chkconfig heartbeat on

[5] Run crm_mon on both server, then if following result is shown, it's OK, heartbeat running normally. These are Basical configuration of HeartBeat.

[root@www1 ~]# crm_mon -i 3
Defaulting to one-shot mode You need to have curses available at compile time to enable console mode ============ Last updated: Sun Jun 15 05:04:34 2008 Current DC: www2.test.vn (f8719a77-70b4-4e5f-851b-dafa7d65e2d3a2) 2 Nodes configured. 0 Resources configured. ============ Node: www2.test.vn (f8719a77-70b4-4e5f-851b-dafa7d65e2d3a2): online Node: www1.test.vn (2bbd6408-ec01-4b8c-bb8e-20723ee7af3a99): online

II/Configure 2 web servers for cluster. httpd is also needed.


The environment of 2 web servers are like below. And more, I set virual IP address [192.168.0.100].

(1) www1.test.vn eth0:192.168.0.21] [eth1:10.0.0.21]
(2) www2.test.vn eth0:192.168.0.22] [eth1:10.0.0.22]
(3) cluster.test.vn Virtual IP:192.168.0.100]
[1] Configure like below on both Host. if httpd is running, stop it because they are controled by HeartBeat.
[root@www1 ~]#/etc/rc.d/init.d/heartbeat stop
Stopping High-Availability services:[ OK ]
[root@www1 ~]# cd /var/lib/heartbeat/crm
[root@www1 crm]#rm -f cib.xml.*
[root@www1 crm]#vi cib.xml










[root@www1 crm]# cd
[root@www1 ~]# vi /etc/httpd/conf/httpd.conf










[root@www1 ~]# /etc/rc.d/init.d/heartbeat start
Starting High-Availability services: [ OK ]

[2] Run crm_mon after some time passed, then following result is shown, it's OK. httpd is running on primary server.

[root@www1 ~]#crm_mon -i 3
Defaulting to one-shot mode You need to have curses available at compile time to enable console mode ============ Last updated: Sun Jun 15 05:58:18 2008 Current DC: www2.test.vn (f8719a77-70b4-4e5f-851b-dafa7d65e2d3a2) 2 Nodes configured. 1 Resources configured. ============ Node: www1.test.vn (2bbd6408-ec01-4b8c-bb8e-20723ee7af3a99): online Node: www2.test.vn (f8719a77-70b4-4e5f-851b-dafa7d65e2d3a2): online Resource Group: group_apache
ipaddr (heartbeat::ocf:IPaddr): Started www1.test.vn
apache (heartbeat::ocf:apache): Started www1.test.vn
[3] Make test page on both servers and access to virtual IP. Primary server replys normally like below.




[4] Shutdown HeartBeat on primary server and verify if HeartBeat works or not.

[root@www1 ~]# /etc/rc.d/init.d/heartbeat stop
Stopping High-Availability services:[ OK ]

Access to virtual IP address you set, then running server is switched normally like below

[5] Start HeartBeat again on primary server and verify if HeartBeat
works or not.

[root@www1 ~]#/etc/rc.d/init.d/heartbeat start
Starting High-Availability services:[ OK ]



Other we can create cluster for FTP and another service by heartbeat.



2 comments:

  1. I have done it as the same you do but I get some erros .

    httpd was not stated by heartbeat. when I start httpd by hand , I get the erro "Starting httpd: (99)Cannot assign requested address: make_sock: could not bind to address 192.168.254.200:80
    no listening sockets available, shutting down
    Unable to open logs"

    what am I wrong, Mr.... ?

    I see something wrongs in cib.xml file ( are redundant)

    ReplyDelete
  2. Hi,

    This problem happend because apache can't detect virtual IP(Please give me cib.xml.I will resolve it for you).Or you can change config heartbeat use mcast(not use unicast as this document).you can prefer:http://conheotiensinh.blogspot.com/2010/04/deploy-cluster-iptables-usefwbuider-and.html and you change config apache from listen 192.168.254.200:80 to *:80

    Notes:if you use heartbeat in centos(version 5.4 and version 5.5) by yum please install which rpm packed Because by default if you install heartbeat in centos(version 5.4 and version 5.5) by yum .Heartbeat will not run

    ReplyDelete