Product SiteDocumentation Site

6.4. Placing Resources Relative to other Resources

Colocation constraints tell the cluster that the location of one resource depends on the location of another one.
Colocation has an important side-effect: it affects the order in which resources are assigned to a node. Think about it: You can’t place A relative to B unless you know where B is. [15]
So when you are creating colocation constraints, it is important to consider whether you should colocate A with B, or B with A.
Another thing to keep in mind is that, assuming A is colocated with B, the cluster will take into account A’s preferences when deciding which node to choose for B.
For a detailed look at exactly how this occurs, see Colocation Explained.

Important

Colocation constraints affect only the placement of resources; they do not require that the resources be started in a particular order. If you want resources to be started on the same node and in a specific order, you need both an ordering constraint (see Section 6.3, “Specifying the Order in which Resources Should Start/Stop”) and a colocation constraint, or alternatively, a group (see Section 10.1, “Groups - A Syntactic Shortcut”).

6.4.1. Colocation Properties

Table 6.3. Properties of a rsc_colocation Constraint

Field Default Description
id
A unique name for the constraint (required).
rsc
The name of a resource that should be located relative to with-rsc (required).
with-rsc
The name of the resource used as the colocation target. The cluster will decide where to put this resource first and then decide where to put rsc (required).
node-attribute
#uname
The node attribute that must be the same on the node running rsc and the node running with-rsc for the constraint to be satisfied. (For details, see Section 6.4.4, “Colocation by Node Attribute”.)
score
Positive values indicate the resources should run on the same node. Negative values indicate the resources should run on different nodes. Values of +/- INFINITY change "should" to "must".



[15] While the human brain is sophisticated enough to read the constraint in any order and choose the correct one depending on the situation, the cluster is not quite so smart. Yet.