-
Notifications
You must be signed in to change notification settings - Fork 2
Keepalived Cluster Setup
We are going to set up very simple keepalived IP failover on Centos 7. The keepalived daemon can be used to monitor services or systems and to automatically failover to standby if problems occur. Keepalived can do more, like load balancing and monitoring, but in this tutorial focusses on very simple setup, just IP failover based on httpd failover.
While keepalived is often used to monitor and failover load balancers, in order to reduce our operational complexity, we will be using Apache as a simple web server in this guide. Start off by updating the local package index on each of your servers. We can then install Apache:
]#yum -y install httpd
To check which of the two servers is serving our requests, for this we will create two different index.html pages for each host.
Server1
]#echo "<h1>Primary</h1>" > index.html
Server2
]#echo "<h1>Secondary</h1>" > index.html
Install and Configure keepalived
]#yum -y install gcc kernel-headers kernel-devel
]#yum -y install keepalived
Create the config file on the first server1
]#vi /etc/keepalived/keepalived.conf
global_defs {
notification_email {
devops@localhost.com
}
notification_email_from test@localhost.com
smtp_server locahost
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_httpd {
script "killall -0 httpd"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER
# The interface keepalived will manage
interface eno16777736
# The virtual router id number to assign the routers to
virtual_router_id 51
# The priority to assign to this device. This controls
# who will become the MASTER and BACKUP for a given
# VRRP instance (a lower number get's less priority)
priority 200
advert_int 1
authentication {
auth_type PASS
auth_pass payoda@123
}
track_script {
chk_httpd
}
# The virtual IP addresses to float between nodes.
virtual_ipaddress {
10.0.0.215/24 dev eno16777736
}
}
Create the config file on the server2
]#vi /etc/keepalived/keepalived.conf
global_defs {
notification_email {
devops@localhost.com
}
notification_email_from test@localhost.com
smtp_server locahost
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_httpd {
script "killall -0 httpd"
interval 2
weight 2
}
vrrp_instance VI_1 {
state BACKUP
# The interface keepalived will manage
interface eno16777736
# The virtual router id number to assign the routers to
virtual_router_id 51
# The priority to assign to this device. This controls
# who will become the MASTER and BACKUP for a given
# VRRP instance (a lower number get's less priority)
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass test@123
}
track_script {
chk_httpd
}
# The virtual IP addresses to float between nodes.
virtual_ipaddress {
10.0.0.215/24 dev eno16777736
}
}
NOTE: *eno16777736 --> interface name *10.0.0.215 --> my floating IP
Restart keepalived
]#systemctl restart keepalived
list out IPs inserver1
]#ip addr
Also if you hit 10.0.0.215 in the browser and you will be able to see the index.html of the srever1 is serving.
Let's do a test failover. On server 1
]#service httpd stop
Now run command in server2
]#ip addr
you will able see the floating IP in second VM.
or you can hit 10.0.0.215 in the browser and you will be able to see the index.html of the srever2 is serving(Secondary).