This post provides an introduction to the tools and processes you use to create a Pacemaker cluster. It is intended for users who are interested in seeing what the cluster software looks like and how it is administered, without needing to configure a working cluster. This example requires a single node running CentOS/RHEL 7 and it requires a floating IP address that resides on the same network as the statically assigned IP address for that node.
By working through the procedure this post provides, you will learn how to use Pacemaker to set up a cluster, how to display cluster status, and how to configure a cluster service. This example creates an Apache HTTP server as a cluster resource and shows how the cluster responds when the resource fails.
Note: This procedure does not create a supported Red Hat cluster, which requires at least two nodes and the configuration of a fencing device. Once you are familiar with the basic cluster commands, you can learn how to configure a highly available service in a two node cluster.
Configuring Cluster Service using PaceMaker
1. Install pcs and start and enable the pcsd service.
# yum install pcs fence-agents-all
# systemctl start pcsd.service # systemctl enable pcsd
2. If you are running the firewalld daemon, enable the ports that are required by the Red Hat High Availability Add-On.
# firewall-cmd --permanent --add-service=high-availability # firewall-cmd --reload
3. Set a password for user hacluster on each node in the cluster and authenticate user hacluster for each node in the cluster on the node from which you will be running the pcs commands. This example is using only a single node, but this step is included here since it is a necessary step in configuring a supported Red Hat High Availability multi-node cluster.
# passwd hacluster
# pcs cluster auth z1.example.com
4. Create a cluster named my_cluster with one member and check the status of the cluster. This command creates and starts the cluster in one step.
# pcs cluster setup --start --name my_cluster z1.example.com
# pcs cluster status Cluster Status: Last updated: Wed Feb 3 22:47:46 2016 Last change: Wed Feb 3 22:47:42 2016 by hacluster via crmd on z1.example.com Stack: corosync Current DC: z1.example.com (version 1.1.13-10.el7-44eb2dd) - partition with quorumFencing in a Red Hat High Availability Cluster 1 node and 0 resources configured Online: [ z1.example.com ] PCSD Status: z1.example.com: Online
Disabling fencing (not recommended)
A Red Hat High Availability cluster requires that you configure fencing for the cluster. For this introduction, however, which is intended to show only how to use the basic Pacemaker commands, disable fencing by setting the stonith-enabled cluster option to false.
# pcs property set stonith-enabled=false
Configuring Web Browser
1. Configure a web browser on your system and create a web page to display a simple text message. If you are running the firewalld daemon, enable the ports that are required by httpd.
# yum install -y httpd wget
# firewall-cmd --permanent --add-service=http # firewall-cmd --reload
# cat <<-END > /var/www/html/index.html <html> <body>My Test Site - $(hostname)</body> </html> END
2. In order for the Apache resource agent to get the status of Apache, create the following addition to the existing configuration to enable the status server URL.
# cat <<-END > /etc/httpd/conf.d/status.conf <Location /server-status> SetHandler server-status Order deny,allow Deny from all Allow from 127.0.0.1 Allow from ::1 </Location> END
Create Floating IP and Apache resource
Create IPaddr2 and apache resources for the cluster to manage. The ‘IPaddr2’ resource is a floating IP address that must not be one already associated with a physical node. If the ‘IPaddr2’ resource’s NIC device is not specified, the floating IP must reside on the same network as the statically assigned IP address used by the node,
You can display a list of all available resource types with the “pcs resource list” command. You can use the “pcs resource describe resourcetype” command to display the parameters you can set for the specified resource type. For example, the following command displays the parameters you can set for a resource of type apache:
# pcs resource describe apache
In this example, the IP address resource and the apache resource are both configured as part of a group named apachegroup, which ensures that the resources are kept together to run on the same node when you are configuring a working multi-node cluster.
# pcs resource create ClusterIP ocf:heartbeat:IPaddr2 ip=192.168.122.120 cidr_netmask=32 op monitor interval=30s --group apachegroup
# pcs resource create WebSite ocf:heartbeat:apache configfile=/etc/httpd/conf/httpd.conf statusurl="http://localhost/server-status" op monitor interval=1min --group apachegroup
# pcs status Cluster name: my_cluster Last updated: Fri Feb 5 17:23:39 2016 Last change: Fri Feb 5 17:22:51 2016 by hacluster via crmd on z1.example.com Stack: corosync Current DC: z1.example.com (version 1.1.13-10.el7-44eb2dd) - partition with quorum 1 node and 2 resources configured Online: [ z1.example.com ] Full list of resources: Resource Group: apachegroup ClusterIP (ocf::heartbeat:IPaddr2): Started z1.example.com WebSite (ocf::heartbeat:apache): Started z1.example.com PCSD Status: z1.example.com: Online ...
After you have configured a cluster resource, you can use the pcs resource show command to display the options that are configured for that resource.
# pcs resource show WebSite Resource: WebSite (class=ocf provider=heartbeat type=apache) Attributes: configfile=/etc/httpd/conf/httpd.conf statusurl=http://localhost/server-status Operations: start interval=0s timeout=40s (WebSite-start-interval-0s) stop interval=0s timeout=60s (WebSite-stop-interval-0s) monitor interval=1min (WebSite-monitor-interval-1min)
Point your browser to the website you created using the floating IP address you configured. This should display the text message you defined.
Testing resource failure
1. Stop the apache web service and check the cluster status. Using “killall -9” simulates an application-level crash.
# killall -9 httpd
2. Check the cluster status. You should see that stopping the web service caused a failed action, but that the cluster software restarted the service and you should still be able to access the website.
# pcs status Cluster name: my_cluster ... Current DC: z1.example.com (version 1.1.13-10.el7-44eb2dd) - partition with quorum 1 node and 2 resources configured Online: [ virt-333.cluster-qe.lab.eng.brq.redhat.com ] Full list of resources: Resource Group: apachegroup ClusterIP (ocf::heartbeat:IPaddr2): Started z1.example.com WebSite (ocf::heartbeat:apache): Started z1.example.com Failed Actions: * WebSite_monitor_60000 on z1.example.com 'not running' (7): call=13, status=complete, exitreason='none', last-rc-change='Thu Feb 4 23:45:50 2016', queued=0ms, exec=0ms PCSD Status: z1.example.com: Online
Clear the resource failure
1. You can clear the failure status on the resource that failed once the service is up and running again and the failed action notice will not longer appear when you view the cluster status.
# pcs resource cleanup WebSite
2. When you are finished looking at the cluster and the cluster status, stop the cluster services on the node. Even though you have only started services on one node for this introduction, the –all parameter is included since it would stop cluster services on all nodes on an actual multinode cluster.
# pcs cluster stop --all