Chapter 3. The pcs command-line interface
The pcs command-line interface controls and configures cluster services such as corosync, pacemaker,booth, and sbd by providing an easier interface to their configuration files.
Note that you should not edit the cib.xml configuration file directly. In most cases, Pacemaker will reject a directly modified cib.xml file.
3.1. pcs help display Copy linkLink copied to clipboard!
You use the -h option of pcs to display the parameters of a pcs command and a description of those parameters.
The following command displays the parameters of the pcs resource command.
pcs resource -h
# pcs resource -h
3.2. Viewing the raw cluster configuration Copy linkLink copied to clipboard!
Although you should not edit the cluster configuration file directly, you can view the raw cluster configuration with the pcs cluster cib command.
You can save the raw cluster configuration to a specified file with the pcs cluster cib filename command. If you have previously configured a cluster and there is already an active CIB, you use the following command to save the raw xml file.
pcs cluster cib filename
pcs cluster cib filename
For example, the following command saves the raw xml from the CIB into a file named testfile.
pcs cluster cib testfile
# pcs cluster cib testfile
3.3. Saving a configuration change to a working file Copy linkLink copied to clipboard!
When configuring a cluster, you can save configuration changes to a specified file without affecting the active CIB. This allows you to specify configuration updates without immediately updating the currently running cluster configuration with each individual update.
For information about saving the CIB to a file, see Viewing the raw cluster configuration. Once you have created that file, you can save configuration changes to that file rather than to the active CIB by using the -f option of the pcs command. When you have completed the changes and are ready to update the active CIB file, you can push those file updates with the pcs cluster cib-push command.
Procedure
The following is the recommended procedure for pushing changes to the CIB file. This procedure creates a copy of the original saved CIB file and makes changes to that copy. When pushing those changes to the active CIB, this procedure specifies the diff-against option of the pcs cluster cib-push command so that only the changes between the original file and the updated file are pushed to the CIB. This allows users to make changes in parallel that do not overwrite each other, and it reduces the load on Pacemaker which does not need to parse the entire configuration file.
Save the active CIB to a file. This example saves the CIB to a file named
original.xml.pcs cluster cib original.xml
# pcs cluster cib original.xmlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Copy the saved file to the working file you will be using for the configuration updates.
cp original.xml updated.xml
# cp original.xml updated.xmlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Update your configuration as needed. The following command creates a resource in the file
updated.xmlbut does not add that resource to the currently running cluster configuration.pcs -f updated.xml resource create VirtualIP ocf:heartbeat:IPaddr2 ip=192.168.0.120 op monitor interval=30s
# pcs -f updated.xml resource create VirtualIP ocf:heartbeat:IPaddr2 ip=192.168.0.120 op monitor interval=30sCopy to Clipboard Copied! Toggle word wrap Toggle overflow Push the updated file to the active CIB, specifying that you are pushing only the changes you have made to the original file.
pcs cluster cib-push updated.xml diff-against=original.xml
# pcs cluster cib-push updated.xml diff-against=original.xmlCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Alternately, you can push the entire current content of a CIB file with the following command.
pcs cluster cib-push filename
pcs cluster cib-push filename
When pushing the entire CIB file, Pacemaker checks the version and does not allow you to push a CIB file which is older than the one already in a cluster. If you need to update the entire CIB file with a version that is older than the one currently in the cluster, you can use the --config option of the pcs cluster cib-push command.
pcs cluster cib-push --config filename
pcs cluster cib-push --config filename
3.4. Displaying cluster status Copy linkLink copied to clipboard!
There are a variety of commands you can use to display the status of a cluster and its components.
You can display the status of the cluster and the cluster resources with the following command.
pcs status
# pcs status
You can display the status of a particular cluster component with the commands parameter of the pcs status command, specifying resources, cluster, nodes, or pcsd.
pcs status commands
pcs status commands
For example, the following command displays the status of the cluster resources.
pcs status resources
# pcs status resources
The following command displays the status of the cluster, but not the cluster resources.
pcs cluster status
# pcs cluster status
If you run the pcs status command before Pacemaker has completed any actions required by changes to the CIB, the cluster state at that time might not match the desired status. In RHEL Hat Enterprixe Linux 9.5 and later, you can ensure that Pacemaker does not need to take any further actions by running the pcs status wait command.
The pcs status wait command waits until the cluster has completed all current actions before returning a value. If any actions unrelated to your recent changes are in progress, the command waits until those are completed. The pcs status wait command returns a value of 0 as soon as Pacemaker completes pending actions.
You can specify a period of time to wait. If the current actions have not completed after that time period, the command prints an error and returns a value of 1.
The following command waits until Pacemaker has applied configuration changes.
pcs status wait
# pcs status wait
Waiting for the cluster to apply configuration changes...
The following command waits up to one minute until Pacemaker has applied configuration changes.
pcs status wait 1min
# pcs status wait 1min
Waiting for the cluster to apply configuration changes (timeout: 60 seconds)...
3.5. Displaying the full cluster configuration Copy linkLink copied to clipboard!
Use the following command to display the full current cluster configuration.
pcs config
# pcs config
3.6. Displaying resource status Copy linkLink copied to clipboard!
In a complex cluster setup, you might need to determine the status of an individual resource in a cluster before performing a cluster or resource action. In Red Hat Enterprise Linux 9.5 and later, you can query various attributes of a single resource in a cluster with the pcs status query resource commands. You can use these commands for pcs-based scripting because there is no need to parse plain text outputs.
The pcs status query resource commands query the following attributes:
- the existence of the resource
- the type of the resource
- the state of the resource
- various information about the members of a collective resource
- on which nodes the resource is running
The following command queries whether a resource has started.
pcs status query resource RESOURCE_ID is-state started
# pcs status query resource RESOURCE_ID is-state started
For example, the following command queries whether the resource resource1 has started.
pcs status query resource resource1 is-state started
# pcs status query resource resource1 is-state started
True
For a full list of the pcs status query resource commands, see the pcs(8) man page on your system.
3.7. Modifying the corosync.conf file with the pcs command Copy linkLink copied to clipboard!
You can use the pcs command to modify the parameters in the corosync.conf file.
The following command modifies the parameters in the corosync.conf file.
pcs cluster config update [transport pass:quotes[transport options]] [compression pass:quotes[compression options]] [crypto pass:quotes[crypto options]] [totem pass:quotes[totem options]] [--corosync_conf pass:quotes[path]]
pcs cluster config update [transport pass:quotes[transport options]] [compression pass:quotes[compression options]] [crypto pass:quotes[crypto options]] [totem pass:quotes[totem options]] [--corosync_conf pass:quotes[path]]
The following example command udates the knet_pmtud_interval transport value and the token and join totem values.
pcs cluster config update transport knet_pmtud_interval=35 totem token=10000 join=100
# pcs cluster config update transport knet_pmtud_interval=35 totem token=10000 join=100
3.8. Displaying the corosync.conf file with the pcs command Copy linkLink copied to clipboard!
The following command displays the contents of the corosync.conf cluster configuration file.
pcs cluster corosync
# pcs cluster corosync
You can print the contents of the corosync.conf file in a human-readable format with the pcs cluster config command, as in the following example.
The output for this command includes the UUID for the cluster if the cluster was created in RHEL 9.1 or later, or if the UUID was added manually as described in Identifying clusters by UUID.
You can run the pcs cluster config show command with the --output-format=cmd option to display the pcs configuration commands that can be used to recreate the existing corosync.conf file, as in the following example.