Examples Using PCS Command on Linux- Part 2

Examples Using pcs resource Command

In this article we will seen how to configure the cluster resources in a cluster.

1) How to create a resource in a cluster.

Use the below syntax  to create a cluster resource.

#pcs resource create resource_id standard:provider:type|type [resource options] [op operation_action operation_options [operation_action operation_options]…]

Lets see a  below command, creates a resource with the name Virtual_IP of standard ocf, provider heartbeat, and type IPaddr2. The floating address of this resource is 192.168.1.10, the system will check whether the resource is running every 30 seconds.

# pcs resource create Virtual_IP ocf:heartbeat:IPaddr2 ip=192.168.1.10 cidr_netmask=24 op monitor interval=30s

Now, verify that the Virtual_IP resource has been added and display the cluster’s status to see that it is now active.

# pcs status
Cluster name: Mysql_cluster
Stack: corosync
Current DC: node2-server (version 1.1.15-11.el7-e174ec8) - partition with quorum
Last updated: Mon Apr 10 03:46:34 2017          Last change: Mon Apr 10 03:12:54 2017 by root via cibadmin on node1-server
2 nodes and 1 resource configured
Online: [ node1-server node2-server ]
Full list of resources:
 Virtual_IP     (ocf::heartbeat:IPaddr2):       Started node1-server
Daemon Status:
  corosync: active/disabled
  pacemaker: active/disabled
  pcsd: active/enabled

As below screenshot, The first field, i.e ocf, is the standard to which the resource script conforms to and where to find it. The second field is specific to OCF resources and tells the cluster which namespace to find the resource script in, in this case heartbeat. The last field indicates the name of the resource script.

To obtain a list of the available resource standards, run below command.

#  pcs resource standards
ocf
lsb
service
systemd

To obtain a list of the available ocf resource providers.

# pcs resource providers
heartbeat
openstack
pacemaker

If you want to see all the resource agents available for a specific ocf provider, run below command;

# pcs resource agents ocf:heartbeat
CTDB
Delay
Dummy
Filesystem
IPaddr
IPaddr2
IPsrcaddr
LVM
.
.
.
.
.
rsyncd
slapd
symlink
tomcat

To obtain a list of all available resources.

#pcs resource list
ocf:.isolation:docker-wrapper - docker wrapper
ocf:heartbeat:CTDB - CTDB Resource Agent
ocf:heartbeat:Delay - Waits for a defined timespan
.
.
.
.
systemd:tuned
systemd:vsftpd
systemd:vsftpd@
systemd:wpa_supplicant

To obtain a list of available resources filtered by the specified string.

#pcs resource list string

For example;

#pcs resource list ocf
ocf:.isolation:docker-wrapper - docker wrapper
ocf:heartbeat:CTDB - CTDB Resource Agent
ocf:heartbeat:Delay - Waits for a defined timespan
.
.
.
.
.
ocf:pacemaker:controld - DLM Agent for cluster file systems
ocf:pacemaker:ping - node connectivity
ocf:pacemaker:pingd - pingd resource agent
ocf:pacemaker:remote - remote resource agent

2) How to delete a configured resource in a cluster.

To delete the configured resource below command is used;

#pcs resource delete Virtual_IP

3) How to display the Resource-Specific Parameters.

By using below command, you can display the parameters which we can set during the creation of resource.

#pcs resource describe standard:provider:type

# pcs resource describe ocf:heartbeat:Delay
ocf:heartbeat:Delay - Waits for a defined timespan

This script is a test resource for introducing delay.

Resource options:
  startdelay: How long in seconds to delay on start operation.
  stopdelay: How long in seconds to delay on stop operation. Defaults to "startdelay" if unspecified.
  mondelay: How long in seconds to delay on monitor operation. Defaults to "startdelay" if
            unspecified.
#

4) How to show all currently configured resources.

Using following command, you can check all  configured resource.

# pcs resource show <resource id>

