Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Using DRBD in Heartbeat R1-style clusters

Running Heartbeat clusters in release 1 compatible configuration is now considered obsolete by the Linux-HA development team. However, it is still widely used in the field, which is why it is documented here in this section. Advantages. Configuring Heartbeat in R1 compatible mode has some advantages over using CRM configuration. In particular, Heartbeat R1 compatible clusters are simple and easy to configure; it is fairly straightforward to extend Heartbeat's functionality with custom, R1-style resource agents.

Disadvantages. Disadvantages of R1 compatible configuration, as opposed to CRM configurations, include: Cluster configuration must be manually kept in sync between cluster nodes, it is not propagated automatically. While node monitoring is available, resource-level monitoring is not. Individual resources must be monitored by an external monitoring system. Resource group support is limited to two resource groups. CRM clusters, by contrast, support any number, and also come with a complex resource-level constraint framework.

Another disadvantage, namely the fact that R1 style configuration limits cluster size to 2 nodes (whereas CRM clusters support up to 255) is largely irrelevant for setups involving DRBD, DRBD itself being limited to two nodes.

Heartbeat R1-style configuration


In R1-style clusters, Heartbeat keeps its complete configuration in three simple configuration files: /etc/ha.d/ha.cf, as described in the section called The ha.cf file. /etc/ha.d/authkeys, as described in the section called The authkeys file. /etc/ha.d/haresources the resource configuration file, described below.

The haresources file


The following is an example of a Heartbeat R1-compatible resource configuration involving a MySQL database backed by DRBD: bob drbddisk::mysql Filesystem::/dev/drbd0::/var/lib/mysql::ext3 \ 10.9.42.1 mysql This resource configuration contains one resource group whose home node (the node where its resources are expected to run under normal circumstances) is named bob. Consequentially, this resource group would be considered the local resource group on host bob, whereas it would be the foreign resource group on its peer host. The resource group includes a DRBD resource named mysql, which will be promoted to the primary role by the cluster manager (specifically, the drbddisk resource agent) on

whichever node is currently the active node. Of course, a corresponding resource must exist and be configured in /etc/drbd.conf for this to work. That DRBD resource translates to the block device named /dev/drbd0, which contains an ext3 filesystem that is to be mounted at /var/lib/mysql (the default location for MySQL data files). The resource group also contains a service IP address, 10.9.42.1. Heartbeat will make sure that this IP address is configured and available on whichever node is currently active. Finally, Heartbeat will use the LSB resource agent named mysql in order to start the MySQL daemon, which will then find its data files at /var/lib/mysql and be able to listen on the service IP address, 192.168.42.1. It is important to understand that the resources listed in the haresources file are always evaluated from left to right when resources are being started, and from right to left when they are being stopped.

Stacked resources in Heartbeat R1-style configurations


Available in DRBD version 8.3.0 and above In three-way replication with stacked resources, it is usually desirable to have the stacked resource managed by Heartbeat just as other cluster resources. Then, your two-node cluster will manage the stacked resource as a floating resource that runs on whichever node is currently the active one in the cluster. The third node, which is set aside from the Heartbeat cluster, will have the other half of the stacked resource available permanently.

Note To have a stacked resource managed by Heartbeat, you must first configure it as outlined in the section called Configuring a stacked resource.
The stacked resource is managed by Heartbeat by way of the drbdupper resource agent. That resource agent is distributed, as all other Heartbeat R1 resource agents, in/etc/ha.d/resource.d. It is to stacked resources what the drbddisk resource agent is to conventional, unstacked resources. drbdupper takes care of managing both the lower-level resource and the stacked resource. Consider the following haresources example, which would replace the one given in the previous section: bob 192.168.42.1 \ drbdupper::mysql-U Filesystem::/dev/drbd1::/var/lib/mysql::ext3 \ mysql Note the following differences to the earlier example: You start the cluster IP address before all other resources. This is necessary because stacked resource replication uses a connection from the cluster IP address to the node IP address of the third node. Lower-level resource replication, by contrast, uses a connection between the physical node IP addresses of the two cluster nodes. You pass the stacked resource name to drbdupper (in this example, mysql-U). You configure the Filesystem resource agent to mount the DRBD device associated with the stacked resource (in this example, /dev/drbd1), not the lower-level one.

Managing Heartbeat R1-style clusters


