Heartbeat2のインストール(両方のノードで)
http://www.linux-ha.org/ja/DownloadSoftware_ja
からRedHat Enterprise 4用のRPMを利用する。
[root@h1 heartbeat-2.1.2-2.rhel4.x86_64.RPMS]# rpm -ivh heartbeat-pils-2.1.2-2.x86_64.rpm Preparing... ########################################### [100%] 1:heartbeat-pils ########################################### [100%] [root@h1 heartbeat-2.1.2-2.rhel4.x86_64.RPMS]# rpm -ivh heartbeat-stonith-2.1.2-2.x86_64.rpm Preparing... ########################################### [100%] 1:heartbeat-stonith ########################################### [100%] [root@h1 heartbeat-2.1.2-2.rhel4.x86_64.RPMS]# rpm -ivh heartbeat-2.1.2-2.x86_64.rpm Preparing... ########################################### [100%] 1:heartbeat ########################################### [100%] [root@h1 heartbeat-2.1.2-2.rhel4.x86_64.RPMS]# rpm -ivh heartbeat-gui-2.1.2-2.x86_64.rpm Preparing... ########################################### [100%] 1:heartbeat-gui ########################################### [100%]
インストールする順番は、
1. pils
2. stonith
3. heartbeat
Heartbeat2の設定ファイル:ha.cf
/etc/ha.d/ha.cf
debugfile /var/log/ha-debug logfile /var/log/ha-log logfacility syslog #use_logd yes keepalive 2 deadtime 30 warntime 10 initdead 120 udpport 694 bcast eth1 # dedicated interconnect mcast eth0 224.1.1.1 694 1 0 auto_failback off node h1 node h2 crm yes
cib.xml
/var/lib/heartbeat/crm/cib.xml
haresourcesから生成する場合は、drbddiskの後にリソース名を指定すること。
h1 172.20.95.50 drbddisk::d0 Filesystem::/dev/drbd0::/mnt/drbd/mysql::ext3 mysql
sticknessはINFINITYに変更すること。(変更しないと自動フェールバックしてしまう。)
またmysqlスクリプトのファイル権限にも注意すること。
<?xml version="1.0" ?> <cib admin_epoch="0" epoch="0" num_updates="0"> <configuration> <crm_config> <cluster_property_set id="cib-bootstrap-options"> <attributes> <nvpair id="cib-bootstrap-options-symmetric-cluster" name="symmetric-cluster" value="true"/> <nvpair id="cib-bootstrap-options-no-quorum-policy" name="no-quorum-policy" value="stop"/> <nvpair id="cib-bootstrap-options-default-resource-stickiness" name="default-resource-stickiness" value="INFINITY"/> <nvpair id="cib-bootstrap-options-default-resource-failure-stickiness" name="default-resource-failure-stickiness" value="0"/> <nvpair id="cib-bootstrap-options-stonith-enabled" name="stonith-enabled" value="false"/> <nvpair id="cib-bootstrap-options-stonith-action" name="stonith-action" value="reboot"/> <nvpair id="cib-bootstrap-options-stop-orphan-resources" name="stop-orphan-resources" value="true"/> <nvpair id="cib-bootstrap-options-stop-orphan-actions" name="stop-orphan-actions" value="true"/> <nvpair id="cib-bootstrap-options-remove-after-stop" name="remove-after-stop" value="false"/> <nvpair id="cib-bootstrap-options-short-resource-names" name="short-resource-names" value="true"/> <nvpair id="cib-bootstrap-options-transition-idle-timeout" name="transition-idle-timeout" value="5min"/> <nvpair id="cib-bootstrap-options-default-action-timeout" name="default-action-timeout" value="15s"/> <nvpair id="cib-bootstrap-options-is-managed-default" name="is-managed-default" value="true"/> </attributes> </cluster_property_set> </crm_config> <nodes/> <resources> <group id="group_1"> <primitive class="ocf" id="IPaddr_172_20_95_50" provider="heartbeat" type="IPaddr"> <operations> <op id="IPaddr_172_20_95_50_mon" interval="5s" name="monitor" timeout="5s"/> </operations> <instance_attributes id="IPaddr_172_20_95_50_inst_attr"> <attributes> <nvpair id="IPaddr_172_20_95_50_attr_0" name="ip" value="172.20.95.50"/> </attributes> </instance_attributes> </primitive> <primitive class="heartbeat" id="drbddisk_2" provider="heartbeat" type="drbddisk"> <operations> <op id="drbddisk_2_mon" interval="120s" name="monitor" timeout="60s"/> </operations> <instance_attributes id="drbddisk_2_inst_attr"> <attributes> <nvpair id="drbddisk_2_attr_1" name="1" value="d0"/> </attributes> </instance_attributes> </primitive> <primitive class="ocf" id="Filesystem_3" provider="heartbeat" type="Filesystem"> <operations> <op id="Filesystem_3_mon" interval="120s" name="monitor" timeout="60s"/> </operations> <instance_attributes id="Filesystem_3_inst_attr"> <attributes> <nvpair id="Filesystem_3_attr_0" name="device" value="/dev/drbd0"/> <nvpair id="Filesystem_3_attr_1" name="directory" value="/mnt/drbd"/> <nvpair id="Filesystem_3_attr_2" name="fstype" value="ext3"/> </attributes> </instance_attributes> </primitive> <primitive class="heartbeat" id="mysql_4" provider="heartbeat" type="mysql"> <operations> <op id="mysql_4_mon" interval="60s" name="monitor" timeout="30s"/> </operations> </primitive> </group> </resources> <constraints> <rsc_location id="rsc_location_group_1" rsc="group_1"> <rule id="prefered_location_group_1" score="100"> <expression attribute="#uname" id="prefered_location_group_1_expr" operation="eq" value="h1"/> </rule> </rsc_location> </constraints> </configuration> <status/> </cib>
authkeys
/etc/ha.d/authkeys
auth 1 1 crc
Heartbeat2の設定
mysqlスタートアップスクリプトのコピー
[root@h1 resource.d]# cp /etc/rc.d/init.d/mysql /etc/ha.d/resource.d/ [root@h2 resource.d]# cp /etc/rc.d/init.d/mysql /etc/ha.d/resource.d/
このスクリプトは、本来はMySQLバイナリに入っているものだが、バグが(MySQL Bugs: #31785: mysql.server stop does not spot server gone away)あるので、修正版を利用する。
各サービスの停止
必要に応じてサービスを停止する。
[root@h1 resource.d]# service drbd stop
Stopping all DRBD resources.
[root@h1 resource.d]# service mysql stop
MySQL manager or server PID file could not be found! [失敗]
[root@h1 resource.d]# service heartbeat stop
Stopping High-Availability services:
[ OK ]
logd is already stopped
h2でも同様の処理を行う。
スタートアップスクリプトに登録(両方のノードで)
[root@h1 resource.d]# chkconfig drbd on [root@h1 resource.d]# chkconfig mysql off [root@h1 resource.d]# chkconfig heartbeat on
h2でも同様の処理を行う。
drbdの起動 (両方のノードで)
[root@h1 resource.d]# service drbd start Starting DRBD resources: [ d0 s0 n0 ].
h2でも同様の処理を行う。
heartbeatの起動(両方のノードで)
[root@h1 resource.d]# service heartbeat start
h2でも同様の処理を行う。
Heartbeat2の稼働確認
[root@h1 ha.d]# crm_mon -i 3 Refresh in 1s...============
Last updated: Thu Nov 8 18:16:25 2007
Current DC: h2 (73553d5d-1a50-4f55-99de-8ba7aec48426)
2 Nodes configured.
1 Resources configured.
============Node: h2 (73553d5d-1a50-4f55-99de-8ba7aec48426): online
Node: h1 (ce2c28c3-585e-494b-baa8-d38b7e7ebd9e): onlineResource Group: group_1
IPaddr_172_20_95_50 (heartbeat::ocf:IPaddr): Started h1
drbddisk_2 (heartbeat:drbddisk): Started h1
Filesystem_3 (heartbeat::ocf:Filesystem): Started h1
mysql_4 (heartbeat:mysql): Started h1