Pacemaker is an open-source, high-availability resource manager that ensures the reliability and availability of your critical services in a Linux cluster environment. This blog post will guide you through the process of how to install and configure Pacemaker on Rocky Linux, a popular Linux distribution ideal for server environments.
Prerequisites
Before we begin, make sure you have the following:
- A system running Rocky Linux
- Root or sudo access
How to Install and Configure Pacemaker on Rocky Linux
Update System Packages
First, update your system packages to the latest versions:
sudo dnf update -y
Enable the necessary repositories: If the packages are not available in the default repositories, you might need to enable the necessary repositories for Rocky Linux. Run the following commands:
sudo dnf install -y epel-release
sudo dnf config-manager --set-enabled powertools
Installing Pacemaker on Rocky Linux
Install the Pacemaker, Corosync, and pcs packages:
sudo dnf install -y pacemaker pcs corosync
Enable and Start Services on Rocky Linux
Enable and start the Corosync and Pacemaker services:
sudo systemctl enable --now corosync
sudo systemctl enable --now pacemaker
Configure Firewall Rules
Add the necessary firewall rules to allow cluster communication:
sudo firewall-cmd --permanent --add-service=high-availability
sudo firewall-cmd --reload
Set Up Cluster Authentication on Rocky Linux
Set up cluster authentication by creating a password for the hacluster
user:
sudo passwd hacluster
Configure Corosync on Rocky Linux
To configure Corosync, first create a cluster configuration file:
sudo nano /etc/corosync/corosync.conf
Add the following contents, replacing the {node_name}
and {node_ip}
placeholders with your node’s hostname and IP address:
totem {
version: 2
cluster_name: my_cluster
transport: udpu
}
nodelist {
node {
ring0_addr: {node_ip}
nodeid: 1
name: {node_name}
}
}
quorum {
provider: corosync_votequorum
two_node: 1
}
logging {
to_logfile: yes
logfile: /var/log/corosync/corosync.log
to_syslog: yes
}
Create and Configure Cluster on Rocky Linux
To create a cluster, run the following command:
sudo pcs cluster setup my_cluster {node_name} --start --enable --token 3000
Synchronize the Corosync configuration across the cluster:
sudo pcs cluster sync
Configure Cluster Resources on Rocky Linux
Now you can start configuring cluster resources. For example, to create an Apache web server resource, follow these steps:
- Install the Apache web server:
sudo dnf install -y httpd
- Create an Apache resource:
sudo pcs resource create Apache ocf:heartbeat:apache configfile=/etc/httpd/conf/httpd.conf op monitor interval=30s
For more advanced resource configuration, check out the official Pacemaker documentation.
Configure Resource Constraints
To set up resource constraints, such as colocation or ordering, use the pcs
command:
sudo pcs constraint colocation add {resource1} with {resource2} [score]
sudo pcs constraint order {resource1} then {resource2}
Replace {resource1}
and {resource2}
with your resource names, and [score]
with a numerical value representing the preference for the colocation.
Replace {resource1}
and {resource2}
with your resource names, and [score]
with a numerical value representing the preference for the colocation.
Configure Resource Stickiness
Resource stickiness ensures that a resource stays on the same node unless it fails. This can be helpful in minimizing the number of failovers and preventing unnecessary movement of resources. To configure resource stickiness, use the following command:
pcs resource defaults resource-stickiness=[stickiness_value]
Replace [stickiness_value]
with the desired numerical value for stickiness. A higher value indicates stronger preference for the resource to stay on the current node.
Configure Failure Timeout
Failure timeout specifies the time after which a failed resource will be attempted to start again. To configure the failure timeout for a resource, use the following command:
pcs resource op defaults timeout=[timeout_value]
Replace [timeout_value]
with the desired timeout value in seconds.
Verify the Cluster Configuration on Rocky Linux
After you have configured your Pacemaker cluster, it’s essential to verify the configuration. You can do this by running the following command:
pcs status
This command will display the current status of your cluster, including the resources and their states. Ensure that everything is running as expected.
Test the Cluster
Finally, to test the cluster, you can simulate a failure on one of the nodes. To do this, run the following command on the primary node:
pcs cluster standby [node_name]
Replace [node_name]
with the name of the node you want to put in standby mode. After running this command, you should see the resources migrate to the other node. You can then bring the node back online using the command:
pcs cluster unstandby [node_name]
This will bring the node back online, and depending on your configuration, the resources may migrate back to the primary node.
Conclusion
In this blog post, we have covered the installation and configuration of Pacemaker on Rocky Linux. You now have a solid understanding of the steps required to set up a high-availability cluster using Pacemaker. By following these steps, you can ensure that your critical services remain online even in the event of a failure.
For more information and tutorials on Rocky Linux, be sure to check out the following resources: