Setting Up KVM High Availability with Fedora and Pacemaker

KVM High Availability with Fedora and Pacemaker

Learn how to set up KVM high availability with Fedora and Pacemaker to ensure seamless failover and minimal downtime for your virtual machines. Step-by-step guide with CLI examples.

Table of Contents

🔈Introduction

In today’s fast-paced digital world, downtime is a luxury that businesses cannot afford. For mission-critical systems, high availability (HA) setups ensure that applications and virtual machines continue running smoothly, even if hardware failures occur. One effective way to achieve high availability is by leveraging KVM (Kernel-based Virtual Machine) and Pacemaker, two powerful tools in the Linux ecosystem.

In this guide, we’ll show you how to set up a high availability cluster for KVM virtual machines (VMs) using Fedora and Pacemaker. Along the way, we’ll cover the essential concepts, provide detailed CLI examples, and walk you through the configuration steps. By the end, you’ll have a resilient KVM-based infrastructure capable of providing continuous uptime for your virtualized workloads.


Introduction to High Availability

High availability (HA) refers to the design and implementation of systems that are resilient to hardware or software failures. In virtualized environments, HA is critical to ensure that virtual machines remain up and running in case of node failures, network issues, or other unforeseen problems.

KVM provides the virtualization layer, while Pacemaker is a cluster resource manager (CRM) that ensures the availability of resources like virtual machines (VMs). Pacemaker, when paired with the Corosync cluster engine, enables the automatic failover of resources to another node in the cluster, thus minimizing downtime.


🧠 Understanding KVM and Pacemaker

KVM (Kernel-based Virtual Machine)

KVM is a full virtualization solution for Linux that uses the hardware-assisted virtualization extensions of modern processors. It allows you to run multiple virtual machines (VMs) on a single physical machine. KVM is widely used in enterprise environments and is supported on many Linux distributions, including Fedora.

Pacemaker

Pacemaker is an open-source cluster resource manager that enables high availability by managing resources and services within a cluster. It monitors the state of the resources and ensures that they are running on the most suitable node. If a failure occurs on one node, Pacemaker can automatically migrate resources to a healthy node.

Benefits of Combining KVM and Pacemaker

  • Automated Failover: Pacemaker ensures VMs running on KVM hosts are moved to healthy nodes automatically.
  • Minimal Downtime: With proper configuration, the failover process can be seamless and fast.
  • Scalability: You can expand your infrastructure as your business grows by adding more nodes to the cluster.
KVM High Availability with Fedora and Pacemaker

Photo by admingeek from Infotechys


✅ Prerequisites for Setting Up KVM HA with Fedora

Before starting, ensure you have the following in place:

Hardware Requirements

  • At least two Fedora-based physical servers (nodes) with virtualization support (Intel VT-x or AMD-V).
  • Shared storage, such as NFS or iSCSI, to store VM images and configuration files.
  • A reliable network connection between the nodes.

Software Requirements

  • Fedora 36 (or later) on both nodes.
  • KVM and libvirt installed on both nodes.
  • Pacemaker, Corosync, and crmsh for cluster management.

Basic Knowledge

  • Familiarity with Linux command-line operations.
  • Understanding of KVM and virtualization concepts.
  • Basic knowledge of clustering and high availability.

Installing and Configuring Pacemaker on Fedora

Step 1: Install KVM and Related Packages

First, install KVM and associated tools on both nodes. On each node, run the following commands:

				
					sudo dnf install @virtualization
				
			
				
					sudo dnf install libvirt virt-install qemu-kvm
				
			
				
					sudo systemctl enable --now libvirtd
				
			

Check that KVM is working by running:

				
					sudo systemctl is-active libvirtd
				
			

Step 2: Install Pacemaker and Corosync

Now, let’s install Pacemaker and Corosync, which are the core components for managing high availability clusters. On both nodes, run:

				
					sudo dnf install pacemaker corosync crmsh
				
			

Enable and start Corosync and Pacemaker services:

				
					sudo systemctl enable --now corosync
				
			
				
					sudo systemctl enable --now pacemaker
				
			

Step 3: Verify Installation

To ensure the services are running correctly:

				
					sudo systemctl status corosync pacemaker
				
			

You should see that both services are active and running.


Configuring KVM for High Availability

Step 1: Configure Shared Storage

For high availability to work, the VM storage must be accessible from both nodes. We’ll use NFS as the shared storage solution. On the primary node, install NFS:

				
					sudo dnf install nfs-utils
				
			

Create a shared directory to store your VMs:

				
					sudo mkdir /srv/nfs/kvm
				
			

Export this directory by adding the following to /etc/exports:

				
					/srv/nfs/kvm *(rw,sync,no_root_squash)
				
			

Start and enable the NFS server:

				
					sudo systemctl enable --now nfs-server && sudo exportfs -ra
				
			

On the secondary node, mount the shared directory:

				
					sudo mount -t nfs <primary-node-ip>:/srv/nfs/kvm /srv/nfs/kvm
				
			

Step 2: Configure KVM Resources in Pacemaker

Now we will create a resource definition for the KVM virtual machines using Pacemaker. Define the virtual machine resource in Pacemaker. Use the crm tool to manage Pacemaker resources:

				
					sudo crm configure primitive my-vm ocf:heartbeat:VirtualDomain \
  params config="/srv/nfs/kvm/my-vm.xml" \
  op monitor interval="30s"
				
			

Configure Pacemaker to manage the virtual machine:

				
					sudo crm configure colocation vm-with-node inf: my-vm master
				
			
				
					sudo crm configure order vm-start-after-node start: my-vm master
				
			

Step 3: Enable HA for VM

To enable automatic failover of the virtual machine, we will set the following constraints in Pacemaker:

				
					sudo crm configure property stonith-enabled=false
				
			
				
					sudo crm configure property no-quorum-policy=ignore
				
			

🛑 STONITH (Shoot the Other Node in the Head) is disabled here because we are focusing on KVM high availability rather than node fencing. You can enable STONITH for a more robust setup later.


đŸ§ȘTesting Your KVM HA Setup

Once you have configured your Pacemaker cluster with KVM, it’s time to test the failover functionality. Start the VM on the primary node:

				
					sudo virsh start my-vm
				
			

Simulate a failure by stopping the libvirt service on the primary node:

				
					sudo systemctl stop libvirtd
				
			

Check if Pacemaker moves the VM to the secondary node:

				
					sudo crm status
				
			

The output should indicate that the VM is now running on the secondary node.


đŸ§©Troubleshooting and Monitoring KVM High Availability

Common Issues and Fixes

  • VM not starting on failover: Ensure that shared storage is mounted on both nodes and the VM configuration is correctly specified.
  • Pacemaker is not starting the VM: Check the log files in /var/log/pacemaker.log and /var/log/messages for error messages.

Monitoring

Use crm to monitor the status of your cluster:

				
					sudo crm status
				
			

You can also use the pcs tool for additional monitoring:

				
					sudo pcs status
				
			

🏁 Conclusion

By combining KVM and Pacemaker on Fedora, you can create a robust high-availability environment for your virtual machines. This setup ensures that in case of a failure on one node, your VMs will automatically fail over to another node with minimal downtime. Whether you’re running production workloads or managing critical applications, high availability is crucial to ensuring business continuity.

Did you find this article helpful? Your feedback is invaluable to us! Feel free to share this post with those who may benefit, and let us know your thoughts in the comments section below.


Related Posts
Install KVM on Fedora 41
Commands
Install KVM on Fedora 41

Learn how to install KVM on Fedora 41 step-by-step—covering prerequisites, CLI & GUI configuration, networking, performance tuning, and best practices for virtualized environments. Table of

Read More »
RHEL9 on KVM
Commands
Install RHEL9 on KVM

In this tutorial, we’ll guide you through the step-by-step installation of RHEL9 on KVM. The process is uncomplicated, and we’ll present it in a format

Read More »

Leave a Reply

Your email address will not be published. Required fields are marked *