High
Availability of linux servers using HEARTBEAT package in ubuntu
heartbeat
package is used for high availability for the linux servers, here by
configure it the load can be balanced and if any server goes down the
other will take up easily by configuring. Here we will show to
configure heartbeat package in ubuntu.
To
install heartbeat pacakage and also pacemaker
#apt-get
-y install heartbeat pacemaker
here
server1 ip address 192.168.1.111 and hostname is sunny (server name
or node)
another
server2 ip address 192.168.1.222 and hostname is venky(server name or
node)
first
of all we will install nginx in ubuntu in server1 and server2
root@sunny:~#
apt-get install nginx
root@venky:~#
apt-get install nginx
after
this we will create a dummy website and configure it, remove this
default files in both the servers
root@sunny:~#rm
-rf /etc/nginx/sites-available/defautls
root@sunny:~#rm
-rf /etc/nginx/sites-enable/defaults
root@sunny:~#vim
/etc/nginx/sites-available/basic
server
{
listen
192.168.1.111:80;
server_name
sunny.example.com;
access_log
/var/log/nginx/basic.access.log;
error_log
/var/log/nginx/basic.error.log;
location
/ {
root /var/www/basic;
index index.html
index.htm;
}
}
then
save
after
this create a directory
root@sunny:~#mkdir
/var/www/basic
root@sunny:~#vim
/etc/www/basic/index.html
sunnys
site server1
then
save
then
create a simulink
root@sunny:~#cd
/etc/nginx/sites-enable/
root@sunny:~#ln
-s ../sites-available/basic
Then
restart the service
root@sunny:~#/etc/init.d/nginx
restart
then
here we do same in the server2 but little changes
root@venky:~#vim
/etc/nginx/sites-available/basic
server
{
listen
192.168.1.222:80;
server_name
sunny.example.com;
access_log
/var/log/nginx/basic.access.log;
error_log
/var/log/nginx/basic.error.log;
location
/ {
root /var/www/basic;
index index.html
index.htm;
}
}
then
save
after
this create a directory
root@venky:~#mkdir
/var/www/basic
root@venky:~#vim
/etc/www/basic/index.html
sunnys
site this is your site two server2
then
save
then
create a simulink
root@venky:~#cd
/etc/nginx/sites-enable/
root@venky:~#ln
-s ../sites-available/basic
Then
restart the service
root@venky:~#/etc/init.d/nginx
restart
from
here we will configure heart beat
root@sunny~#
vim /etc/ha.d/ha.cf
autojoin
none
bcast eth0
warntime 3
deadtime 6
initdead 60
keepalive 1
node sunny
node venky
crm respawn
bcast eth0
warntime 3
deadtime 6
initdead 60
keepalive 1
node sunny
node venky
crm respawn
then
save
here
we copy the same in server2
root@sunny~#
scp /etc/ha.d/ha.cf venky:/etc/ha.d
root@sunny~#
( echo -ne "auth 1\n1 sha1 "; \
dd if=/dev/urandom bs=512 count=1 | openssl md5 ) \
> /etc/ha.d/authkeys
dd if=/dev/urandom bs=512 count=1 | openssl md5 ) \
> /etc/ha.d/authkeys
root@sunny:~#
chmod 0600 /etc/ha.d/authkeys
root@sunny:~#
scp /etc/ha.d/authkeys venky:/etc/ha.d
root@sunny:~#
ssh chmod 0600 venky:/etc/ha.d/authkeys
here
we will restart the service in both the servers
root@sunny:~#
/etc/init.d/heartbeat restart
root@sunny:~#
ssh venky /etc/init.d/heartbeat restart
here
both the cluster must me up and known by each other to see this we
use crm tool
root@sunny:~#
crm_mon -1 | grep Online
root@sunny:~#
crm configure
crm(live)configure#
primitive site_one_ip IPaddr params ip=192.168.1.111
cidr_netmask="255.255.255.0" nic="eth0"
crm(live)configure#
primitive site_two_ip IPaddr params ip=192.168.1.222
cidr_netmask="255.255.255.0" nic="eth0"
crm(live)configure#
commit
crm(live)configure# exit
crm(live)configure# exit
root@sunny:~#
crm configure show
node $id="1876vbiu-g98iuhgiu09-7hb0-9775" sunny.example.com
node $id="iho1ih24-4g2jjiofnufcv0-fe98sdkf7-1as sunny.example.com
primitive site_one_ip ocf:heartbeat:IPaddr \
params ip="192.168.1.111" cidr_netmask="255.255.255.0" nic="eth0"
primitive site_two_ip ocf:heartbeat:IPaddr \
params ip="192.168.1.222" cidr_netmask="255.255.255.0" nic="eth0"
node $id="1876vbiu-g98iuhgiu09-7hb0-9775" sunny.example.com
node $id="iho1ih24-4g2jjiofnufcv0-fe98sdkf7-1as sunny.example.com
primitive site_one_ip ocf:heartbeat:IPaddr \
params ip="192.168.1.111" cidr_netmask="255.255.255.0" nic="eth0"
primitive site_two_ip ocf:heartbeat:IPaddr \
params ip="192.168.1.222" cidr_netmask="255.255.255.0" nic="eth0"
root@sunny:~#
crm configure
crm(live)configure# location site_one_ip_pref site_one_ip 100: sunny.example.com
crm(live)configure# location site_two_ip_pref site_two_ip 100: sunny.example.com
crm(live)configure# commit
crm(live)configure# exit
crm(live)configure# location site_one_ip_pref site_one_ip 100: sunny.example.com
crm(live)configure# location site_two_ip_pref site_two_ip 100: sunny.example.com
crm(live)configure# commit
crm(live)configure# exit
root@sunny:~#
crm configure
crm(live)configure# monitor site_one_ip 40s:20s
crm(live)configure# monitor site_two_ip 40s:20s
crm(live)configure# commit
crm(live)configure# exit
crm(live)configure# monitor site_one_ip 40s:20s
crm(live)configure# monitor site_two_ip 40s:20s
crm(live)configure# commit
crm(live)configure# exit
after
to check check from the other system like this in local
local
system is some xyz with 192.168.1.49
in
this edit the /etc/hosts file
root@xyz:#vim
/etc/hosts
192.168.1.111
sunny.example.com sunny
192.168.1.222
sunny.example.com venky
then
save
then
serach for the website with sunny.example.com
it
will show “sunnys server1”
then
disconnect the net from server1
then
serach for sunny.example.com here the page will be redirected to the
second server
it
will display “sunny this is your server2”
No comments:
Post a Comment