High availability is a major buzzword in the IT industry and there are several reasons for this. As more and more business provide their services through the Internet, the need for these services to always be accessible has grown. Gone are the days when you would have to go to a physical storefront to purchase goods and services. Now, at any time of the day or night, you can purchase food, clothes, entertainment, or just about anything else you can think of and have it shipped to your front door or consumed on a media device. This is where high availability comes in. Ensuring that your services remain highly-available is key to succeeding in the modern marketplace. In this tutorial, we will walk through installing a Pacemaker cluster on two CentOS 7 servers and configuring it to ensure that our services remain highly-available.
Install a Pacemaker Cluster
Pacemaker is a high availability Cluster Resource Manager (CRM) that can be used to manage resources, and ensure that they remain available in the event of a node failure.
First, we need to install the Pacemaker package and the pcs command line tool. On both nodes, run:
sudo yum install -y pacemaker pcs
firewall-cmd commands on both nodes, and allow traffic for Pacemaker (TCP ports 2224, 3121, 21064, and UDP port 5405):
sudo firewall-cmd --permanent --add-service=high-availability sudo firewall-cmd --reload
Start and enable the pcsd service. Again, run these on both nodes:
sudo systemctl start pcsd.service sudo systemctl enable pcsd.service
Set the password for the
hacluster user, again on both nodes, that is created during the package installation. This user will be used to authenticate to the other cluster nodes and to perform actions on the cluster:
sudo passwd hacluster
node1, authenticate as the
sudo pcs cluster auth NODE1 NODE2
Generate and synchronize the corosync configuration on
sudo pcs cluster setup --name cluster_name NODE1 NODE2
Start up the cluster on
sudo pcs cluster start --all
Configure Cluster Resources
Now that the cluster is up and running, we can create our cluster resources. First, we will create an IP address resource followed by an Apache HTTP server resource. Once the resources are created, we can set resources constraints to ensure that the IP address always starts before the Apache HTTP server and that the two resources always run together on the same node.
Add an IP address resource to the cluster on
sudo pcs resource create cluster_ip ocf:heartbeat:IPaddr2 ip=192.168.1.100 cidr_netmask=24 op monitor interval=30s
Install the Apache HTTP server on both nodes, and open the HTTP ports in the firewall:
sudo yum install -y httpd sudo firewall-cmd --permanent --add-service=http sudo firewall-cmd --reload
On both nodes, enable a status URL for health monitoring:
sudo cat > /var/www/html/index.html <<EOF SetHandler server-status Require local EOF
Add the Apache HTTP server resource to the cluster on
sudo pcs resource create apache ocf:heartbeat:apache configfile=/etc/httpd/conf/httpd.conf statusurl="http://localhost/server-status" op monitor interval=1min
Set a colocation constraint on
node1, to ensure that the cluster resources run on the same node:
sudo pcs constraint colocation add apache with cluster_ip INFINITY
node1, set an order constraint to ensure that the cluster resources start in the correct order:
sudo pcs constraint order cluster_ip then apache
Verify the resource constraints on
sudo pcs constraint
Validate the status of the cluster resources on
sudo pcs status
Now we have successfully configured a failover cluster using Pacemaker! In the event of a node failure, the resources will automatically move to a working node in the cluster.
Want to Learn More?
If you enjoyed this brief tutorial and want to Learn more about Pacemaker, please check out my LPIC-3 304 Virtualization and High Availability prep course. This course covers Pacemaker, as well as several other technologies and services that support high availability and virtualization.