Install Keepalived on CentOS 8

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Keepalived is a system daemon that monitors services or systems continuously and achieve high availability in the event of failure. If one node is down then the second node will serve the resources. Keepalived is used for IP failover between two servers. Its facilities for load balancing and high-availability to Linux-based infrastructures. It worked on VRRP (Virtual Router Redundancy Protocol) protocol.

Usually we install and configure Keepalived in two server with one IP usually known as VIP (Virtual IP).

We will show the installation and configuration of both servers one by one.

Prerequisites:

Install HA Proxy in order for Keepalived to work in fail-safe situation.

We will install prerequisite libraries before installing Keepalived.

yum -y install kernel-headers kernel-devel

Install Keepalived:

Install keepalived by entering following command in both machines:

yum -y install keepalived

Configuration of Master Server:

Open configuration file of keepalived in the MASTER Server.

nano /etc/keepalived/keepalived.conf

Add the following configuration:

! Configuration File for keepalived

global_defs {

}

vrrp_script haproxy {
  script "pgrep haproxy" # check the haproxy process
  interval 2 # every 2 seconds
  timeout 1 # add 2 points if OK
}


vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 101
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.7.40
    }
    track_script {
        haproxy
    }
   
}

Virtual IP will be allocation to interface ens33 will be as follows:

Configurations of Backup Server:

Open configuration file in backup server.

nano /etc/keepalived/keepalived.conf

Enter the following configuration in the backup server:

! Configuration File for keepalived

global_defs {

}

vrrp_script haproxy {
  script "killall -0 haproxy" # check the haproxy process
  interval 2 # every 2 seconds
  timeout 1 # add 2 points if OK
}

vrrp_instance VI_1 {
    state MASTER
    interface ens33
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.7.40 
    }
    track_script {
        haproxy
    }
    
}

Start and Enable Keepalived in both servers:

systemctl start keepalived.service
systemctl enable keepalived.service
systemctl status keepalived.service

As you can see above Virtual IP is allocated on ens33 is 192.168.7.40 and will listen to the traffic coming on this IP. Similarly as its Priority is 101 so its the master state.

Given Below is the status of backup machine .

Now if the master gets down then the backup server will become master as its priority will be higher and downtime will be minimum.

when the master gets up the backup machine will enter backup state automatically.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Mel
Melhttps://unixcop.com
Unix/Linux Guru and FOSS supporter

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook