HeartBeat インストール

2021-06-18

概要

keepalivedに続き、HeartBeatもインストールしてみました。
その時にインストール時のメモです。

構成情報

構成は、2台のノード(192.168.24.153,192.168.24.154)で構成し、仮想IPとして192.168.24.161をフロントとします。

OS

  • CentOS5.5

ミドルウェア

  • heartbeat 2.1.3-3
  • apache 2.2.3-43

※上記の環境を、VirtualBOXで構築しています

+-----------------------------------------------------------------+
| HOSTNAME | IP [eth0] | IP [eth1]
+-----------------------------------------------------------------+
| ex-ha_test1 | 192.168.24.153 | 172.168.0.153
| ex-ha_test2 | 192.168.24.154 | 172.168.0.154
| ex-ha_test | 192.168.24.161 <= http(仮想IP)
+-----------------------------------------------------------------+

【作業内容】

  • HeartBeat V2 インストール
  • HeartBeat V2 設定
  • HeartBeat 起動
  • 動作確認
  • apache インストール
  • apache 動作確認

HeartBeat V2 のインストール(RPMパッケージ)

両方のホスト(ex-ha_test1,ex-ha_test2)でも ともに実施します。

(1)HeartBeatのインストール(1回目)

# yum -y install heartbeat

(2)HeartBeatのインストール(2回目)

以下のエラーとなるので再度、インストールを実施します

useradd: ユーザ hacluster は存在します
error: %pre(heartbeat-2.1.3-3.el5.centos.i386) scriptlet failed, exit status 9
error:   install: %pre scriptlet failed (2), skipping heartbeat-2.1.3-3.el5.centos

(3)エラーとなった、haclusterのユーザー情報を確認します

# cat /etc/passwd|grep hacluster
hacluster:x:498:496::/var/lib/heartbeat/cores/hacluster:/bin/bash

HeartBeatの設定ファイル

両方のホスト(ex-ha_test1,ex-ha_test2)でも ともに実施します。

(1)設定ファイルのコピー

# cp -p /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/
# cp -p /usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d/
# cp -p /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/

(2)/etc/hostsの設定

hosts に監視用ネットワーク(172.168.0.0/24)を追加

# vi /etc/hsots
172.168.0.153 ex-ha_test1
172.168.0.154 ex-ha_test2

(3)ha.cfの設定 (ex-ha_test1側)

# cp -p /etc/ha.d/ha.cf /etc/ha.d/ha.cf.org
# vi /etc/ha.d/ha.cf
crm on
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
bcast eth1
auto_failback on
node ex-ha_test1
node ex-ha_test2

(4)ha.cfの設定 (ex-ha_test2側)

# cp -p /etc/ha.d/ha.cf /etc/ha.d/ha.cf.org
# vi /etc/ha.d/ha.cf
crm on
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 30
warntime 10
initdead 120
udpport 694
bcast eth1
auto_failback on
node ex-ha_test1
node ex-ha_test2

設定項目の詳細は、ここを参照

(5)authkeys の設定

# cp -p /etc/ha.d/authkeys /etc/ha.d/authkeys.org
# vi /etc/ha.d/authkeys
auth 3
3 md5 Hello!
# chmod 600 /etc/ha.d/authkeys
# chown root:root /etc/ha.d/authkeys

設定項目の詳細は、ここを参照

HeartBeatの起動 ex-ha_test1,ex-ha_test2 ともに実施

(1)自動起動の設定

# chkconfig --add heartbeat
# chkconfig --list|grep heart
heartbeat 0:off 1:off 2:on 3:on 4:on 5:on 6:off

(2)keepaliceの起動

順番は、ex-ha_test1 ⇒ ex-ha_test2で実施

# /etc/init.d/heartbeat start
Starting High-Availability services:

[ OK ]

動作確認

(1)crm_monでクラスタ状態を確認します

両系とも、onlineである事を確認します

# crm_mon
Defaulting to one-shot mode
You need to have curses available at compile time to enable console mode

============
Last updated: Fri Mar 18 17:19:16 2011
Current DC: ex-ha_test1 (e6ffd284-6313-411e-b27f-989c1fd1682f)
2 Nodes configured.
0 Resources configured.
============

Node: ex-ha_test2 (ee8b503b-458f-4119-b608-fe6dd9160338): online
Node: ex-ha_test1 (e6ffd284-6313-411e-b27f-989c1fd1682f): online

apache の組込み

(1)apache インストール

# yum -y install httpd
# chkconfig httpd off
# chkconfig --list httpd
httpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
※ heartbeat経由でapache が自動的に起動するので自動起動はOFFに設定します

(2)仮想IPの設定する前にheartbeatのサービスを一旦停止します

# /etc/rc.d/init.d/heartbeat stop
Stopping High-Availability services:
[ OK ]

apache も念のため、停止します
# /etc/init.d/httpd stop
httpd を停止中: [ OK ]

設定の編集(cib.xml, httpd.conf)

(1)cib.xmlのディレクトリに移動

# cd /var/lib/heartbeat/crm
# ls -l
合計 16
-rw------- 2 hacluster haclient 812 3月 18 17:42 cib.xml
-rw------- 2 hacluster haclient 812 3月 18 17:42 cib.xml.last
-rw-r--r-- 2 hacluster haclient 32 3月 18 17:42 cib.xml.sig
-rw-r--r-- 2 hacluster haclient 32 3月 18 17:42 cib.xml.sig.last

(2)不要なファイル(cib.xml.last,cib.xml.sig*)を削除します

※cib.xml のみ残します

# rm -f cib.xml.last
# rm -f cib.xml.sig*

(3)cib.xmlの編集

# cp -p cib.xml cib.xml.org
# vi cib.xml

<cib generated="false" admin_epoch="0" epoch="1" have_quorum="true" ignore_dtd="false" num_peers="2" cib_feature_revision="2.0" num_updates="13" cib-last-written="Fri Mar 18 17:42:54 2011" ccm_transition="2">
<configuration>
<crm_config>
<cluster_property_set id="cib-bootstrap-options">
<attributes>
<nvpair id="cib-bootstrap-options-dc-version" name="dc-version" value="2.1.3-node: 552305612591183b1628baa5bc6e903e0f1e26a3"/>
</attributes>
</cluster_property_set>
</crm_config>
<nodes>
<node id="e6ffd284-6313-411e-b27f-989c1fd1682f" uname="ex-ha_test1" type="normal"/>
<node id="ee8b503b-458f-4119-b608-fe6dd9160338" uname="ex-ha_test2" type="normal"/>
</nodes>

<!-- 下記(<resources/>)を削除して下記を追加
<resources/> -->

<!--- 追記箇所 ここから --->
<resources>
<group id="group_apache">
<primitive id="ipaddr" class="ocf" type="IPaddr" provider="heartbeat">
<instance_attributes id="ia_ipaddr">
<attributes>
<nvpair id="ia_ipaddr_ip" name="ip" value="192.168.24.161"/>
<nvpair id="ia_ipaddr_nic" name="nic" value="eth0"/>
<nvpair id="ia_ipaddr_netmask" name="netmask" value="24"/>
</attributes>
</instance_attributes>
</primitive>
<primitive id="apache" class="ocf" type="apache" provider="heartbeat">
<instance_attributes id="ia_apache">
<attributes>
<nvpair id="ia_apache_configfile" name="configfile" value="/etc/httpd/conf/httpd.conf"/>
</attributes>
</instance_attributes>
</primitive>
</group>
</resources>
<!--- 追記箇所 ここまで --->
<constraints/>
</configuration>
</cib>

※ サンプルファイルは、ここより入手

(4)httpd.conf の編集

# cp -p /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.org
# vi /etc/httpd/conf/httpd.conf

# Listen 80
# 134行目を以下のように、仮想IPに変更
Listen 192.168.24.161:80

# 903行目:コメント解除し、以下のように変更

SetHandler server-status
Order deny,allow
# Deny from all
Allow from all

(5)cib.xml の構文チェック

何も表示されなければOKです

# crm_verify -x /var/lib/heartbeat/crm/cib.xml

(6)heartbeat の起動

# /etc/rc.d/init.d/heartbeat start
Starting High-Availability services:
[ OK ]

(7)crm_monでクラスタ状態を確認します

しばらくしてから、crm_monで状態を確認します

# crm_mon -i 3
Defaulting to one-shot mode
You need to have curses available at compile time to enable console mode

============
Last updated: Fri Mar 18 18:21:22 2011
Current DC: ex-ha_test2 (ee8b503b-458f-4119-b608-fe6dd9160338)
2 Nodes configured.
1 Resources configured.
============

Node: ex-ha_test1 (e6ffd284-6313-411e-b27f-989c1fd1682f): OFFLINE
Node: ex-ha_test2 (ee8b503b-458f-4119-b608-fe6dd9160338): online

Resource Group: group_apache
ipaddr (heartbeat::ocf:IPaddr): Started ex-ha_test2
apache (heartbeat::ocf:apache): Started ex-ha_test2

apache 動作確認

(1)テストページ作成(ex-ha_test1側)

# vi /var/www/html/index.html
<h1>ex-ha_test1 test page</h1>

(2)テストページ作成(ex-ha_test2側)

# vi /var/www/html/index.html
<h1>ex-ha_test2 test page</h1>

(3)動作確認 (フェイルオーバー)

以下の手順で、アクティブ側のheartbeatを停止して、フェイルオーバーを発生させます

(4)[ ex-ha_test1 ] のheartbeatを停止

# /etc/rc.d/init.d/heartbeat stop
Stopping High-Availability services:
[ OK ]

(5)ブラウザで確認すると、待機系のWEB画面が表示され、フェイルオーバーした事が確認できます

(6)動作確認 (フェイルバック)

      アクティブ側のheartbeatを停止して、フェイルオーバーを発生させて後に、アクティブ系を再開します

(7)[ ex-ha_test1 ] のheartbeatを停止

# /etc/rc.d/init.d/heartbeat stop
Stopping High-Availability services:
[ OK ]

(8)ブラウザで確認すると、スタンバイ系のWEB画面が表示され、フェイルオーバーした事が確認する

(9)[ ex-ha_test1 ] のheartbeatを起動

# /etc/rc.d/init.d/heartbeat start
Starting High-Availability services:
[ OK ]

(10)ブラウザで確認すると、アクティブ系のWEB画面が表示され、フェイルバックした事が確認できます

スポンサーリンク

0
0