KeepAlived IP Failover on CentOS & Red Hat

KeepAlived IP Failover
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
Keepalived use highly available to make Virtual IP call VIP . it's a linux implementation make of VRRP
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 keepalived
global_defs {
   notification_email {
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   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
    }
}
On Node 2
! Configuration File for keepalived
global_defs {
   notification_email {
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   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
    }
}
*Note
priority: The hight is master, nguoc lai la Backup.
virtual_router_id : the same bettween node 1 vs node 2
If you used Unicast, notify and track script then full script as bellow
! Configuration File for keepalived
global_defs {
   notification_email {
     [email protected]
     [email protected]
   }
   notification_email_from [email protected]
   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
}
The bash script keepalivecheck_haproxy.sh
cat /opt/scripts/keepalivecheck_haproxy.sh
As the output below
#!/bin/bash
# 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
The bash script keepalivekeepalived.state.sh
cat /opt/scripts/keepalivekeepalived.state.sh
As the output below
#!/bin/bash
TYPE=$1
NAME=$2
STATE=$3
echo $STATE > /var/run/keepalived.state

Starting keepalived services
service keepalived start
chkconfig keepalived on
To verify keepalived
ip addr show eth1
tailf /var/messages


Comments

Popular posts from this blog

zimbra some services are not running [Solve problem]

Bash script list all IP addresses connected to Server

How to install php7 on centos 6