This guide
configuring high availability HTTP cluster with Hearbeat on CentOS 6.5 -
64bits.
hb01 is a primary
node with IP address 123.123.123.101 to eth1
hb02 is a slave node
with IP address 123.123.123.102 to eth1.
123.123.123.100 is
the virtual IP address that will be used for our Apache webserver
HB01:
Edit file hosts
vim /etc/hosts
with content
123.123.123.101 hb01
123.123.123.102 hb02
Install EPEL and hearbeat
yum install
epel-release
yum install
heartbeat
Configurations
Copy the config sample file to directory /etc/ha.d/
cp
/usr/share/doc/heartbeat-3.0.4/authkeys /etc/ha.d/
cp
/usr/share/doc/heartbeat-3.0.4/ha.cf /etc/ha.d/
cp
/usr/share/doc/heartbeat-3.0.4/haresources /etc/ha.d/
Edit file authkeys
vim /etc/ha.d/authkeys
add these lines:
auth 2
2 crc
Change permission on
file authkeys
chmod 600
/etc/ha.d/authkeys
Edit file ha.cf
vim /etc/ha.d/ha.cf
with content:
logfile
/var/log/ha-log
logfacility local0
keepalive 2
deadtime 10
warntime 5
initdead 20
udpport 694
ucast eth1
123.123.123.102
auto_failback on
node hb01 hb02
Edit file haresources
vim /etc/ha.d/haresources
with content:
hb01 IPaddr::123.123.123.100/24/eth1:0 httpd
Start Hearbeat and
enable in start up
service heartbeat
start
chkconfig heartbeat
on
Install Apache
yum install httpd
Append some text into index.html in DocumentRoot
echo "HB01
apache test server" > /var/www/html/index.html
Start Apache and enable in startup
service httpd start
chkconfig httpd on
Allow port 80 and 964 in iptables
vim
/etc/sysconfig/iptables
Add 2 lines
-A INPUT -m state
--state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state
--state NEW -m udp -p udp --dport 694 -j ACCEPT
Save and exit
Restart IPTABLES
/etc/init.d/iptables
rerestart
HB02:
Edit file hosts
vim /etc/hosts
With content:
123.123.123.101 hb01
123.123.123.102 hb02
Install EPEL and hearbeat
yum install
epel-release
yum install
heartbeat
Go to HB01 and copy
the config file (authkeys ha.cf
haresources) to HB02
[root@hb01 ~]# cd /etc/ha.d/
[root@hb01 ~]# scp
authkeys ha.cf haresources root@123.123.123.102:/etc/ha.d/
Go to HB02
Update the
config file ha.cf
vim /etc/ha.d/ha.cf
Change line
ucast eth1
123.123.123.102
to
ucast eth1
123.123.123.101
Update the
config file haresources
vim
/etc/ha.d/haresources
Update line
hb01 IPaddr::123.123.123.100/24/eth1:0 httpd
To
hb02 IPaddr::123.123.123.100/24/eth1:0 httpd
Install Apache
yum install httpd
Append some text into index.html in DocumentRoot
echo "HB02
apache test server" > /var/www/html/index.html
Stop service apache and disable on start up
service httpd stop
chkconfig httpd off
Note: Service Apache will be handled by Heartbeat
Allow port 80 and 964 in iptables
vim
/etc/sysconfig/iptables
Add these 2 lines
-A INPUT -m state
--state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state
--state NEW -m udp -p udp --dport 694 -j ACCEPT
Save and exit
Restart IPTABLES
/etc/init.d/iptables
rerestart
Open up a browser and access to server IP:
http://123.123.123.100
will got access to ha01 server page
Now let make test to stop the heartbeat service on server ha01 and refresh the page.
We should got as the page below:
Done,
No comments:
Post a Comment