heartbeatのSTONITHにfence_xvmを使ってみた
Fedora12のfence-virtパッケージ, CentOS5のcmanパッケージには、Fedora12 ホストOSのfence-virtdパッケージと連携し、他のゲストOSをFenceできるfence_xvmが付属している。このパッケージはRHCSのFenceDeviceとして使用できるが、合わせてheartbeatのSTONITH用のデバイスとしても使用できる。
ここでは、fence_xvmをSTONITHデバイスとして設定してみた。
STONITH向けスクリプトの作成
Fedora12, CentOS5とともに標準パッケージ内にはSTONITH向けのスクリプトが付属していないため、個別にSTONITH向けのスクリプトを作成する必要がある。
heartbeat(Fedora12ではpacemaker)では、STONITH向けのスクリプトは、/usr/lib/stonith/plugins/external/ に置かれているので、次のスクリプトをfence_xvm_stonithとして配置する。
#!/bin/sh # # Rewrite the hostlist to accept "," as a delimeter for hostnames too. hostlist=`echo $hostlist | tr ',' ' '` case $1 in gethosts) for h in $hostlist ; do echo ${h} done exit 0 ;; on) res=1 for h in ${hostlist}; do if [ "${h}" != "${2}" ]; then continue fi fence_xvm -H ${h%%.*} -o on res=$? done exit ${res} ;; off) res=1 for h in ${hostlist}; do if [ "${h}" != "${2}" ]; then continue fi fence_xvm -H ${h%%.*} -o off res=$? done exit ${res} ;; reset) fence_xvm -H ${2%%.*} -o off exit $? ;; status) fence_xvm -H ${2%%.*} -o status exit $? ;; getconfignames) echo "hostlist" exit 0 ;; getinfo-devid) echo "fence_xvm STONITH device" exit 0 ;; getinfo-devname) echo "fence_xvm STONITH external device" exit 0 ;; getinfo-devdescr) echo "fence_xvm-based Linux host reset" echo "Fine for testing, but not suitable for production!" exit 0 ;; getinfo-devurl) echo "http://www.google.co.jp" exit 0 ;; getinfo-xml) cat << FENCEVIRTXML <parameters> <parameter name="hostlist" unique="1" required="1"> <content type="string" /> <shortdesc lang="en"> Hostlist </shortdesc> <longdesc lang="en"> The list of hosts that the STONITH device controls </longdesc> </parameter> </parameters> FENCEVIRTXML exit 0 ;; *) exit 1 ;; esac
この状態で、heartbeatが動作しているノード上で、
# stonith -L
を実行すると、 external/fence_xvm_stonith が表示される。
STONITHデバイスとして動作しているかを確認するには、次のように入力し、実際にVMが停止されることを確認する。(下の例は、centos-virt14/15をクラスタとし、centos-virt14からcentos-virt15を停止する場合。)
# stonith -t external/fence_xvm_stonith \ hostlist="centos-virt14.jp.example.org centos-virt15.jp.example.org" \ centos-virt15.jp.example.org -T reset
STONITHデバイスの設定
STONITHデバイスを実際に設定する方法はCentOS5と、Fedora12でかなり大きな違いがある。
CentOS5の場合
CentOS5ではEPELからheartbeatをyumでインストールできるので、筆者はこちらを利用した。(heartbeat-2.1.4-11.el5 のパッケージを使用)
なお、heartbeatの2.0系列では、2ノードクラスタのリソース管理のために、crmを使用する方法と、haresourceを使用する方法があるが、ここではcrmを使用する方法を使っている。
設定方法としては、次のリンクを参考にした。
http://www.atmarkit.co.jp/flinux/rensai/heartbeat03/heartbeat03c.html
この系列のcrmでは、設定用のGUIやシェルが存在しないため、オンラインで設定を反映するには、cibadmin(cib.xmlを直接編集するためのツール。。)を使用する必要がある。。設定内容は、次の3点となる。
1. crm_configのstonith_enabled をTRUEに設定する
2. resoruces でprimitiveとしてexternal/fence_xvm_stonithを設定する
3. constraintsでrsc_location を設定し、stonith用のデバイスが正しいノードで実行されるようにする。
参考までに、設定に使用したxmlファイルを添付しておく。。(基本的にこれらのxmlファイルを # cibadmin -C -x xmlファイル名 や、 # cibadmin -U -x xmlファイル名 で反映すれば登録できるはずである。。 orz)
1: stonith_enabled を設定 <?xml version="1.0" ?> <cib> <configuration> <crm_config> <cluster_property_set id="cib-bootstrap-options"> <attributes> <nvpair id="stonith_enabled" name="stonith_enabled" value="TRUE"/> </attributes> </cluster_property_set> </crm_config> </configuration> </cib> 2: STONITH用のデバイスを設定 <?xml version="1.0" ?> <cib> <configuration> <resources> <primitive class="stonith" id="stonith-fence_xvm_centos-virt14" provider="heartbeat" type="external/fence_xvm_stonith"> <instance_attributes id="stonith-fence_xvm-instance_attributes_centos-virt14"> <attributes> <nvpair id="stonith-fence_xvm-hostlist_centos-virt14" name="hostlist" value="centos-virt14.jp.example.org centos-virt14.jp.example.org"/> </attributes> </instance_attributes> </primitive> </resources> </configuration> </cib> 3: STONITH用のデバイスが正しいノードで起動するように設定 <?xml version="1.0" ?> <cib> <configuration> <constraints> <rsc_location id="rloc_centos-virt14" rsc="stonith-fence_xvm_centos-virt15"> <rule id="rloc_centos-virt14:rule1" score="INFINITY"> <expression id="rlocl_centos-virt14:rule1:expr1" attribute="#uname" operation="eq" value="centos-virt14.jp.example.org"/> </rule> <rule id="rloc_centos-virt14:rule2" score="-INFINITY"> <expression id="rlocl_centos-virt14:rule2:expr1" attribute="#uname" operation="ne" value="centos-virt14.jp.example.org"/> </rule> </rsc_location> <rsc_location id="rloc_centos-virt15" rsc="stonith-fence_xvm_centos-virt14"> <rule id="rloc_centos-virt15:rule1" score="INFINITY"> <expression id="rlocl_centos-virt15:rule1:expr1" attribute="#uname" operation="eq" value="centos-virt15.jp.example.org"/> </rule> <rule id="rloc_centos-virt15:rule2" score="-INFINITY"> <expression id="rlocl_centos-virt15:rule2:expr1" attribute="#uname" operation="ne" value="centos-virt15.jp.example.org"/> </rule> </rsc_location> </constraints> </configuration> </cib>
Fedora12の場合
Fedora12ではpacemakerが直接yumでインストールできるのでそちらを使用した。
http://fedoraproject.org/wiki/Features/Cluster
Pacemakerの場合にはcrmシェルがあるため、xmlファイルを直接編集する必要はないようである。。
STONITH用デバイスの設定には次の3行を追記する。(クラスタが
fedora-virt7/8 の2ノードで構成されている場合。)
primitive fence_xvm_stonith stonith:external/fence_xvm_stonith params hostlist="fedora-virt7.jp.example.org fedora-virt8.jp.example.org" clone fencing fence_xvm_stonith property stonith-enabled=true
稼働確認
STONITHデバイスが上手く動作している時には、crm_mon の出力に、次のような表示が行われるようである。
実行コマンド: # crm_mon -i 1
CentOS5の場合
stonith-fence_xvm_centos-virt14 (stonith:external/fence_xvm_stonith): Started centos-virt15.jp. example.org stonith-fence_xvm_centos-virt15 (stonith:external/fence_xvm_stonith): Started centos-virt14.jp. example.org
Fedora12の場合
Clone Set: fencing Started: [ fedora-virt7.jp.example.org fedora-virt8.jp.example.org ]
設定が上手くいかない場合には、大抵この出力の、"Failed Resouce"の部分で、fence_xvm_stonth_0_start などが出力されているので、色々と確認してみる必要がある。。orz
( xmlファイルでノード名が間違っていないか、など )
実際にSTONITHが起こるかを見てみるには、heartbeatに使っているNICをifdownしてみるとよいようである。。
# ifdown eth0
上手く動作していると、自動的にVMが停止され、リソースが移動するはず、、である。 orz
今のところ、heartbeatとfence_xvmを組み合わせてつかうことがどれぐらいあるかは分からないが、覚えておくのが無難なようである。。