HeartBeat連携

HeartBeatのインストール

[root@test_dev1 ~]# yum install -y heartbeat
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
 * addons: www.ftp.ne.jp
 * extras: www.ftp.ne.jp
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package heartbeat.i386 0:2.1.3-3.el5.centos set to be updated
--> Processing Dependency: heartbeat-stonith = 2.1.3-3.el5.centos for package: heartbeat
--> Processing Dependency: heartbeat-pils = 2.1.3-3.el5.centos for package: heartbeat
--> Processing Dependency: libstonith.so.1 for package: heartbeat
--> Processing Dependency: PyXML for package: heartbeat
--> Processing Dependency: libpils.so.1 for package: heartbeat
--> Running transaction check
---> Package heartbeat-stonith.i386 0:2.1.3-3.el5.centos set to be updated
---> Package PyXML.i386 0:0.8.4-4 set to be updated
---> Package heartbeat-pils.i386 0:2.1.3-3.el5.centos set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================
 Package                    Arch            Version                   Repository       Size
=======================================================================================================
Installing:
 heartbeat                  i386            2.1.3-3.el5.centos        extras           1.7 M
Installing for dependencies:
 PyXML                      i386            0.8.4-4                   base             1.1 M
 heartbeat-pils             i386            2.1.3-3.el5.centos        extras           213 k
 heartbeat-stonith          i386            2.1.3-3.el5.centos        extras           311 k

Transaction Summary
=======================================================================================================
Install      4 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Total download size: 3.3 M
Downloading Packages:
(1/4): heartbeat-pils-2.1.3-3.el5.centos.i386.rpm              | 213 kB     00:00     
(2/4): heartbeat-stonith-2.1.3-3.el5.centos.i386.rpm           | 311 kB     00:00     
(3/4): PyXML-0.8.4-4.i386.rpm                    (29%) 40% [===-        ]  0.0 B/s | 464 kB     --:-- ETA 
(3/4): PyXML-0.8.4-4.i386.rpm                                  | 1.1 MB     00:00     
(4/4): heartbeat-2.1.3-3.el5.centos.i386.rpm     (58%) 18% [===-        ]  0.0 B/s | 320 kB     --:-- ETA 
(4/4): heartbeat-2.1.3-3.el5.centos.i386.rpm     (70%) 42% [=====-      ] 664 kB/s | 728 kB     00:01 ETA 
(4/4): heartbeat-2.1.3-3.el5.centos.i386.rpm     (93%) 86% [=========== ] 775 kB/s | 1.4 MB     00:00 ETA 
(4/4): heartbeat-2.1.3-3.el5.centos.i386.rpm                   | 1.7 MB     00:01     
---------------------------------------------------------------------------------------------
Total                                                 1.2 MB/s | 3.3 MB     00:02     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : heartbeat-pils                                    [1/4] 
  Installing     : heartbeat-stonith                                 [2/4] 
  Installing     : PyXML                                             [3/4] 
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

Installed: heartbeat.i386 0:2.1.3-3.el5.centos
Dependency Installed: PyXML.i386 0:0.8.4-4 heartbeat-pils.i386 0:2.1.3-3.el5.centos 
heartbeat-stonith.i386 0:2.1.3-3.el5.centos
Complete!
[root@test_dev1 ~]# yum install -y heartbeat
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * updates: www.ftp.ne.jp
 * addons: www.ftp.ne.jp
 * extras: www.ftp.ne.jp
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package heartbeat.i386 0:2.1.3-3.el5.centos set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================================
 Package                    Arch            Version                   Repository       Size
=======================================================================================================
Installing:
 heartbeat                  i386            2.1.3-3.el5.centos        extras           1.7 M

Transaction Summary
=======================================================================================================
Install      1 Package(s)         
Update       0 Package(s)         
Remove       0 Package(s)         

Total download size: 1.7 M
Downloading Packages:
heartbeat-2.1.3-3.el5.centos.i386.rpm            37% [==========        ]  0.0 B/s | 632 kB     --:-- ETA 
heartbeat-2.1.3-3.el5.centos.i386.rpm            80% [================- ] 1.2 MB/s | 1.3 MB     00:00 ETA 
heartbeat-2.1.3-3.el5.centos.i386.rpm                                              | 1.7 MB     00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : heartbeat                                         [1/1] 