Assuming control of cluster resources
A Heartbeat R1-style cluster node may assume control of cluster resources in the following way: Manual resource takeover. This is the approach normally taken if one simply wishes to test resource migration, or assume control of resources for any reason other than the peer having to leave the cluster. This operation is performed using the following command: /usr/lib/heartbeat/hb_takeover On some distributions and architectures, you may be required to enter: /usr/lib64/heartbeat/hb_takeover

Relinquishing cluster resources


A Heartbeat R1-style cluster node may be forced to give up its resources in several ways. Switching a cluster node to standby mode. This is the approach normally taken if one simply wishes to test resource migration, or perform some other activity that does not require the node to leave the cluster. This operation is performed using the following command: /usr/lib/heartbeat/hb_standby On some distributions and architectures, you may be required to enter: /usr/lib64/heartbeat/hb_standby Shutting down the local cluster manager instance. This approach is suited for local maintenance operations such as software updates which require that the node be temporarily removed from the cluster, but which do not necessitate a system reboot. It involves shutting down all processes associated with the local cluster manager instance: /etc/init.d/heartbeat stop Prior to stopping its services, Heartbeat will gracefully migrate any currently running resources to the peer node. This is the approach to be followed, for example, if you are upgrading DRBD to a new release, without also upgrading your kernel. Shutting down the local node. For hardware maintenance or other interventions that require a system shutdown or reboot, use a simple graceful shutdown command, such as reboot or poweroff Since Heartbeat services will be shut down gracefully in the process of a normal system shutdown, the previous paragraph applies to this situation, too. This is also the

approach you would use in case of a kernel upgrade (which also requires the installation of a matching DRBD version).

Using DRBD in Heartbeat CRM-enabled clusters


Running Heartbeat clusters in CRM configuration mode is the recommended approach as of Heartbeat release 2 (per the Linux-HA development team). Advantages. Advantages of using CRM configuration mode, as opposed to R1 compatible configuration, include: Cluster configuration is distributed cluster-wide and automatically, by the Cluster Resource Manager. It need not be propagated manually. CRM mode supports both node-level and resource-level monitoring, and configurable responses to both node and resource failure. It is still advisable to also monitor cluster resources using an external monitoring system. CRM clusters support any number of resource groups, as opposed to Heartbeat R1style clusters which only support two. CRM clusters support a powerful (if complex) constraints framework. This enables you to ensure correct resource startup and shutdown order, resource co-location (forcing resources to always run on the same physical node), and to set preferred nodes for particular resources.

Another advantage, namely the fact that CRM clusters support up to 255 nodes in a single cluster, is somewhat irrelevant for setups involving DRBD (DRBD itself being limited to two nodes). Disadvantages. Configuring Heartbeat in CRM mode also has some disadvantages in comparison to using R1-compatible configuration. In particular, Heartbeat CRM clusters are comparatively complex to configure and administer; Extending Heartbeat's functionality with custom OCF resource agents is non-trivial.

Note This disadvantage is somewhat mitigated by the fact that you do have the option of using custom (or legacy) R1-style resource agents in CRM clusters.

Heartbeat CRM configuration


In CRM clusters, Heartbeat keeps part of configuration in the following configuration files: /etc/ha.d/ha.cf, as described in the section called The ha.cf file. You must include the following line in this configuration file to enable CRM mode: crm yes /etc/ha.d/authkeys. The contents of this file are the same as for R1 style clusters. See the section called The authkeys file for details.

The remainder of the cluster configuration is maintained in the Cluster Information Base (CIB), covered in detail in the following section. Contrary to the two relevant configuration files, the CIB need not be manually distributed among cluster nodes; the Heartbeat services take care of that automatically.

The Cluster Information Base


