第 24 章 Configuring a node placement strategy
Pacemaker decides where to place a resource according to the resource allocation scores on every node. The resource will be allocated to the node where the resource has the highest score. This allocation score is derived from a combination of factors, including resource constraints, resource-stickiness settings, prior failure history of a resource on each node, and utilization of each node.
If the resource allocation scores on all the nodes are equal, by the default placement strategy Pacemaker will choose a node with the least number of allocated resources for balancing the load. If the number of resources on each node is equal, the first eligible node listed in the CIB will be chosen to run the resource.
Often, however, different resources use significantly different proportions of a node’s capacities (such as memory or I/O). You cannot always balance the load ideally by taking into account only the number of resources allocated to a node. In addition, if resources are placed such that their combined requirements exceed the provided capacity, they may fail to start completely or they may run with degraded performance. To take these factors into account, Pacemaker allows you to configure the following components:
- the capacity a particular node provides
- the capacity a particular resource requires
- an overall strategy for placement of resources
24.1. Utilization attributes and placement strategy 复制链接链接已复制到粘贴板!
To configure the capacity that a node provides or a resource requires, you can use utilization attributes for nodes and resources. You do this by setting a utilization variable for a resource and assigning a value to that variable to indicate what the resource requires, and then setting that same utilization variable for a node and assigning a value to that variable to indicate what that node provides.
You can name utilization attributes according to your preferences and define as many name and value pairs as your configuration needs. The values of utilization attributes must be integers.
Configuring node and resource capacity
The following example procedure configures utilization attributes for two nodes and then specifies the same utilization attributes that three different resources require. A node is considered eligible for a resource if it has sufficient free capacity to satisfy the resource’s requirements, as defined by the utilization attributes.
Procedure
Configure utilization attributes for
node1. This command configures a node attribute of CPU capacity, setting this attribute as the variablecpuand definingnode1as providing a CPU capacity of two. This command also defines a utilization attribute of RAM capacity, setting this attribute as the variablememoryand definingnode1as providing a RAM capacity of 2048.# pcs node utilization node1 cpu=2 memory=2048Configure utilization attributes for
node2. This command configures a node attribute of CPU capacity, setting this attribute as the variablecpuand definingnode2as providing a CPU capacity of four. This command also defines a utilization attribute of RAM capacity, setting this attribute as the variablememoryand definingnode2as providing a RAM capacity of 2048.# pcs node utilization node2 cpu=4 memory=2048Specify the utilization attributes that resource
dummy-smallrequires. In this example,dummy-smallrequires a CPU capacity of 1 and a RAM capacity of 1024.# pcs resource utilization dummy-small cpu=1 memory=1024Specify the utilization attributes that resource
dummy-mediumrequires. In this example,dummy-mediumrequires a CPU capacity of 2 and a RAM capacity of 2048.# pcs resource utilization dummy-medium cpu=2 memory=2048Specify the utilization attributes that resource
dummy-largerequires. In this example,dummy-requiresrequires a CPU capacity of 1 and a RAM capacity of 3072.# pcs resource utilization dummy-large cpu=3 memory=3072
Displaying node utilization as pcs commands
You can export node utilization as a series of pcs commands by using the --output-format=cmd option. This is useful for scripting, automation, or replicating the same configuration on a different system.
You can display the configured node utilization in one of three formats:
-
text: Displays the output in plain text. This is the default format. -
json: Displays the output in a machine-readable JSON format, which is useful for scripting and automation. -
cmd: Displays the output as a series ofpcscommands, which you can use to recreate the same node utilization on a different system.
To display the configured node utilization as a series of
pcscommands:# pcs node utilization --output-format=cmdExample output
pcs node utilization node1 cpu=2 pcs node utilization node2 cpu=4
Configuring placement strategy
After you have configured the capacities your nodes provide and the capacities your resources require, you need to set the placement-strategy cluster property, otherwise the capacity configurations have no effect.
Four values are available for the placement-strategy cluster property:
-
default- Utilization values are not taken into account at all. Resources are allocated according to allocation scores. If scores are equal, resources are evenly distributed across nodes. -
utilization- Utilization values are taken into account only when deciding whether a node is considered eligible (that is, whether it has sufficient free capacity to satisfy the resource’s requirements). Load-balancing is still done based on the number of resources allocated to a node. -
balanced- Utilization values are taken into account when deciding whether a node is eligible to serve a resource and when load-balancing, so an attempt is made to spread the resources in a way that optimizes resource performance. -
minimal- Utilization values are taken into account only when deciding whether a node is eligible to serve a resource. For load-balancing, an attempt is made to concentrate the resources on as few nodes as possible, thereby enabling possible power savings on the remaining nodes.
The following example command sets the value of placement-strategy to balanced. After running this command, Pacemaker will ensure the load from your resources will be distributed evenly throughout the cluster, without the need for complicated sets of colocation constraints.
# pcs property set placement-strategy=balanced