All about High Availability


In a scenario where the Network Administrative Server [NAS] has some data on a file ‘book’.
NAS is connected to 2PCs, Primary Node & Adaptive Node. Here a Client is connected to the
Primary Node initially. Adaptive Node checks the heartbit of Primay Node, if fails then acts
itself as Primary Node. NAS exports the directory of book to tne Network. Primay Node
mounts it & delivers it to Client PC & checks its own Health by counting Memory.
This Scenario can be solved by writing 7 small Shell Script. Partitioning Problem
as follows
1. Script1 reads a line from ‘book’ & write to ‘verse’, another file | run in NAS
2. Script2 reads the file ‘verse’, mounted in Primary Node by ftp | run in Client PC
3. Script3 exports the directory to network which contains files & scripts | run in NAS
4. Script4 mounts the directory exported by NAS to ‘a directory in Primary Node’
known as Mountpoint | run in Primary Node
5. Script5 checks the heartbit of Primay Node, if fails then change the IP into
the IP of Primary Node | run in Adaptive Node
6. Script6 checks the Health of Primary Node by Memory, if ill then restart
itself | run in Primary Node
Codes r given below:
Script1:
#!/bin/sh
while read LINE
do
echo $LINE
echo $LINE > verse
sleep 2
done < book
Script2:
#!/bin/sh
if [ “$1” == “” ] || [ “$2” == “” ]
then
echo “Usage: script2 [IP of Primary node] [Directory of content(verse) in remote PC]”
else
while [ 1 ]
do
echo -n
ftp -n -i $1 <<Srijon
user client ”
cd $2
mget verse
bye
Srijon

  1. mget used instead of get to maintain Accurate filename without unrecognised character

cat verse
sleep 2
done
fi

Script3:
#!/bin/sh
chmod 777 `pwd`

  1. stops SELinux enforced administration tool for IPv4 packet filtering and NAT

service iptables stop
service nfs start

  1. -o = Options; rw = read-wtite mode; subtree_check = export with subtrees;
  2. insecure,insecure_locks = disables selinux security & allows clients with NFS
  3. implementations that don’t use a reserved port for NFS; fsid == filesystem ID;
  4. anonuid = Anonymous User ID; anongid = Anonymous Group ID
  5. fsid=anonuid=anongid=0 means all export IDs is verified by root

exportfs *:`pwd`

Script4:
#!/bin/sh
if [ “$1” == “” ]
then
echo “Usage: script4 [IP of NAS]”
else
service nfs start
service vsftpd start

  1. Required for connecting ftp users to this PC otherwise SELinux blocks the ACCESS
  2. piping commands to find the dir to mount exported by NAS

dir=`showmount -e $1 | grep / | awk ‘{print $1}’`
mkdir $dir

  1. mkdir returns 0 in Success

if [ $? != 0 ]
then
rmdir -p $dir
mkdir $dir
fi
mount -o rw $1:$dir $dir
fi

Script5:
#!/bin/sh
if [ “$1” = “” ] || [ “$2” = “” ]
then
echo “Usage: script5 [IP of Primary node] [IP of NAS]”;
else
service nfs start
service vsftpd start

  1. ping only 8 byte of data from Primary Node

ping $1 -s 0

  1. ping returns 0 in Success

while [ $? == 0 ]
do
ping $1 -s 0
echo “Primary node is Alive”
sleep 1
done
echo “!Primary node failed”

  1. Add IP of Primary Node having netmask 255.255.255.0 for device eth0

ip addr add $1/24 dev eth0
dir=`showmount -e $2 | grep / | awk ‘{print $1}’`
mkdir $dir
if [ $? != 0 ]
then
rmdir -p $dir

mkdir $dir
fi
mount -o rw $2:$dir $dir
fi
Script6:
#!/bin/sh
if [ “$1” == “” ]
then
echo “Usage: script6 [maximum RAM is allowed to use in KB]”
else
echo “Memory:”
echo “|   USED     |   LIMIT     |”
echo “—————————-”
while [ 1 ]
do
#’free’ returns a line contains ‘Mem’ pipe the output to grep where
used=`free | grep Mem | awk ‘{ print $3 }’`
echo “|   $used   |   $1   |”
sleep 2
#if $a is less than parameter specified then
if [ $used -gt $1 ]
then

  1. init 0 = Shutdown
  2. init 1 = single user mode
  3. init 3 = disable gui [close X Server] multiuser mode
  4. init 5 = Enable X Server [multiuser mode][DEFAULT]
  5. init 6 = reboot
  6. More info: man init

init 6
fi
done
fi

############################################################
To run these Scripts a Prerequisite Script is to run in Primary Node & Adaptive Node
Prerequisite Script Code:
#!/bin/sh
#Run this in Primary node & Adaptive Node
groupadd srijon -f
useradd client -g srijon
passwd client -d                  # Delete passwd for user client
# setsebool -P ftp_home_dir=1 means SET SELinux boolean to true for $HOME of ftp users
setsebool -P ftp_home_dir=1

############################################################

Advertisements