Skip to content

Colocation Rules

Pacemaker resource groups and colocation constraints are essential for managing interdependent resources and ensuring coordinated failover in a high-availability cluster. By grouping related resources and defining colocation rules, you enforce logical dependencies that prevent partial failures and maintain service continuity during node outages.


Resource Groups: Bundling Interdependent Resources

A resource group is a logical container for one or more resources that should be managed as a single unit. This ensures that all resources within the group are started, stopped, and migrated together, preserving application consistency.

Creating a Resource Group

To create a resource group, use the crm configure command and define it in the cluster configuration. For example:

crm configure primitive web_server ocf:heartbeat:HTTP \
  params port=80 \
  op start timeout=20s \
  op stop timeout=20s

crm configure primitive shared_fs ocf:heartbeat:Filesystem \
  params device="/dev/sdb" directory="/var/www" \
  op start timeout=20s \
  op stop timeout=203

crm configure group web_group web_server shared_fs

This groups the web_server and shared_fs resources, ensuring they move together during failover.

Verifying the Group

Use crm configure show to inspect the group structure:

crm configure show | grep -A 5 'group'
Output will include the group definition and its member resources.


Colocation Constraints: Enforcing Node-Level Dependencies

Colocation constraints ensure that specific resources (or groups) are scheduled on the same node. This is critical for dependencies where one resource requires another to be active, such as a database needing a shared storage resource.

Defining a Colocation Constraint

To colocate a resource group with another resource, use the <colocation> element in the configuration. For example:

crm configure colocation web_group_with_storage \
  score=INFINITY \
  resource=web_group \
  rsc=storage_resource

This ensures the web_group is always placed on the same node as storage_resource. The score=INFINITY enforces a hard requirement, while lower scores allow flexibility.

Example Use Case

If a database resource (db_resource) depends on a shared storage resource (storage_resource), you might colocate them:

crm configure colocation db_with_storage \
  score=INFINITY \
  resource=db_resource \
  rsc=storage_resource


Best Practices for Resource Groups and Colocation

  1. Group tightly coupled resources (e.g., application + database + filesystem) to avoid partial failures.
  2. Use colocation for critical dependencies (e.g., ensuring a database runs only on nodes with attached storage).
  3. Balance colocation scores to avoid over-constraining the cluster while meeting operational needs.
  4. Test failover scenarios to validate that grouped resources and colocation rules behave as expected.

Key takeaways

  • Resource groups bundle interdependent resources for unified management during failover.
  • Colocation constraints ensure resources (or groups) are scheduled on the same node, preserving application integrity.
  • Proper grouping and colocation rules prevent partial failures and improve cluster reliability.
  • Always validate configurations with crm configure show and test failover scenarios.