Setup of multiple (in this case 2) Oracle Linux servers in a cluster with a virtual IP (VIP). The intention is that the VIP is always active on exactly one server machine.
Apache is installed on both machines. When navigating to the default page, the document root is shown.
In the “/root” directory, create a start and a stop script that will be executed when the virtual ip defined by ucarp comes up or goes down.
Change the general “vip-common.conf” file:
[root@ol6a ~]# more /etc/ucarp/vip-common.conf
# Common VIP settings which can be overridden in individual vip-<nnnn>.conf
PASSWORD="MyPwd1"
BIND_INTERFACE="eth0"
SOURCE_ADDRESS="192.168.56.121"
# If you have extra options to add, see "ucarp --help" output
OPTIONS="--shutdown --preempt"
Create an appropriate config file:
[root@ol6a ~]# more /etc/ucarp/vip-ol6.conf
ID=001
BIND_INTERFACE="eth0"
SOURCE_ADDRESS="192.168.56.121"
VIP_ADDRESS="192.168.56.120"
PASSWORD="MyPwd1"
UPSCRIPT=/root/vip_up.sh
DOWNSCRIPT=/root/vip_down.sh
OPTIONS="--shutdown --preempt --advbase 10"
Check the current data for the “eth0” interface:
[root@ol6a ~]# ip addr sh eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:7b:6a:3f brd ff:ff:ff:ff:ff:ff
inet 192.168.56.121/24 brd 192.168.56.255 scope global eth0
inet6 fe80::a00:27ff:fe7b:6a3f/64 scope link
valid_lft forever preferred_lft forever
Installation / Configuration steps on the second machine
Change the general “vip-common.conf” file:
[root@ol6b ~]# more /etc/ucarp/vip-common.conf
# Common VIP settings which can be overridden in individual vip-<nnnn>.conf
PASSWORD="MyPwd1"
BIND_INTERFACE="eth0"
SOURCE_ADDRESS="192.168.56.122"
# If you have extra options to add, see "ucarp --help" output
OPTIONS="--shutdown --preempt"
Create an appropriate config file:
[root@ol6b ~]# more /etc/ucarp/vip-ol6.conf
ID=001
BIND_INTERFACE="eth0"
SOURCE_ADDRESS="192.168.56.122"
VIP_ADDRESS="192.168.56.120"
PASSWORD="MyPwd1"
UPSCRIPT=/root/vip_up.sh
DOWNSCRIPT=/root/vip_down.sh
OPTIONS="--shutdown --preempt --advbase 10"
Check the current data for the “eth0” interface:
[root@ol6b ~]# ip addr sh eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:d1:09:96 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.122/24 brd 192.168.56.255 scope global eth0
inet6 fe80::a00:27ff:fed1:996/64 scope link
valid_lft forever preferred_lft forever
Test Process
(1)
On the first machine, start the ucarp service:
[root@ol6a ~]# service ucarp start
Starting common address redundancy protocol daemon: [ OK ]
(2)
Check if the VIP becomes active on this host:
[root@ol6a ~]# ip addr sh eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:7b:6a:3f brd ff:ff:ff:ff:ff:ff
inet 192.168.56.121/24 brd 192.168.56.255 scope global eth0
inet 192.168.56.120/24 scope global secondary eth0
inet6 fe80::a00:27ff:fe7b:6a3f/64 scope link
valid_lft forever preferred_lft forever
=> OK
Check the logfile populated by the “up” script:
[root@ol6a ~]# more /root/vip.txt
down:
Sat Feb 21 11:55:14 CET 2015
up:
Sat Feb 21 11:55:52 CET 2015
=> OK, note that the first logging comes from the “down” script
(3)
On the second machine, start the ucarp service as well:
[root@ol6b ~]# service ucarp start
Starting common address redundancy protocol daemon: [ OK ]
(4)
The VIP doesn’t have to come up on this host:
[root@ol6b ~]# ip addr sh eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:d1:09:96 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.122/24 brd 192.168.56.255 scope global eth0
inet6 fe80::a00:27ff:fed1:996/64 scope link
valid_lft forever preferred_lft forever
=> OK, the VIP is not active here
(5)
Navigate to the the Apache web page through the hostname linked to the VIP and check if the web page is accessible.
(6)
Stop the ucarp service on the first machine:
[root@ol6a ~]# service ucarp stop
Stopping common address redundancy protocol daemon: [ OK ]
An extra “down” message must be added tot the logfile:
[root@ol6a ~]# more /root/vip.txt
down:
Sat Feb 21 11:55:14 CET 2015
up:
Sat Feb 21 11:55:52 CET 2015
down:
Sat Feb 21 11:58:12 CET 2015
=> OK
Check if the VIP becomes active on the second host machine:
[root@ol6b ~]# ip addr sh eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:d1:09:96 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.122/24 brd 192.168.56.255 scope global eth0
inet 192.168.56.120/24 scope global secondary eth0
inet6 fe80::a00:27ff:fed1:996/64 scope link
valid_lft forever preferred_lft forever
=> OK
Check the logfile on the second machine and verify if there is an extra “up” message:
[root@ol6b ~]# more /root/vip.txt
down:
Sat Feb 21 11:56:31 CET 2015
up:
Sat Feb 21 11:58:42 CET 2015
=> OK
(7)
Refresh the webpage: you should see now the content of the second web server.
(8)
Stop all ucarp services on both machines.
Change the scripts “vip_up.sh” and “vip_down.sh” to execute the log script by user “tom”:
[root@ol6a ~]# tail -4 vip_up.sh
# Write to logfile
# echo "up:" >> /root/vip.txt
# date >> /root/vip.txt
su - tom -c /home/tom/log_up.sh
[root@ol6a ~]# tail -4 vip_down.sh
# Write to logfile
# echo "down:" >> /root/vip.txt
# date >> /root/vip.txt
su - tom -c /home/tom/log_down.sh
[root@ol6b ~]# tail -4 vip_up.sh
# Write to logfile
# echo "up:" >> /root/vip.txt
# date >> /root/vip.txt
su - tom -c /home/tom/log_up.sh
[root@ol6b ~]# tail -4 vip_down.sh
# Write to logfile
# echo "down:" >> /root/vip.txt
# date >> /root/vip.txt
su - tom -c /home/tom/log_down.sh
(9)
Start again the ucarp service on the first machine only:
[root@ol6a ~]# service ucarp start
Starting common address redundancy protocol daemon: [ OK ]
Check the IP config:
[root@ol6a ~]# ip addr sh eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:7b:6a:3f brd ff:ff:ff:ff:ff:ff
inet 192.168.56.121/24 brd 192.168.56.255 scope global eth0
inet 192.168.56.120/24 scope global secondary eth0
inet6 fe80::a00:27ff:fe7b:6a3f/64 scope link
valid_lft forever preferred_lft forever
=> OK
Check the log file:
[root@ol6a ~]# more /home/tom/vip.txt
down:
Sat Feb 21 13:24:44 CET 2015
up:
Sat Feb 21 13:25:22 CET 2015
=> OK
Start the ucarp service on the second machine:
[root@ol6b ~]# service ucarp start
Starting common address redundancy protocol daemon: [ OK ]
Check the IP config:
[root@ol6b ~]# ip addr sh eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:d1:09:96 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.122/24 brd 192.168.56.255 scope global eth0
inet6 fe80::a00:27ff:fed1:996/64 scope link
valid_lft forever preferred_lft forever
=> OK, the VIP is not active
Check the log file:
[root@ol6b ~]# more /home/tom/vip.txt
down:
Sat Feb 21 13:25:49 CET 2015
(10)
Stop the ucarp service on the first machine.
[root@ol6a ~]# service ucarp stop
Stopping common address redundancy protocol daemon: [ OK ]
There is a new “down” entry in the logfile:
[root@ol6a ~]# more /home/tom/vip.txt
down:
Sat Feb 21 13:15:17 CET 2015
up:
Sat Feb 21 13:15:55 CET 2015
down:
Sat Feb 21 13:20:43 CET 2015
On the second machine, check the IP config:
[root@ol6b ~]# ip addr sh eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:d1:09:96 brd ff:ff:ff:ff:ff:ff
inet 192.168.56.122/24 brd 192.168.56.255 scope global eth0
inet 192.168.56.120/24 scope global secondary eth0
inet6 fe80::a00:27ff:fed1:996/64 scope link
valid_lft forever preferred_lft forever
=> OK, the VIP is active
Check also the log file:
[root@ol6b ~]# tail -f /home/tom/vip.txt
down:
Sat Feb 21 13:25:49 CET 2015
up:
Sat Feb 21 13:28:52 CET 2015
=> OK