# pcs resource show Virtual_IP
 Resource: Virtual_IP (class=ocf provider=heartbeat type=IPaddr2)
  Attributes: ip=192.168.1.10 cidr_netmask=24
  Operations: start interval=0s timeout=20s (Virtual_IP-start-interval-0s)
              stop interval=0s timeout=20s (Virtual_IP-stop-interval-0s)
              monitor interval=30s (Virtual_IP-monitor-interval-30s)

#

Using –full option, all configured resource options will be displayed.

#pcs resource show --full

5) How to Stop and Start cluster resource.

Using following command you can stop a resource on a node.

# pcs resource
 Master/Slave Set: WebserverClone [DRBD]
     Masters: [ node1.server ]
     Slaves: [ node2.server ]
 DRBD_fs        (ocf::heartbeat:Filesystem):    Started node1.server
 VirtIP (ocf::heartbeat:IPaddr2):       Started node1.server
 Httpd  (ocf::heartbeat:apache):        Started node1.server
# pcs resource disable Httpd
# pcs resource
 Master/Slave Set: WebserverClone [DRBD]
     Masters: [ node1.server ]
     Slaves: [ node2.server ]
 DRBD_fs        (ocf::heartbeat:Filesystem):    Started node1.server
 VirtIP (ocf::heartbeat:IPaddr2):       Started node1.server
 Httpd  (ocf::heartbeat:apache):        Stopped (disabled)

Note: Depending on the rest of the configuration (constraints, options, failures, etc), the resource may remain stopped.

To start the resource on a node, following command is used;

# pcs resource enable Httpd
# pcs resource
 Master/Slave Set: WebserverClone [DRBD]
     Masters: [ node1.server ]
     Slaves: [ node2.server ]
 DRBD_fs        (ocf::heartbeat:Filesystem):    Started node1.server
 VirtIP (ocf::heartbeat:IPaddr2):       Started node1.server
 Httpd  (ocf::heartbeat:apache):    Started node1.server

6) How to  ban a resource on a node.

Following command is used to Prevent the resource id specified from running on the node.

#pcs resource ban <resource id> [node]

Note: If no node specified, it’s banned on current node.

To Remove constraints created by ban on the specified resource,following command is used;

#pcs resource clear <resource id>

7) How to update (Add/Change) options to specified resource.

To add or change options to specified resource check the following examples;

# pcs resource show VirtIP
 Resource: VirtIP (class=ocf provider=heartbeat type=IPaddr2)
  Attributes: ip=192.168.1.20 cidr_netmask=24
  Operations: start interval=0s timeout=20s (VirtIP-start-interval-0s)
              stop interval=0s timeout=20s (VirtIP-stop-interval-0s)
              monitor interval=30s (VirtIP-monitor-interval-30s)
# pcs resource update  VirtIP cidr_netmask=23
# pcs resource show VirtIP
 Resource: VirtIP (class=ocf provider=heartbeat type=IPaddr2)
  Attributes: ip=192.168.1.20 cidr_netmask=23
  Operations: start interval=0s timeout=20s (VirtIP-start-interval-0s)
              stop interval=0s timeout=20s (VirtIP-stop-interval-0s)

Similarly if you want to  update monitor operation for a resource, see on following example;

# pcs resource show VirtIP
 Resource: VirtIP (class=ocf provider=heartbeat type=IPaddr2)
  Attributes: ip=192.168.1.20 cidr_netmask=24
  Operations: start interval=0s timeout=20s (VirtIP-start-interval-0s)
              stop interval=0s timeout=20s (VirtIP-stop-interval-0s)
              monitor interval=30s (VirtIP-monitor-interval-30s)
# pcs resource update  VirtIP op monitor interval=10s
# pcs resource show VirtIP
 Resource: VirtIP (class=ocf provider=heartbeat type=IPaddr2)
  Attributes: ip=192.168.1.20 cidr_netmask=24
  Operations: start interval=0s timeout=20s (VirtIP-start-interval-0s)
              stop interval=0s timeout=20s (VirtIP-stop-interval-0s)
              monitor interval=10s (VirtIP-monitor-interval-10s) 
              monitor interval=30s (VirtIP-monitor-interval-30s)
#

8) How to display a list of all configured resources.

