Keepalived To Provide IP Failover on Redhat Linux



Install Keepalived
Before installing Keepalived, any previously installed version should be removed.

1. Download the latest Keepalived source code from the web site (keepalived.org) and unzip/untar it.
Dependancies
In order to compile Keepalived you need to have the following libraries installed:
Install Kernel Headers
You need to install the following packages:

  • Kernel-headers - includes the C header files that specify the interface between the Linux kernel and userspace libraries and programs. The header files define structures and constants that are needed for building most standard programs and are also needed for rebuilding the glibc package.
  • kernel-devel - this package provides kernel headers and makefiles sufficient to build modules against the kernel package.
  • OpenSSL, : This library is needed for MD5 and SSL support.
  • popt, : Used for command line parsing.
Make sure kernel-headers, kernel-devel, opnessl, openssl-devel, popt and popt-devel packages are installed. If not type the following install the same:
# yum -y install kernel-headers kernel-devel openssl openssl-devel popt popt-devel
Compile keepalived
Move to your keepalived folder and type the following command: # ./configure --with-kernel-dir=/lib/modules/$(uname -r)/build
Compile and install the same:
# make && make install

Create Required Softlinks
Type the following commands to create service and run it at RHEL / CentOS run level #3 and #5 :
# ln -s /usr/local/etc/sysconfig/keepalived /etc/sysconfig
# ln -s /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/

# chkconfig –level 35 keepalived on
Keepalived seems searching the config file in /etc/keepalived so create soft link:
# ln -s /usr/local/etc/keepalived/ /etc/keepalived
Modify The Script
modify the keepalived script as follow :

# vim /usr/local/etc/rc.d/init.d/keepalived
.........................................
........................................
start() {
echo -n $"Starting $prog: "
daemon /usr/local/sbin/keepalived ${KEEPALIVED_OPTIONS}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog
}
....................................................................
....................................................................
Configuration
Your main configuration directory is located at /usr/local/etc/keepalived and configuration file name is keepalived.conf. First, make backup of existing configuration:
# cd /usr/local/etc/keepalived
# cp keepalived.conf keepalived.conf.bak

Edit keepalived.conf as follows on Server1:

vrrp_instance VI_1 {
        interface eth0
        state MASTER
        virtual_router_id 51
        priority 101
        authentication {
            auth_type PASS
            auth_pass Add-Your-Password-Here
        }
        virtual_ipaddress {
                192.168.0.110 dev eth0
        }
}
Edit keepalived.conf as follows on Server2: (note priority set to 100 i.e. backup load balancer):

vrrp_instance VI_1 {
        interface eth0
        state BACKUP
        virtual_router_id 51
        priority 100
        authentication {
            auth_type PASS
            auth_pass Add-Your-Password-Here
        }
        virtual_ipaddress {
                192.168.0.110 dev eth1
        }
}
VRRP Instance definitions

1. vrrp_instance

Each interface needs at least one vrrp_instance. Each vrrp_instance is a group of VIPs that are logically grouped together. You can have as many vrrp_instaces as you want.

2. virtual_router_id

Each virtual_router_id must be unique per instance name. Instance names are the same on MASTER and BACKUP (VI_1), so the virtual router_id is the same as VI_1 on the MASTER and BACKUP.

3. Priority

MASTER and BACKUP state are determined by the priority even if you specify MASTER as the state, the state will be voted on by priority (so if your state is MASTER but your priority is lower than the router with BACKUP, you will lose the MASTER state)


Start Keepalived

Finally start keepalived on both Server1 and Server2 as follows:
# /etc/init.d/keepalived start

Verify: Keepalived Working Or Not

/var/log/messages will keep track of VIP:

# tail -f /var/log/messages

Verify that VIP assigned to eth0:

# ip addr show eth0

ping failover test

Open terminal on any other computer on same network and type the following command to ping to VIP:

# ping 192.168.0.110


Login to server1 and
halt the server or take down networking:

# halt

Within seconds VIP should move from server1 to server2 and you should not see any drops in ping. On server1 and server2 open the /var/log/messages file.

Conclusion

Your server is now configured with IP failover.
Share on Google Plus

About bles

IT Trainer | MCSE | CCNA | RHCE | +91 984 679 1609. LinkedIn | Google
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment