Start a Project

Server Clustering with keepalived

In Production, All Servers need to be in the working state by 24*7, you have to achieve 0% downtime of the servers if you want smooth & stable working environment, As everyone knows that Technical problem may arise anytime in the server then how can we give the assurity of the availability of the server to the production and for that there is a name came in my mind called Clustering. In clustering you can make two or more servers, i would make two servers like:

1) Primary Server

2) Secondary (Replica of Primary) Server

Primary Server will be available 24*7 in the production & the another one will be like replica of primary server called Secondary Server. If primary goes down then no need to worry, you can have your time to troubleshoot it and to make it available again in the production while your secondary server is working like primary, in such scenario except you no one knows either your primary server is running or secondary (replica) server.

Now the question arises like how can we do clustering in the production between two servers:

Keepalived

Keepalived is a linux implementation of VRRP (Virtual Router Redundancy Protocol), through which we make IPs highly available which is called VIPs (Virtual IPs). Basically we can generate a virtual ip & can share it between two servers through VRRP, with the help of that we can make our Primary Server & the another one is Secondary (Replica) Server.

Basically VRRP protocol ensures that the one node is primary & the another one is secondary or you can use backup node. Backup node listens for multicast packet from the primary node with a high priority & if it gets failed to receive packets, the secondary node automatic takes the primary state & assign the configured IP to itself & when primary node comes up, it automatically takes initiative.

Now Lets implement it in the production.

Install Ubuntu Server on two nodes then install apache packages on both web server nodes by typing:-

Now install & setup keepalived by typing:-

For Primary server, edit the /etc/keepalived/keepalived.conf file

For Secondary Server, edit the /etc/keepalived/keepalived.conf file

Now we start keepalived:

As this node is configured as Secondary Server, It should not be listening on the virtual IP as long as Primary Server is in up state.
Now let’s check it on Primary Server with the command mentioned below:-

the output of this command will be like:-

Now let’s check it again on Secondary (Replica) Server with the same command mentioned below:-

the output of this command will be like:-

To test it out, shut down your primary server & check with those command.

Exit mobile version