Configuracion KeepAlive
Configuracion KeepAlive
Configuracion KeepAlive
html
In this article, we will configure a Floating IP address for the cluster of two web servers by
using KeepAlived.
Table of Contents:
What is KeepAlived? :
Keepalived is a routing software written in C. The main goal of this project is to provide simple
and robust facilities for loadbalancing and high-availability to Linux system and Linux based
infrastructures. Loadbalancing framework relies on well-known and widely used Linux Virtual
Server (IPVS) kernel module providing Layer4 loadbalancing. Keepalived implements a set of
checkers to dynamically and adaptively maintain and manage loadbalanced server pool
according their health. On the other hand high-availability is achieved by VRRP protocol. VRRP
is a fundamental brick for router failover. In addition, Keepalived implements a set of hooks to
the VRRP finite state machine providing low-level and high-speed protocol interactions.
Keepalived frameworks can be used independently or all together to provide resilient
infrastructures.
KeepAlived performs well with haproxy load balancers. Have a look at our article on how to
install and configure haproxy load balancer on CentOS 7.
System Specification:
Dependencies Resolved
==============================================================================
==
Package Arch Version Repository
Size
==============================================================================
==
Installing:
keepalived x86_64 1.2.10-2.el7 localyum 218
k
Installing for dependencies:
net-snmp-agent-libs x86_64 1:5.7.2-18.el7 localyum 698
k
net-snmp-libs x86_64 1:5.7.2-18.el7 localyum 745
k
Transaction Summary
==============================================================================
==
Install 1 Package (+2 Dependent packages)
Installed:
keepalived.x86_64 0:1.2.10-2.el7
Dependency Installed:
net-snmp-agent-libs.x86_64 1:5.7.2-18.el7 net-snmp-libs.x86_64 1:5.7.2-
18.el7
Complete!
Set Linux Kernel parameters as follows to support Floating IP.
[root@webserver-01 ~]# echo "net.ipv4.ip_nonlocal_bind = 1" >>
/etc/sysctl.conf
[root@webserver-01 ~]# sysctl -p
net.ipv4.ip_nonlocal_bind = 1
[root@webserver-01 ~]# systemctl stop firewalld; systemctl disable firewalld
Now configure keepalived settings.
[root@webserver-01 ~]# cd /etc/keepalived/
[root@webserver-01 keepalived]# mv keepalived.conf keepalived.conf.org
[root@webserver-01 keepalived]# vi keepalived.conf
Add following directives and save.
! Configuration File for keepalived
global_defs {
notification_email {
root@webserver-01.centlinux.com
}
notification_email_from root@webserver-01.centlinux.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eno16777728
virtual_router_id 51
priority 101 #used in election, 101 for master & 100 for backup
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.116.50/24
}
}
Start and enable keepalived service.
[root@webserver-01 keepalived]# systemctl start keepalived ; systemctl enable
keepalived
ln -s '/usr/lib/systemd/system/keepalived.service' '/etc/systemd/system/multi-
user.target.wants/keepalived.service'
Check IP Address of the server.
[root@webserver-01 keepalived]# ip addr | grep "inet" | grep "eno16777728"
inet 192.168.116.31/24 brd 192.168.116.255 scope global eno16777728
inet 192.168.116.50/24 scope global secondary eno16777728
[root@webserver-01 keepalived]#
You might observe that the Floating IP: 192.168.116.50 has been assigned to the network
interface.
Dependencies Resolved
==============================================================================
==
Package Arch Version Repository
Size
==============================================================================
==
Installing:
keepalived x86_64 1.2.10-2.el7 localyum 218
k
Installing for dependencies:
net-snmp-agent-libs x86_64 1:5.7.2-18.el7 localyum 698
k
net-snmp-libs x86_64 1:5.7.2-18.el7 localyum 745
k
Transaction Summary
==============================================================================
==
Install 1 Package (+2 Dependent packages)
Installed:
keepalived.x86_64 0:1.2.10-2.el7
Dependency Installed:
net-snmp-agent-libs.x86_64 1:5.7.2-18.el7 net-snmp-libs.x86_64 1:5.7.2-
18.el7
Complete!
Set Linux Kernel parameters as follows to support Floating IP.
[root@webserver-02 ~]# echo "net.ipv4.ip_nonlocal_bind = 1" >>
/etc/sysctl.conf
[root@webserver-02 ~]# sysctl -p
net.ipv4.ip_nonlocal_bind = 1
Now configure keepalived settings.
[root@webserver-02 ~]# cd /etc/keepalived/
[root@webserver-02 keepalived]# mv keepalived.conf keepalived.conf.org
[root@webserver-02 keepalived]# vi keepalived.conf
Add following directives and save.
! Configuration File for keepalived
global_defs {
notification_email {
root@webserver-02.centlinux.com
}
notification_email_from root@webserver-02.centlinux.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP
interface eno16777728
virtual_router_id 51
priority 100 #used in election, 101 for master & 100 for backup
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.116.50/24
}
}
Start and enable keepalived service.
[root@webserver-02 keepalived]# systemctl start keepalived ; systemctl enable
keepalived
ln -s '/usr/lib/systemd/system/keepalived.service' '/etc/systemd/system/multi-
user.target.wants/keepalived.service'
Check IP Address of the server.
[root@webserver-02 keepalived]# ip addr | grep "inet" | grep "eno16777728"
inet 192.168.116.32/24 brd 192.168.116.255 scope global eno16777728
inet 192.168.116.50/24 scope global secondary eno16777728
[root@webserver-02 keepalived]#
You might observe that the Floating IP: 192.168.116.50 has been assigned to the network
interface.