Use following command, To display a list of all configured resources.

# pcs resource show
 Master/Slave Set: WebserverClone [DRBD]
     Masters: [ node1.server ]
     Slaves: [ node2.server ]
 DRBD_fs        (ocf::heartbeat:Filesystem):    Started node1.server
 VirtIP (ocf::heartbeat:IPaddr2):       Started node1.server
 Httpd  (ocf::heartbeat:apache):        Started node1.server
#

Use the –full option, To display a list of all configured resources and the parameters configured for those resources.

# pcs resource show --full
 Master: WebserverClone
  Meta Attrs: master-node-max=1 clone-max=2 notify=true master-max=1 clone-node-max=1
  Resource: DRBD (class=ocf provider=linbit type=drbd)
   Attributes: drbd_resource=webserver
   Operations: start interval=0s timeout=240 (DRBD-start-interval-0s)
               promote interval=0s timeout=90 (DRBD-promote-interval-0s)
               demote interval=0s timeout=90 (DRBD-demote-interval-0s)
               stop interval=0s timeout=100 (DRBD-stop-interval-0s)
               monitor interval=30s (DRBD-monitor-interval-30s)
 Resource: DRBD_fs (class=ocf provider=heartbeat type=Filesystem)
  Attributes: device=/dev/drbd1 directory=/drbd1 fstype=ext4
  Operations: start interval=0s timeout=60 (DRBD_fs-start-interval-0s)
              stop interval=0s timeout=60 (DRBD_fs-stop-interval-0s)
              monitor interval=20 timeout=40 (DRBD_fs-monitor-interval-20)
 Resource: VirtIP (class=ocf provider=heartbeat type=IPaddr2)
  Attributes: ip=192.168.1.20 cidr_netmask=24
  Operations: start interval=0s timeout=20s (VirtIP-start-interval-0s)
              stop interval=0s timeout=20s (VirtIP-stop-interval-0s)
              monitor interval=10s (VirtIP-monitor-interval-10s)
 Resource: Httpd (class=ocf provider=heartbeat type=apache)
  Attributes: configfile=/etc/httpd/conf/httpd.conf statusurl=http://127.0.0.1/server-status
  Operations: monitor interval=20s (Httpd-monitor-interval-20s)
              start interval=0 timeout=60s (Httpd-start-interval-0)
              stop interval=0 timeout=60s (Httpd-stop-interval-0)

To displays the currently configured parameters for resource, following command used.

# pcs resource show VirtIP
 Resource: VirtIP (class=ocf provider=heartbeat type=IPaddr2)
  Attributes: ip=192.168.1.20 cidr_netmask=24
  Operations: start interval=0s timeout=20s (VirtIP-start-interval-0s)
              stop interval=0s timeout=20s (VirtIP-stop-interval-0s)
              monitor interval=10s (VirtIP-monitor-interval-10s)
#

9) How to cluster Resources Cleanup.

Suppose if a resource showing failure message. The following command, resets the resource status and fail-count , telling the cluster to forget the operation history of a resource and re-detect its current state.

# pcs resource cleanup Httpd
Cleaning up Httpd on node1.server, removing fail-count-Httpd
Cleaning up Httpd on node2.server, removing fail-count-Httpd
Waiting for 2 replies from the CRMd.. OK
#

Note: If you do not specify a resource_id, this command resets the resource status and failcount for all resources.

10) How to move a resource to other node.

Use the below command, to move the resource on which it is currently running to other node.

#pcs resource move <resource_id>

11) How to Managed the Resources.

You can set a resource to u n man ag ed mode, which indicates that the resource is still in the configuration but Pacemaker does not manage the resource.

# pcs resource unmanage <resource  id>

To sets resources to man ag ed mode, which is the default state;

#pcs resource manage <resource  id>

Read Also:
Examples Using PCS Command on Linux- Part 1

Allow Local User to Gives Read/Write Access to the Cluster Configuration.

Hope this post will help Linux/Unix beginners. Please share you feedback and Comments. Stay tune for more updates with ittroubleshooter.in …!!!

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz