32.5. Managing Resources with Pacemaker
Pacemaker turns "which host may do what" into a configured, monitored, and enforced statement. Its input is the CIB, the cluster information base - an XML document replicated across the nodes - and its output is a stream of start, stop, promote, and monitor operations executed by resource agents.
32.5.1. Installing and Configuring the Cluster with crmsh
The crmsh package provides the crm command used throughout this
chapter. On ha1, as john:
$ sudo crm --version
crm 5.0.0
The -D plain prefix disables colorized output; omit it in interactive
use. crm runs either as a one-shot command
(crm status, crm configure show) or as an interactive shell in which
configuration changes are staged and committed together. The interactive
form is what the configuration scripts in this chapter automate: each
script enters the configure level, states the changes, and ends with
commit, so the CIB moves from one consistent state to the next. Every
change is logged to /var/log/crmsh/crmsh.log, referenced by the init
transcript in section 32.3.3.
The CIB itself lives under /var/lib/pacemaker and is synchronized by the
cluster stack; administrators do not edit it by hand. Its content is
inspected with crm configure show, captured in full in section 32.6.3,
and saved to a portable text form with crm configure save, used in
section 32.12.6. Configuration changes can be made from any node; the DC
serializes them and replicates the result.
Two housekeeping facts keep a crmsh-managed cluster debuggable. First,
cluster nodes must agree on software versions: the status header's
DC: ha1 (version 3.0.0-3.0.0) line records the Pacemaker schema version
in use, and nodes running mismatched major versions refuse to cooperate
rather than misinterpret each other's messages. Second, crmsh reaches the
other nodes as root over SSH for bootstrap and maintenance commands; if a
crm cluster subcommand hangs, the first check is SSH trust, not the
cluster.
32.5.2. Resource Agents, Start and Stop Operations, and Monitor Actions
A resource agent is a script with a standard interface: the cluster
calls it with an action (start, stop, monitor, promote, demote,
meta-data) and reads a standard exit code back. The ocf: agents are
the ones used for services; each names its provider and script, as in
ocf:heartbeat:IPaddr2. The agents used by this chapter's stack come
from two packages:
| Agent | Package | Manages |
|---|---|---|
ocf:linbit:drbd |
drbd-utils |
DRBD resource roles and replication state |
ocf:heartbeat:Filesystem |
resource-agents |
mount and unmount of a block device |
ocf:heartbeat:IPaddr2 |
resource-agents |
a virtual address with gratuitous ARP |
ocf:heartbeat:nfsserver |
resource-agents |
the NFS server and its stable identity |
ocf:heartbeat:exportfs |
resource-agents |
NFS export table entries |
Every agent documents its parameters and defaults the same way the fencing
agent did in section 32.4.3. Selected output, on ha1, as john:
$ sudo crm ra info ocf:heartbeat:IPaddr2
ocf:heartbeat:IPaddr2 - Manages virtual IPv4 and IPv6 addresses (Linux specific version)
This Linux-specific resource manages IP alias IP addresses.
It can add an IP alias, or remove one.
In addition, it can implement Cluster Alias IP functionality
if invoked as a clone resource.
When the specified IP address gets assigned to a respective interface, the
resource agent sends unsolicited ARP (Address Resolution Protocol, IPv4) or NA
(Neighbor Advertisement, IPv6) packets to inform neighboring machines about the
change. This functionality is controlled for both IPv4 and IPv6 by shared
'arp_*' parameters.
## Parameters (*: required, []: default):
ip* (string): IPv4 or IPv6 address
The IPv4 (dotted quad notation) or IPv6 address (colon hexadecimal notation)
example IPv4 "192.168.1.1".
example IPv6 "2001:db8:DC28:0:0:FC57:D4C8:1FFF".
arp_bg (string): ARP/NA from background
Whether or not to send the ARP (IPv4) or NA (IPv6) packets in the background.
The listing is trimmed in one place - the agent's long note on its
clone-mode operation, which sits between the description and the
address-assignment paragraph, is omitted - and it continues past the
arp_bg entry with the remaining parameters and the agent's supported
actions. It reads metadata only; it is safe to run anywhere and is
the authoritative answer to "what parameters does this agent take" - more
reliable than copying an example whose parameter names came from a
different version. Two details in this listing are worth noticing: the
required ip parameter the walkthrough sets, and the agent's own
statement of what section 32.6.4 depends on - unsolicited ARP for IPv4
and neighbor advertisements for IPv6 when the address is assigned.
The monitor action is how the cluster learns about failures between
start and stop. A monitor that finds the service healthy returns success;
a monitor that finds it cleanly stopped returns the OCF "not running"
code (7); anything else is a failure, which increments the resource's
failure count on that node. Monitors are declared per operation with an
interval, and a promotable resource can declare different monitors per
role - the DRBD configuration in section 32.6.3 monitors the promoted
instance every 15 seconds and the unpromoted instance every 30, because
the questions worth asking differ by role.
Start and stop are not symmetrical in one important way: stop failures are escalated. A start that fails can be retried elsewhere; a stop that fails blocks the resource from moving, because the cluster cannot risk starting a second copy while the first may still hold state. That asymmetry is why fencing exists - an unfenceable node that will not stop its resources is the stop-failure case at its worst.
32.5.3. Location, Colocation, Ordering, and Promotable Resources
Pacemaker expresses the design in four kinds of statements. Location
constraints score how much a resource prefers each node. Colocation
constraints require two resources to run together (or apart, with
negative scores). Ordering constraints sequence actions. Groups
bundle primitives so they colocate and start in listed order - the
shorthand used by the walkthrough's g_nfs.
A promotable clone runs one instance of a primitive on each node and
promotes at most a configured number of them. The DRBD stack uses exactly
that: clone ms_drbd with promotable=true promoted-max=1 keeps one
instance per node and promotes one, giving the cluster a single object to
place instead of two separately-managed primitives. The promoted instance
is what the colocation constraint points at - in the walkthrough's final
configuration, captured in section 32.6.3:
colocation col_g_master inf: g_nfs ms_drbd:Promoted
order ord_promote_g Mandatory: ms_drbd:promote g_nfs:start
The colocation line reads: the group g_nfs must run on the node whose
ms_drbd clone instance is Promoted, with infinite score - a hard
requirement, not a preference. The order line reads: promote the DRBD
clone before starting the group, and the Mandatory kind makes the
relationship hold for recovery and shutdown as well: the group stops before
the clone demotes. Together the two lines enforce section 32.2.1's three
facts - address, process, and writable data - on one node.
Planned movement uses location constraints under the hood. The captured sequence in section 32.6.5 runs:
$ sudo crm resource move g_nfs ha1
INFO: Move constraint created for g_nfs to ha1
INFO: Use `crm resource clear g_nfs` to remove this constraint
move creates an infinite location preference toward the named node and
the group follows it; clear removes the constraint again. Leaving move
constraints in place after a planned switch is a common way to turn one
failover into a permanent constraint that surprises the next unplanned
one, so the walkthrough clears immediately.
32.5.4. Failure Counts, Timeouts, Stickiness, and Cleanup
Every failed operation increments a per-resource, per-node failure count. The captured cluster defaults show the three settings that govern what happens next:
rsc_defaults rsc-options:
resource-stickiness=100 \
migration-threshold=3 \
priority=0
op_defaults op-options:
timeout=600
resource-stickiness=100 makes a healthy resource prefer its current
node by 100 points. With no location constraints distinguishing the two
nodes, the effect is that failover does not undo itself: when a failed
node returns, the resources it lost stay where they moved to. Failback
becomes an explicit decision (crm resource move), not a default. The
value is small enough that any deliberate constraint outweighs it.
migration-threshold=3 bans a resource from a node after three
failures there, moving it to the other node and keeping it there until
the failure count is cleared. Without it, a resource that fails
repeatably on one node (a bad disk on one host, for example) would keep
returning. With it, the cluster "gives up" locally and recovers by
relocation.
timeout=600 in op_defaults bounds every agent invocation,
including monitors. The default is deliberately generous for
first-resource clusters; production clusters usually tune it down per
operation, because an operation that hangs to its 600-second timeout is
six hundred seconds during which the cluster knows only that the resource
is in an unknown state. Every timeout should exceed the slowest honest
execution of the operation and nothing more.
After the underlying fault is fixed, the failure counts that triggered
the migration persist - that is their point. Clearing them is an explicit
administrative act: sudo crm resource cleanup g_nfs resets the failure
counts for the group's members on all nodes. It is the standard last step
of "the node is healthy again" procedures, and it must never be used as a
substitute for finding out why the failures happened. The practice
cluster never accumulated failures worth clearing, so the command is
documented here from crmsh's manual rather than captured.
32.5.5. Building a DRBD, Filesystem, Service, and Virtual-IP Resource Stack
The walkthrough's service is a stack of five resources whose order is the whole design:
Figure 32.4. The NFS service stack. The promotable DRBD clone runs one instance per node with a single promoted copy; the ordering constraint promotes before the group starts, and the colocation constraint pins the group to whichever node holds the promotion. The group's internal order is filesystem, address, server, export.
Read the stack from the data upward. p_drbd is the promotable DRBD
resource - one promoted instance owns the block device. p_fs mounts
/dev/drbd0 at /srv/ha-data; it can only start where the device is
promoted, which the colocation enforces. p_vip places the service
address on the same node and announces it with gratuitous ARP. p_nfs
starts the NFS server, and p_export installs the export entry that
advertises the mounted tree to clients. Nothing in the group can start on
the wrong node, and the group stops in reverse - unexport first, then the
server, then the address, then the mount - so the visible service always
disappears before the data underneath it.
The same pattern generalizes. A mail server, a version-control server, or
any single-writer daemon substitutes for p_nfs; the filesystem and
address layers rarely change. What must not vary is the direction of
ordering: data first, service last, address in between - because an
address that answers before the service exists is a client-visible
outage, and a service that runs before the data is mounted is a
correctness failure.
Section 32.6.3 writes this stack as a configuration script and loads it into the running cluster.