Linux (Centos) failover without a third-party load balance solution

In this article I describe the steps I followed in order to test a redundant Centos server setup. My goal was to create an Active/Passive Centos setup that could work without the use of any third-party load balance solutions.


Configuration steps (for each Centos LB server)

Enable yum repositories on server

# vi /etc/yum.repos.d/CentOSBase.repo

set enable to 1

Install Keepalived on both servers

# yum install keepalived

Configure keepalived config file

# vi /etc/keepalived/keepalived.conf

Set config similar to below and change state, interface, priority & virtual ip address accordantly:

[root@VLC-2 ~]# vi /etc/keepalived/keepalived.conf




notification_email_from Alexandre.Cassen@firewall.loc


smtp_connect_timeout 30

router_id LVS_DEVEL


vrrp_instance VI_1 {

state MASTER

interface eth0

virtual_router_id 51

priority 101

advert_int 1

authentication {

auth_type PASS

auth_pass 1111


virtual_ipaddress {



Start keepalived services

# service keepalived start

Check for newly created VIP address

[root@CEN-2 ~]# ip address show eth0

2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000

link/ether 00:0c:29:d1:08:f1 brd ff:ff:ff:ff:ff:ff

inet brd scope global eth0

inet scope global eth0

inet6 fe80::20c:29ff:fed1:8f1/64 scope link

valid_lft forever preferred_lft forever

[root@CEN-2 ~]#


Make Keepalived start at boot time

# chkconfig keepalived on


Configuration steps (on Master only!)

Create a process monitoring script so eth0 is disabled when “your-process” stops running

Mkdir /scripts

# vi /scripts/

Create a similar script as shown below:


# your-process process monitoring script shutdown interface eth0

while :


CURRENT=$(status your-process | awk ‘{ print $2}’ | sed ‘s/,//g’)


if [ “$CURRENT” = “$THRESHOLD” ] ; then

logger -t your-process not compliant

ifconfig eth0 down



logger -t your-process compliant

sleep 15



Test the script is running by checking the /var/log/messages entries. This should look similar to this:

# tailf /var/log/messages

Oct 18 20:50:06 VLC1 puppet-agent[1666]: Finished catalog run in 22.05 seconds

Oct 18 20:50:07 VLC1 your-process: compliant

Oct 18 20:50:22 VLC1 your-process: compliant

Make start at boot time and run it as a background process so it will not intervene with the normal boot process of the VLC server

# vi /etc/init.d/



#Call your-process script and run in background

exec /scripts/ &



Change to obtain execution rights

# chmod +x

Make it run after the boot sequence

# echo /etc/init.d/ >> /etc/rc.local

Reboot the CentOS and check the process has started

# ps ax | grep your-process

1637 ?        S      0:00 /bin/bash /scripts/

4663 pts/0    S+     0:00 grep your-process


Although Keepalive and the process monitoring script are not ideal. They can be useful when you like to test or need to demonstrate a redundant setup with no access to third party solutions.

Your comments or thoughts are more than welcome!

Geplaatst op oktober 19, 2015, in Failover, Linux en getagd als , , , , . Markeer de permalink als favoriet. Een reactie plaatsen.

Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen. logo

Je reageert onder je account. Log uit /  Bijwerken )

Google photo

Je reageert onder je Google account. Log uit /  Bijwerken )


Je reageert onder je Twitter account. Log uit /  Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit /  Bijwerken )

Verbinden met %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers liken dit: