x386.org: Debian and Ubuntu Documentation

|  Home  |  About  |  Contact  |  License  |  Privacy Policy  |

Copyright (C) 2020 - 2024 Exforge exforge@x386.org

This document is free text: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.

This document is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see .


KeepalivedOnDebianUbuntu

keepalived Clustering on Debian and Ubuntu

0. Specs


If the first server goes off for any reason, then floating IP address will point to second server. It will return to the first server again when it goes back online.

This looks like clustering only at the network level.

All the necessary services on the first server must be installed on the second server too. (Web server, DB server, mail server etc)

The servers must be in the same network.

Based on the book Mastering Ubuntu Server 2nd Ed. by Jay LaCroix.

I tested the tutorial with Debian 11, Debian 12, Ubuntu 22.04 and Ubuntu 24.04 pairs.

You may establish a full cluster of LAMP stack by:

  1. Installing Apache on both servers
  2. Configuring the apache and sites equally on the both server
  3. Installing MariaDB on both server
  4. Establishing Master-Master Replication for Mariadb on 1st and 2nd servers


1. Install keepalived


Install on both the first and the second servers

sudo apt update
sudo apt -y install keepalived

After the installation, tries to start but cannot because there is no config.


2. First Server Config


2.1. Config

Config file location is /etc/keepalived directory, initially empty

Create primary server conf file

sudo nano /etc/keepalived/keepalived.conf

Fill as below:

global_defs {
    notification_email {
    notify@x11.xyz
    }
    notification_email_from keepalived@x11.xyz
    smtp_server 192.168.1.150
    smtp_connect_timeout 30
    router_id mycompany_web_prod
}
vrrp_instance VI_1 {
    smtp_alert
    interface enp0s3
    virtual_router_id 51
    priority 100
    advert_int 5
    virtual_ipaddress {
    192.168.1.240
    }
}

2.2. Explanations

3. Second Server Config


Almost the same as step 2. Just give a smaller number (say 90) for priority.

If you want to add more servers, give them numbers less then 90


4. Start keepalived


Run on both servers

sudo systemctl start keepalived

You can check the status of your cluster

systemctl status -l keepalived