Using Pacemaker
Introduction
Pacemaker is a high-availability cluster resource manager suitable for both small and large clusters. It can manage services and resources, ensuring they are running correctly and restarting them if they fail. This tutorial will guide you through the process of setting up and using Pacemaker on a Linux system.
Installation
To install Pacemaker, you need to install the necessary packages. The following commands show how to install Pacemaker on a Debian-based system:
sudo apt-get update
sudo apt-get install pacemaker corosync
For Red Hat-based systems, use the following commands:
sudo yum update
sudo yum install pacemaker corosync
Setting Up Corosync
Corosync is used for cluster communication. You need to configure it to work with Pacemaker. The configuration file is usually located at /etc/corosync/corosync.conf
. Below is an example configuration:
totem { version: 2 secauth: on cluster_name: my_cluster transport: udpu interface { ringnumber: 0 bindnetaddr: 192.168.1.0 mcastport: 5405 } } nodelist { node { ring0_addr: node1 nodeid: 1 } node { ring0_addr: node2 nodeid: 2 } } quorum { provider: corosync_votequorum two_node: 1 }
After configuring Corosync, start and enable the service:
sudo systemctl start corosync
sudo systemctl enable corosync
Starting Pacemaker
Once Corosync is configured and running, you can start Pacemaker:
sudo systemctl start pacemaker
sudo systemctl enable pacemaker
Check the status of Pacemaker to ensure it is running correctly:
sudo systemctl status pacemaker
Basic Pacemaker Commands
Here are some basic commands to interact with Pacemaker:
- crm status - View the current status of the cluster
- crm configure show - Display the current configuration
- crm configure edit - Edit the cluster configuration
Adding Resources
To add a resource to the cluster, use the crm configure
command. For example, to add an IP address resource:
crm configure primitive IPAddr1 ocf:heartbeat:IPaddr2 params ip=192.168.1.100 cidr_netmask=24 op monitor interval=30s
To verify the resource has been added:
crm status
Managing Resources
You can start, stop, and delete resources using the following commands:
- crm resource start
- Start a resource - crm resource stop
- Stop a resource - crm configure delete
- Delete a resource
Failover Testing
To test the failover capabilities of your cluster, you can simulate a node failure. For example, to simulate a failure on node1:
sudo systemctl stop pacemaker
Check the status of the cluster on another node to ensure the resources have failed over:
crm status
Conclusion
Pacemaker is a powerful tool for managing high-availability clusters. By following this tutorial, you should be able to install Pacemaker, configure Corosync, add and manage resources, and test failover scenarios. This foundational knowledge will help you ensure your services remain available and resilient to failures.