The cart is empty

In today's business environment, where service availability is critical, ensuring that key applications are always up and resistant to failures is paramount. One way to achieve this is by implementing an HA (High Availability) cluster. This article will focus in detail on setting up an HA cluster using Corosync and Pacemaker, which together offer a robust solution for cluster management in Linux environments.

What is an HA Cluster?

An HA cluster, or High Availability cluster, is a group of linked computer servers that aims to ensure high availability and resilience for critical applications and services. If one node in the cluster fails, the workload is automatically transferred to other available nodes, minimizing downtime.

Key Components

To build an HA cluster with Corosync and Pacemaker, we need:

  • Corosync: A cluster communication software, ensuring communication between the cluster nodes.
  • Pacemaker: A cluster resource manager that decides where and how resources will run based on defined rules.

Prerequisites

  • Two or more servers with Linux installed, each with a unique IP address and hostname.
  • Network configuration that allows communication between the servers.
  • Package management software installed (e.g., YUM or APT) for installing necessary packages.

Installing and Configuring Corosync

  1. Install Corosync and Pacemaker

    Install Corosync and Pacemaker on all cluster nodes using the package manager.

    sudo yum install corosync pacemaker pcs
    

    for CentOS/RHEL, or

    sudo apt-get install corosync pacemaker pcs
    

    for Debian/Ubuntu.

  2. Configure Authentication

    On one of the nodes, set up authentication between cluster nodes using the pcs tool. This allows us to manage the cluster from a single point.

    sudo pcs cluster auth node1 node2 -u hacluster -p password
    

    where node1 and node2 are your servers' hostnames, and password is the password for authentication.

  3. Create the Cluster

    After successful authentication, create the cluster using the pcs tool.

    sudo pcs cluster setup --name my_cluster node1 node2
    

    my_cluster is the name of your cluster.

  4. Start the Cluster

    Start Corosync and Pacemaker services on all nodes.

    sudo pcs cluster start --all
    

 

Configuring Pacemaker

  1. Create and Configure Resources

    Resources are services or applications managed by the cluster. Use the pcs tool to create and configure resources as needed. For example, for an Apache web server, you would use:

    sudo pcs resource create Apache ocf:heartbeat:apache configfile=/etc/httpd/conf/httpd.conf op monitor interval=30s
    
  2. Configure Failover Policies

    Next, set up policies for automatically moving resources between nodes in case of a failure. These policies are defined through constraints in Pacemaker.

    sudo pcs constraint colocation add Apache with WebVIP INFINITY
    sudo pcs constraint order WebVIP then Apache
    

Testing and Monitoring

After completing the configuration, it's important to test failover scenarios to ensure that resources automatically move to another available node without significant service interruption upon a node failure. Use pcs status and crm_mon for cluster status monitoring.

 

Implementing an HA cluster with Corosync and Pacemaker is an effective solution for ensuring high availability of critical applications. Proper configuration and testing are key to successful implementation and smooth operation.