The Cluster Information Base (CIB) is kept in one XML file, /var/lib/heartbeat/crm/cib.xml. It is, however, not recommended to edit the contents of this file directly, except in the case of creating a new cluster configuration from scratch. Instead, Heartbeat comes with both command-line applications and a GUI to modify the CIB. The CIB actually contains both the cluster configuration (which is persistent and is kept in the cib.xml file), and information about the current cluster status (which is volatile). Status information, too, may be queried either using Heartbeat command-line tools, and the Heartbeat GUI. After creating a new Heartbeat CRM cluster that is, creating the ha.cf and authkeys files, distributing them among cluster nodes, starting Heartbeat services, and waiting for nodes to establish intra-cluster communications a new, empty CIB is created automatically. Its contents will be similar to this: <cib> <configuration> <crm_config> <cluster_property_set id="cib-bootstrap-options"> <attributes/> </cluster_property_set> </crm_config> <nodes> <node uname="alice" type="normal" id="f11899c3-ed6e-4e63-abae-b9af90c62283"/> <node uname="bob" type="normal" id="663bae4d-44a0-407f-ac14-389150407159"/> </nodes> <resources/> <constraints/> </configuration> </cib> The exact format and contents of this file are documented at length on the Linux-HA web site, but for practical purposes it is important to understand that this cluster has two nodes named alice and bob, and that neither any resources nor any resource constraints have been configured at this point.

Adding a DRBD-backed service to the cluster configuration


This section explains how to enable a DRBD-backed service in a Heartbeat CRM cluster. The examples used in this section mimic, in functionality, those described in the section called Heartbeat resources, dealing with R1-style Heartbeat clusters. The complexity of the configuration steps described in this section may seem overwhelming to some, particularly those having previously dealt only with R1-style Heartbeat configurations. While the configuration of Heartbeat CRM clusters is indeed complex (and sometimes not very user-friendly), the CRM's advantages may outweigh those of R1-style clusters. Which approach to follow is entirely up to the administrator's discretion. Using the drbddisk resource agent in a Heartbeat CRM configuration

Even though you are using Heartbeat in CRM mode, you may still utilize R1-compatible resource agents such as drbddisk. This resource agent provides no secondary node monitoring, and ensures only resource promotion and demotion. In order to enable a DRBD-backed configuration for a MySQL database in a Heartbeat CRM cluster with drbddisk, you would use a configuration like this: <group ordered="true" collocated="true" id="rg_mysql"> <primitive class="heartbeat" type="drbddisk" provider="heartbeat" id="drbddisk_mysql"> <meta_attributes> <attributes> <nvpair name="target_role" value="started"/> </attributes> </meta_attributes> <instance_attributes> <attributes> <nvpair name="1" value="mysql"/> </attributes> </instance_attributes> </primitive> <primitive class="ocf" type="Filesystem" provider="heartbeat" id="fs_mysql"> <instance_attributes> <attributes> <nvpair name="device" value="/dev/drbd0"/> <nvpair name="directory" value="/var/lib/mysql"/> <nvpair name="type" value="ext3"/> </attributes> </instance_attributes> </primitive> <primitive class="ocf" type="IPaddr2" provider="heartbeat" id="ip_mysql"> <instance_attributes> <attributes> <nvpair name="ip" value="192.168.42.1"/> <nvpair name="cidr_netmask" value="24"/> <nvpair name="nic" value="eth0"/> </attributes> </instance_attributes> </primitive> <primitive class="lsb" type="mysqld" provider="heartbeat" id="mysqld"/> </group> Assuming you created this configuration in a temporary file named /tmp/hb_mysql.xml, you would add this resource group to the cluster configuration using the following command (on any cluster node): cibadmin -o resources -C -x /tmp/hb_mysql.xml After this, Heartbeat will automatically propagate the newly-configured resource group to all cluster nodes. Using the drbd OCF resource agent in a Heartbeat CRM configuration The drbd resource agent is a pure-bred OCF RA which provides Master/Slave capability, allowing Heartbeat to start and monitor the DRBD resource on multiple nodes and promoting and demoting as needed. You must, however, understand that the drbd RA disconnects and

