KeepAlived IP Failover on CentOS & Red Hat
Introduction
Learn how to set up Keepalived for IP failover on CentOS and Red Hat. This step-by-step guide ensures high availability and network redundancy, keeping your critical services online during hardware or network failures.
In the world of high availability and network redundancy, ensuring that your critical services remain operational despite hardware or network failures is paramount. Keepalived is a robust and versatile tool designed to provide IP failover solutions on Linux servers, particularly on CentOS and Red Hat distributions. This guide delves into the configuration and deployment of Keepalived for IP failover, ensuring that your services continue to run smoothly even in the face of unexpected downtimes. Whether you're an IT professional aiming to bolster your infrastructure or a systems administrator looking to implement a reliable failover mechanism, this tutorial offers step-by-step instructions to help you achieve high availability with Keepalived.
my post, use keepAlived IP Failover on CentOS & Red Hat. I'm running commands as root account.
Links to below you maybe likes:
- How to install php7 on centos 6
- How to install and configure redmine on centos 6
- How to owncloud 9 install ssl certificate centos 7
- How To Install the BIND DNS Server on CentOS 6
- KeepAlived IP Failover on CentOS & Red Hat
To install keepalived on centos
yum update -y
yum install -y keepalived
To configure keepalived
On Node 1! Configuration File for keepalivedOn Node 2
global_defs {
notification_email {
sysadmin@mydomain.com
support@mydomain.com
}
notification_email_from node1@mydomain.com
smtp_server localhost
smtp_connect_timeout 30
}
vrrp_instance VI_1 {
state MASTER
interface eth1
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass You-Add-Password-Here
}
virtual_ipaddress {
192.168.10.121
}
}
! Configuration File for keepalivedNote
global_defs {
notification_email {
sysadmin@mydomain.com
support@mydomain.com
}
notification_email_from node2@mydomain.com
smtp_server localhost
smtp_connect_timeout 30
}
vrrp_instance VI_1 {
state MASTER
interface eth1
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass You-Add-Password-Here
}
virtual_ipaddress {
192.168.10.121 dev eth0
}
}
- priority: The hight is master, nguoc lai la Backup.
- virtual_router_id : the same bettween node 1 vs node 2
! Configuration File for keepalivedThe bash script keepalivecheck_haproxy.sh
global_defs {
notification_email {
sysadmin@mydomain.com
support@mydomain.com
}
notification_email_from lb1@mydomain.com
smtp_server localhost
smtp_connect_timeout 30
}
vrrp_instance VI_1 {
state MASTER
interface eth1
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass You-Add-Password-Here
}
unicast_src_ip 192.168.10.122 # Unicast specific option, this is the IP of the interface keepalived listens on
unicast_peer { # Unicast specific option, this is the IP of the peer instance
192.168.10.123
}
virtual_ipaddress {
192.168.10.121 dev eth0
}
vrrp_script check_haproxy {
script "/opt/scripts/keepalivecheck_haproxy.sh"
interval 2
fall 2
rise 2
}
track_script {
check_haproxy
}
notify /opt/scripts/keepalivekeepalived.state.sh
}
cat /opt/scripts/keepalivecheck_haproxy.shAs the output below
#!/bin/bashThe bash script keepalivekeepalived.state.sh
# Check if haproxy is running, return 1 if not.
# Used by keepalived to initiate a failover in case haproxy is down
HAPROXY_STATUS=$(/bin/ps -e | grep -w haproxy)
if [ "$HAPROXY_STATUS" != "" ]
then
exit 0
else
logger "HAProxy is NOT running. Setting keepalived state to FAULT."
exit 1
fi
cat /opt/scripts/keepalivekeepalived.state.shAs the output below
#!/bin/bash
TYPE=$1
NAME=$2
STATE=$3
echo $STATE > /var/run/keepalived.state
Starting keepalived services
service keepalived startTo verify keepalived
chkconfig keepalived on
ip addr show eth1
tailf /var/messages
Conclusion
Implementing IP failover using Keepalived on CentOS or Red Hat not only enhances the resilience of your network but also ensures continuous service availability even in the event of failures. By following the steps outlined in this guide, you can create a highly available system that automatically manages failovers with minimal manual intervention. Keepalived, with its simplicity and effectiveness, stands out as an essential tool in the arsenal of any Linux systems administrator tasked with maintaining service uptime. Thank you for reading the huuphan.com page!
Comments
Post a Comment