Installed: heartbeat.i386 0:2.1.3-3.el5.centos
Complete!
[root@test_dev1 ~]#

HeartBeatの設定ファイルコピー

[root@test_dev1 ~]# cp /usr/share/doc/heartbeat-*/ha.cf /etc/ha.d/
[root@test_dev1 ~]# cp /usr/share/doc/heartbeat-*/logd.cf /etc/
[root@test_dev1 ~]# cp /usr/share/doc/heartbeat-*/authkeys /etc/ha.d/
[root@test_dev1 ~]# 

HeartBeatのpgsql用ファイルをコピー

[root@test_dev1 ~]# cp /usr/lib/ocf/resource.d/heartbeat/pgsql /etc/ha.d/resource.d/
[root@test_dev1 ~]#

設定ファイル編集

[root@test_dev1 ~]# vi /etc/ha.d/ha.cf
------------------------------------ここから------------------------------------
crm on
keepalive 2
deadtime  30
initdead  120
udpport   694
bcast     eth0
watchdog /dev/watchdog
node test_dev1
node test_dev2
use_logd yes
------------------------------------ここまで------------------------------------
[root@test_dev1 ~]# vi /etc/logd.cf
------------------------------------ここから------------------------------------
debugfile    /var/log/ha-debug
logfile      /var/log/ha-log
logfacility  none
------------------------------------ここまで------------------------------------
[root@test_dev1 ~]# vi /etc/ha.d/authkeys
------------------------------------ここから------------------------------------
auth 1
1 crc
------------------------------------ここまで------------------------------------

認証ファイルの権限変更

[root@test_dev1 ~]# chmod 600 /etc/ha.d/authkeys
[root@test_dev1 ~]#

両サーバでリソースファイル作成

[root@test_dev1 ~]# vi /etc/ha.d/haresources
------------------------------------ここから------------------------------------
test_dev1 IPaddr2::192.168.10.80/24/eth0/192.168.10.255 \
          drbddisk::r0 \
          Filesystem::/dev/drbd0::/data::ext3 \
          pgsql::::::::::::::::::::
------------------------------------ここまで------------------------------------

cibファイルを生成

[root@test_dev1 ~]# rm -f /var/lib/heartbeat/crm/cib.xml*
[root@test_dev1 ~]# /usr/lib/heartbeat/haresources2cib.py /etc/ha.d/haresources 
[root@test_dev1 ~]# 

cibファイルを編集

[root@test_dev1 ~]# vi /var/lib/heartbeat/crm/cib.xml
-------------------------------省略-------------------------------------
< primitive class="ocf" id="IPaddr2_1" provider="heartbeat" type="IPaddr2" > 
  < operations > 
    < op id="IPaddr2_1_mon" interval="5s" name="monitor" timeout="5s"/ > 
  < /operations > 
  < instance_attributes id="IPaddr2_1_inst_attr" > 
    < attributes > 
      < nvpair id="IPaddr2_1_attr_0" name="ip" value="192.168.10.80"/ > 
      < nvpair id="IPaddr2_1_attr_1" name="nic" value="eth0"/ > 
      < nvpair id="IPaddr2_1_attr_2" name="cidr_netmask" value="24"/ > 
      < nvpair id="IPaddr2_1_attr_3" name="broadcast" value="192.168.10.255"/ > 
    < /attributes > 
  < /instance_attributes > 
< /primitive > 
-------------------------------省略-------------------------------------
< primitive class="ocf" id="pgsql_4" provider="heartbeat" type="pgsql" > 
  < operations > 
    < op id="pgsql_4_mon" interval="120s" name="monitor" timeout="60s"/ > 
  < /operations > 
  < instance_attributes id="pgsql_4_inst_attr" > 
    < attributes > 
      < nvpair id="pgsql_4_attr_0" name="pgctl" value="/usr/local/pgsql/bin/pg_ctl"/ > 
      < nvpair id="pgsql_4_attr_1" name="start_opt"/ > 
      < nvpair id="pgsql_4_attr_2" name="ctl_opt"/ > 
      < nvpair id="pgsql_4_attr_3" name="psql" value="/usr/local/pgsql/bin/psql"/ > 
      < nvpair id="pgsql_4_attr_4" name="pgdata" value="/data/pgsql/data"/ > 
      < nvpair id="pgsql_4_attr_5" name="pgdba" value="postgres"/ > 
      < nvpair id="pgsql_4_attr_6" name="pghost"/ > 
      < nvpair id="pgsql_4_attr_7" name="pgport" value="5432"/ > 
      < nvpair id="pgsql_4_attr_8" name="pgdb" value="template1"/ > 
      < nvpair id="pgsql_4_attr_9" name="logfile" value="/data/pgsql.log"/ > 
    < /attributes > 
  < /instance_attributes > 
