Archives

Categories

Heartbeat version 2.0 CIB STONITH example configuration

Below is a sample script to configure the ssh STONITH agent for the Heartbeat system. STONITH will reboot nodes when things go wrong to restore the integrity of the cluster.

The STONITH test program supports the -n option to list parameters and the -l option to list nodes. The following is an example of using it with the ssh agent:
# stonith -t ssh -n
hostlist
# stonith -t ssh hostlist="node-0 node-1" -l
node-0
node-1

The hostlist tuple is the only configuration option for ssh. It is assumed that you have passwordless ssh logins allowed between root on all the nodes in the cluster so the host name list is all that’s needed.

The important thing to note about the constraint is that you are constraining the parent of the clones (which in this example has an ID of “DoFencing“) not a clone instance.

ssh is the simplest and in many ways least useful method of STONITH, but it’s good for an example as everyone knows it. Once you get ssh going it’ll be trivial to get the other methods working.

See below for the script to insert the XML in the CIB.

#!/bin/bash
if [ "$1" = "start" ]; then
  cibadmin --obj_type resources --cib_create -p << END
  <clone id="DoFencing">
    <instance_attributes>
      <attributes>
        <nvpair name="clone_max" value="2"/>
        <nvpair name="clone_node_max" value="1"/>
      </attributes>
    </instance_attributes>
    <primitive id="child_DoFencing" class="stonith" type="ssh">
      <operations>
        <op name="monitor" interval="5s" timeout="20s"
        prereq="nothing"/>
        <op name="start" timeout="20s" prereq="nothing"/>
      </operations>
      <instance_attributes>
        <attributes>
          <nvpair name="hostlist" value="node-0 node-1"/>
        </attributes>
      </instance_attributes>
    </primitive>
  </clone>
END
  sleep 1
  cibadmin --obj_type constraints --cib_create -p << END
  <rsc_location id="stonith-cons:0" rsc="DoFencing">
      <rule id="stonith-cons-rule-node-0" score="100000">
        <expression id="stonith-cons-rule-expression-node-0"
          attribute="#uname" operation="eq" value="node-0"/>
      </rule>
  </rsc_location>
END
  cibadmin --obj_type constraints --cib_create -p << END
  <rsc_location id="stonith-cons:1" rsc="DoFencing">
      <rule id="stonith-cons-rule-node-1" score="100000">
        <expression id="stonith-cons-rule-expression-node-1"
          attribute="#uname" operation="eq" value="node-1"/>
      </rule>
  </rsc_location>
END
else
  cibadmin -D --obj_type resources -X '<clone id="DoFencing">'
  cibadmin -D --obj_type constraints -X \
          '<rsc_location id="stonith-cons:0">'
  cibadmin -D --obj_type constraints -X \
          '<rsc_location id="stonith-cons:1">'
fi

1 comment to Heartbeat version 2.0 CIB STONITH example configuration