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:
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¶
- Group tightly coupled resources (e.g., application + database + filesystem) to avoid partial failures.
- Use colocation for critical dependencies (e.g., ensuring a database runs only on nodes with attached storage).
- Balance colocation scores to avoid over-constraining the cluster while meeting operational needs.
- 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 showand test failover scenarios.