< /primitive > 
-------------------------------省略-------------------------------------

cibファイルをチェック

[root@test_dev1 ~]# crm_verify -x /var/lib/heartbeat/crm/cib.xml
[root@test_dev1 ~]# rm -f /etc/ha.d/haresources 
[root@test_dev1 ~]# 

起動

[root@test_dev1 ~]# /etc/rc.d/init.d/heartbeat start
Starting High-Availability services: 
                                                           [  OK  ]
[root@test_dev1 ~]# chkconfig heartbeat on
[root@test_dev1 ~]#

動作確認

確認

[root@test_dev1 ~]# crm_mon
Defaulting to one-shot mode
You need to have curses available at compile time to enable console mode


============
Last updated: Tue Jun  2 13:51:24 2009
Current DC: test_dev2 (f67a4bd5-4b26-4476-b4b8-d398a735b8f8)
2 Nodes configured.
1 Resources configured.
============

Node: test_dev2 (f67a4bd5-4b26-4476-b4b8-d398a735b8f8): online
Node: test_dev1 (7778425f-3d96-4672-92ad-00894d924ded): online

Resource Group: group_1
    IPaddr2_1   (heartbeat::ocf:IPaddr2):       Started test_dev1
    drbddisk_2  (heartbeat:drbddisk):   Started test_dev1
    Filesystem_3        (heartbeat::ocf:Filesystem):    Started test_dev1
    pgsql_4     (heartbeat::ocf:pgsql): Started test_dev1
[root@test_dev1 ~]# 
[root@test_dev1 ~]# df
Filesystem           1K-ブロック    使用   使用可 使用% マウント位置
/dev/mapper/VolGroup00-LogVol00
                       6094400   3286352   2556392  57% /
/dev/sda1               101086     18162     77705  19% /boot
tmpfs                    62800         0     62800   0% /dev/shm
/dev/drbd0             1419048     64568   1282396   5% /data
[root@test_dev1 ~]# 

切り替え

[root@test_dev1 ~]# /etc/init.d/heartbeat stop
Stopping High-Availability services: 
                                                           [  OK  ]
[root@test_dev1 ~]#
[root@test_dev2 ~]# crm_mon
Defaulting to one-shot mode
You need to have curses available at compile time to enable console mode


============
Last updated: Tue Jun  2 13:26:02 2009
Current DC: test_dev2 (f67a4bd5-4b26-4476-b4b8-d398a735b8f8)
2 Nodes configured.
1 Resources configured.
============

Node: test_dev2 (f67a4bd5-4b26-4476-b4b8-d398a735b8f8): online
Node: test_dev1 (7778425f-3d96-4672-92ad-00894d924ded): OFFLINE

Resource Group: group_1
    IPaddr2_1   (heartbeat::ocf:IPaddr2):       Started test_dev2
    drbddisk_2  (heartbeat:drbddisk):   Started test_dev2
    Filesystem_3        (heartbeat::ocf:Filesystem):    Started test_dev2
    pgsql_4     (heartbeat::ocf:pgsql): Started test_dev2
[root@test_dev2 ~]# 
[root@test_dev2 ~]# df
Filesystem           1K-ブロック    使用   使用可 使用% マウント位置
/dev/mapper/VolGroup00-LogVol00
                       6094400   3307856   2534888  57% /
/dev/sda1               101086     18162     77705  19% /boot
tmpfs                    62800         0     62800   0% /dev/shm
/dev/drbd0             1419048     64568   1282396   5% /data
[root@test_dev2 ~]#

補足

自動起動の設定を行う(両サーバで処理を行う)

[root@test_dev1 ~]# chkconfig heartbeat on
[root@test_dev1 ~]# 

スタンバイへ切り替え

[root@test_dev2 ]# crm_standby -U test_dev1 -v on
[root@test_dev2 ]#
最終更新:2009年06月02日 16:53