Accueil > Système > Simple failover cluster using UCARP on Ubuntu

Simple failover cluster using UCARP on Ubuntu

15/04/2024 Categories: Système Tags: , , ,
Print Friendly, PDF & Email

In this tutorial, I’ll show you the steps to create a simple failover cluster on Ubuntu using CARP. To make the things meaningful,we’ll create the cluster for Apache service but you can use it for any other service, which relay on IP.

Scenario:

Here is my Setup:

PrimarySrv: This is the main server, where I configured the apache and which act as Master (IP: 192.168.1.202)
SecondarySrv: 2nd Apache Server where I configured the apache exactly like on PrimarySrv (IP : 192.168.1.203)
192.168.1.250 : Virtual IP address,created using Ucarp.

Ucarp is really simple, it works like this,when the PrimarySrv is up,it will assign the virtual IP 192.168.1.250 to it, in case that PrimarySrv is down then it will assign virtual IP to the SeconadrySrv and when the PrimarySrv will come online, it will assign the virtual IP once again to it.

I assume that you configured Apache server already according to the above scenario, Let’s test it for PrimarySrv:

For SecondarySrv:

Login to the servers and install Ucarp:

sudo apt-get install ucarp

Edit the file /etc/network/interfaces on PrimarySrv:

sudo vi /etc/network/interfaces

Change it according to your scenario:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.202
netmask 255.255.255.0

  #######################
  # ucarp configuration
  #######################
  # vid : The ID of the virtual server [1-255]
  ucarp-vid 1
  # vip : The virtual address
  ucarp-vip 192.168.1.250
  # password : A password used to encrypt Carp communications
  ucarp-password secret
  # advskew : Advertisement skew [1-255]
  ucarp-advskew 1
  # advbase : Interval in seconds that advertisements will occur
  ucarp-advbase 1
  # master : determine if this server is the master
  ucarp-master yes

# The carp network interface, on top of eth0
iface eth0:ucarp inet static
        address 192.168.1.250
        netmask 255.255.255.0

Edit the file /etc/network/interfaces on SecondarySrv:

sudo vi /etc/network/interfaces

Change it according to your scenario:

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.1.203
netmask 255.255.255.0

 #########################
 # ucarp configuration
 #########################
 # vid : The ID of the virtual server [1-255]
 ucarp-vid 1
 # vip : The virtual address
 ucarp-vip 192.168.1.250
 # password : A password used to encrypt Carp communications
 ucarp-password secret
 # advskew : Advertisement skew [1-255]
 ucarp-advskew 100
 # advbase : Interval in seconds that advertisements will occur
 ucarp-advbase 1
 # master : determine if this server is the master
 ucarp-master no

# The carp network interface, on top of eth0
iface eth0:ucarp inet static
 address 192.168.1.250
 netmask 255.255.255.0

Restart the network service on both servers:

sudo /etc/init.d/networking restart

Check the IP configuration on both servers,you’ll see that the virtual IP(192.168.1.250) is assigned to the PrimarySrv:

ifconfig

At this moment, SecondarySrv don’t know about the virtual IP,we can verify it:

ifconfig

Now we access the apache web page in our web browser:

www.apache-cluser.local

Note: http://www.apache-cluster.local is equal to 192.168.1.250

Lire aussi:  4 outils utiles pour rechercher et supprimer des fichiers en double sous Linux

Shutdown the PrimarySrv server:

sudo poweroff

Now,Ucarp assign the virtual IP (192.168.1.250) to the SecondarySrv server, let’s verify it:

ifconfig

Access the apache web page in web browser once again:

www.apache-cluster.local

Once the PrimarySrv will be online, it will take the virtual IP back once again. For configuring the synchronization between the servers, please refer this tutorial.

 

Source: Lazy Geek -:)

Les commentaires sont fermés.