Wednesday, December 4, 2024

Guide for High-Availability Cluster Using Pacemaker and Corosync

Share

Creating a high-availability cluster is crucial to ensure continuous uptime for your critical services. In this tutorial, we’ll guide you through setting up a high-availability cluster using Pacemaker and Corosync. Pacemaker is an advanced, scalable High-Availability cluster resource manager while Corosync provides the messaging layer, which allows cluster nodes to communicate.

Pacemaker and CoroSync Configuration

Prerequisites

  1. Two or more servers with a Linux-based OS installed (we’ll use Ubuntu 20.04 for our examples)
  2. User with sudo privileges
  3. Familiarity with the Linux command line interface

Step 1: Installing Necessary Packages

On each server, start by updating the system and installing necessary software packages.

$ sudo apt update
$ sudo apt upgrade
$ sudo apt install pacemaker corosync

Step 2: Configuring Corosync

The first major step is configuring Corosync. Edit the Corosync configuration file found at /etc/corosync/corosync.conf.

$ sudo nano /etc/corosync/corosync.conf

Enter the following configuration. Replace the bindnetaddr field with your server’s network interface address.

totem {
    version: 2
    secauth: off
    cluster_name: cluster_name
    transport: udpu
    interface {
        ringnumber: 0
        bindnetaddr: 192.168.1.1
        mcastport: 5405
    }
}

nodelist {
    node {
        ring0_addr: 192.168.1.1
        nodeid: 1
    }

    node {
        ring0_addr: 192.168.1.2
        nodeid: 2
    }
}

quorum {
    provider: corosync_votequorum
    two_node: 1
}

Step 3: Configuring Pacemaker

In this step, we’ll configure Pacemaker on both servers. We’ll also ensure that both Pacemaker and Corosync start on boot.

$ sudo systemctl enable pacemaker
$ sudo systemctl enable corosync

Now, restart both services to apply the changes.

$ sudo systemctl restart corosync
$ sudo systemctl restart pacemaker

To check the status of the cluster, use the crm_mon command. It should show both nodes online.

$ crm_mon

Step 4: Adding Resources to the Cluster

In this step, we’ll add a service (resource) to the cluster. For demonstration purposes, we’ll add a basic IP address.

$ sudo crm configure primitive ClusterIP ocf:heartbeat:IPaddr2 params ip="192.168.1.100" cidr_netmask="32" op monitor interval="30s"

Check the status of your cluster using crm_mon. You should now see the IP address resource in your cluster.

Step 5: Setting Up Resource Groups

If you have more than one resource, it’s a good idea to group them together. This ensures that all resources in a group are located on the same node. To create a resource group:

$ sudo crm configure group WebServerGroup ClusterIP

This group can now be managed as a single entity.

This guide provided the basics for setting up a high-availability cluster with Pacemaker and Corosync. There are many more resources and options to explore in the Pacemaker and Corosync documentation.

Related Articles

Read more

Local News

Eine häufig gestellte frage ist, ob hunde nudeln essen dürfen. Tue.