detaches all DRBD resources it manages on Heartbeat shutdown, and also upon enabling standby mode for a node. In order to enable a DRBD-backed configuration for a MySQL database in a Heartbeat CRM cluster with the drbd OCF resource agent, you must create both the necessary resources, and Heartbeat constraints to ensure your service only starts on a previously promoted DRBD resource. It is recommended that you start with the constraints, such as shown in this example: <constraints> <rsc_order id="mysql_after_drbd" from="rg_mysql" action="start" to="ms_drbd_mysql" to_action="promote" type="after"/> <rsc_colocation id="mysql_on_drbd" to="ms_drbd_mysql" to_role="master" from="rg_mysql" score="INFINITY"/> </constraints> Assuming you put these settings in a file named /tmp/constraints.xml, here is how you would enable them: cibadmin -U -x /tmp/constraints.xml Subsequently, you would create your relevant resources: <resources> <master_slave id="ms_drbd_mysql"> <meta_attributes id="ms_drbd_mysql-meta_attributes"> <attributes> <nvpair name="notify" value="yes"/> <nvpair name="globally_unique" value="false"/> </attributes> </meta_attributes> <primitive id="drbd_mysql" class="ocf" provider="heartbeat" type="drbd"> <instance_attributes id="ms_drbd_mysql-instance_attributes"> <attributes> <nvpair name="drbd_resource" value="mysql"/> </attributes> </instance_attributes> <operations id="ms_drbd_mysql-operations"> <op id="ms_drbd_mysql-monitor-master" name="monitor" interval="29s" timeout="10s" role="Master"/> <op id="ms_drbd_mysql-monitor-slave" name="monitor" interval="30s" timeout="10s" role="Slave"/> </operations> </primitive> </master_slave> <group id="rg_mysql"> <primitive class="ocf" type="Filesystem" provider="heartbeat" id="fs_mysql"> <instance_attributes id="fs_mysql-instance_attributes"> <attributes> <nvpair name="device" value="/dev/drbd0"/> <nvpair name="directory" value="/var/lib/mysql"/> <nvpair name="type" value="ext3"/> </attributes> </instance_attributes> </primitive> <primitive class="ocf" type="IPaddr2" provider="heartbeat" id="ip_mysql">

<instance_attributes id="ip_mysql-instance_attributes"> <attributes> <nvpair name="ip" value="10.9.42.1"/> <nvpair name="nic" value="eth0"/> </attributes> </instance_attributes> </primitive> <primitive class="lsb" type="mysqld" provider="heartbeat" id="mysqld"/> </group> </resources> Assuming you put these settings in a file named /tmp/resources.xml, here is how you would enable them: cibadmin -U -x /tmp/resources.xml After this, your configuration should be enabled. Heartbeat now selects a node on which it promotes the DRBD resource, and then starts the DRBD-backed resource group on that same node.

Managing Heartbeat CRM clusters


Assuming control of cluster resources
A Heartbeat CRM cluster node may assume control of cluster resources in the following ways: Manual takeover of a single cluster resource. This is the approach normally taken if one simply wishes to test resource migration, or move a resource to the local node as a means of manual load balancing. This operation is performed using the following command: crm_resource -r resource -M -H `uname -n`

Note The -M (or --migrate) option for the crm_resource command, when used without the -H option, implies a resource migration awayfrom the local host. You must initiate a migration to the local host by specifying the -H option, giving the local host name as the option argument. It is also important to understand that the migration is permanent, that is, unless told otherwise, Heartbeat will not move the resource back to a node it was previously migrated away from even if that node happens to be the only surviving node in a near-cluster-wide system failure. This is undesirable under most circumstances. So, it is prudent to immediately un-migrate resources after successful migration, using the the following command:
crm_resource -r resource -U

Finally, it is important to know that during resource migration, Heartbeat may simultaneously migrate resources other than the one explicitly specified (as required by existing resource groups or colocation and order constraints).

Manual takeover of all cluster resources. This procedure involves switching the peer node to standby mode (where hostname is the peer node's host name): crm_standby -U hostname -v on

Relinquishing cluster resources


A Heartbeat CRM cluster node may be forced to give up one or all of its resources in several ways. Giving up a single cluster resource. A node gives up control of a single resource when issued the following command (note that the considerations outlined in the previous section apply here, too): crm_resource -r resource -M If you want to migrate to a specific host, use this variant: crm_resource -r resource -M -H hostname However, the latter syntax is usually of little relevance to CRM clusters using DRBD, DRBD being limited to two nodes (so the two variants are, essentially, identical in meaning). Switching a cluster node to standby mode. This is the approach normally taken if one simply wishes to test resource migration, or perform some other activity that does not require the node to leave the cluster. This operation is performed using the following command: crm_standby -U `uname -n` -v on Shutting down the local cluster manager instance. This approach is suited for local maintenance operations such as software updates which require that the node be temporarily removed from the cluster, but which do not necessitate a system reboot. The procedure is the same as for Heartbeat R1 style clusters. Shutting down the local node. For hardware maintenance or other interventions that require a system shutdown or reboot, use a simple graceful shutdown command, just as previously outlined for Heartbeat R1 style clusters.

You might also like