The following is part 2 of a 4 part series that will go over an installation and configuration of Pacemaker, Corosync, Apache, DRBD and a VMware STONITH agent.
The convention followed in the series is that [ALL] # denotes a command that needs to be run on all cluster machines.
Configure Cluster Resources
The first resource that we are going to add is an IP address that the cluster can bring up on either node. This will be used as a VIP for Apache frontend.
Add a Virtual IP Resource
The name of the resource is my_VIP. The cluster is told to check whether the address is running every 10 seconds.
[pcmk01]# pcs resource create my_VIP ocf:heartbeat:IPaddr2 \ ip=10.247.50.213 cidr_netmask=32 op monitor interval=10s
To test the resource failover, we can put the active node into standby mode:
[pcmk01]# pcs status [pcmk01]# pcs cluster standby pcmk01-cr [pcmk01]# pcs status [pcmk01]# ssh pcmk02 ip ad show [pcmk01]# pcs cluster unstandby pcmk01-cr
The VIP should float from the first node to the second. We also want to prevent the resources from moving after recovery as it usually increases downtime:
[pcmk01]# pcs resource defaults resource-stickiness=100
If need be, after recovery, we can move the resource manually:
[pcmk01]# pcs resource move my_VIP pcmk01-cr [pcmk01]# pcs resource clear my_VIP
Note that when we execute the pcs resource move command, this adds constraints to the resource to prevent it from running on the indicated node. When we execute the pcs resource clear command, this removes the constraints. This does not necessarily move the resources back to the indicated node.
Add Apache as a Cluster Service
We need to have Apache installed first:
[ALL]# yum install -y httpd wget
Create a temp index document:
[ALL]# cat <<EOL >/var/www/html/index.html Apache test on $(hostname) EOL
Enable the Apache status URL:
[ALL]# 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 </Location> END
Add Apache to the cluster:
[pcmk01]# pcs resource create my_website ocf:heartbeat:apache \ configfile=/etc/httpd/conf/httpd.conf \ statusurl="http://localhost/server-status" \ op monitor interval=10s
The name of the Apache resource is my_website. The cluster is told to check whether the Apache is running every 10 seconds.
Create a Resource Group
One of the most common elements of a cluster is a set of resources that need to be located together, start sequentially, and stop in the reverse order. To simplify this configuration, Pacemaker supports the concept of groups.
If we don’t use a resource group, then we have to ensure that resources run on the same host.
There is no limit to the number of resources a group can contain. The fundamental properties of a group are as follows.
- Resources are started in the order in which we specify them (in our example, my_VIP first, then my_website),
- Resources are stopped in the reverse order in which we specify them. (my_website first, then my_VIP).
Let us check the resources that we’ve configured so far:
[pcmk01]# pcs resource show my_VIP (ocf::heartbeat:IPaddr2): Started pcmk01-cr my_website (ocf::heartbeat:apache): Started pcmk02-cr
Create a resource group called my_webresource and specify that the VIP resource should be started before the Apache:
[pcmk01]# pcs resource group add my_webresource my_VIP my_website
[pcmk01]# pcs resource show Resource Group: my_webresource my_VIP (ocf::heartbeat:IPaddr2): Started pcmk01-cr my_website (ocf::heartbeat:apache): Started pcmk01-cr
[pcmk01]# pcs resource group list my_webresource: my_VIP my_website
We now have an Apache cluster service which is accessible via 10.247.50.213 (pcmk-vip).
I am currently writing my own OCF resource agent however i am facing the following error.
Error: Agent ‘ocf:heartbeat:syslogng’ is not installed or does not provide valid metadata: Metadata query for ocf:heartbeat:syslogng failed: Input/output error, use –force to override
I created my RA in /usr/lib/ocf/resource.d/heartbeat. The command i executed.
“pcs resource create my_syslogng ocf:heartbeat:syslogng configfile=/opt/syslog-ng/var/run/syslog-ng.ctl”
Think you can give me some advice? I will attached my code when you reply back to me. Thanks.
I suspect there is something wrong with