High availability is crucial for critical systems that should remain accessible even in the face of hardware or software failures. Pacemaker and Corosync are open-source tools that allow you to create a high-availability cluster on your Ubuntu servers. In this tutorial, I will guide you through the process of setting up a high-availability cluster using Pacemaker and Corosync on Ubuntu, ensuring that your services remain available with minimal downtime.
Section 1: Understanding High Availability Clustering
Before diving into the configuration, let’s briefly understand what high availability clustering is:
High availability clustering involves grouping multiple servers (nodes) together to provide redundancy for critical services. If one node fails, another takes over seamlessly, ensuring continuous service availability.
Section 2: Setting Up Pacemaker and Corosync
Step 1: Install Pacemaker and Corosync On each node, install the Pacemaker and Corosync packages:
sudo apt update
sudo apt install pacemaker corosync
Step 2: Configure Corosync Edit the Corosync configuration file on each node:
sudo nano /etc/corosync/corosync.conf
Here’s a basic configuration example for a two-node cluster:
totem {
version: 2
secauth: off
cluster_name: my_cluster
transport: udpu
}
nodelist {
node {
ring0_addr: node1_IP
nodeid: 1
}
node {
ring0_addr: node2_IP
nodeid: 2
}
}
quorum {
provider: corosync_votequorum
}
Replace node1_IP
and node2_IP
with the actual IP addresses of your nodes.
Step 3: Start Corosync Start the Corosync service on each node:
sudo systemctl start corosync
Step 4: Enable Corosync at Boot Ensure Corosync starts automatically at boot:
sudo systemctl enable corosync
Section 3: Configuring Pacemaker
Step 5: Start Pacemaker Start the Pacemaker service on each node:
sudo systemctl start pacemaker
Step 6: Enable Pacemaker at Boot Enable Pacemaker to start automatically at boot:
sudo systemctl enable pacemaker
Section 4: Creating a Resource
Step 7: Create a Resource Agent Pacemaker manages resources using resource agents. To create a simple resource agent for a virtual IP (VIP) address, create a file like vip.sh
:
sudo nano /usr/local/bin/vip.sh
Add the following content and make the script executable:
#!/bin/bash
/sbin/ifconfig eth0:0 $1 netmask 255.255.255.0 up
sudo chmod +x /usr/local/bin/vip.sh
Step 8: Create a Resource Now, create a Pacemaker resource for the VIP. On one of the nodes, run:
sudo crm configure primitive vip ocf:heartbeat:IPaddr2 params ip="VIP_IP" nic="eth0" cidr_netmask="24" op monitor interval="10s"
Replace VIP_IP
with the virtual IP address you want to use.
Step 9: Create a Resource Group Create a resource group that includes the VIP resource:
sudo crm configure group vip_group vip
Section 5: Testing Failover
Step 10: Simulate Node Failure To test the cluster, simulate a node failure by stopping the Corosync service on one of the nodes:
sudo systemctl stop corosync
Check the status of the cluster on the remaining node:
sudo crm status
You should see that the VIP has moved to the surviving node.
Section 6: Additional Configuration
To configure more resources, fencing, or complex constraints, refer to the Pacemaker documentation and tutorials. Pacemaker and Corosync offer a wide range of features for building highly available systems.
WooHoo! You’ve successfully set up a high-availability cluster on Ubuntu using Pacemaker and Corosync. Your services are now resilient to node failures, providing uninterrupted availability for critical applications.
I hope you have found this article useful. If so, please consider following me here and on social media. Also, if you need 24 x 7 linux help, check out my company: https://techguys2go.com
Cheers!