DRBD+Heartbeat(目次)
| Table of Contents |
DRBDとは
DRBDは、2台以上のサーバでネットワーク越しのデータミラーリングを実現します。 Heartbeatと連携する事で、データベース,nfs,sambaなどのHAクラスタを安価(共有ストレージ無し)に実現する事が可能です。
システム構成
プライマリ側
- ホスト名(IP)
- serv111(192.168.11.111)
- OS
- CentOS 5.4(kernel 2.6.18-164.6.1.el5)
- パッケージ
- drbd83-8.3.2-6.el5_3
- kmod-drbd83-8.3.2-6.el5_3
- heartbeat-2.1.3-3.el5.centos
- HDD構成
- /dev/sda :OS領域
- /dev/sdb :DRBD領域(未フォーマット状態)
セカンダリ側
- ホスト名(IP)
- serv112(192.168.11.112)
- OS
- CentOS 5.4(kernel 2.6.18-164.6.1.el5)
- パッケージ
- drbd83-8.3.2-6.el5_3
- kmod-drbd83-8.3.2-6.el5_3
- heartbeat-2.1.3-3.el5.centos
- HDD構成
- /dev/sda :OS領域
- /dev/sdb :DRBD領域(未フォーマット状態)
仮想IP
- ホスト名(IP)
- serv111(192.168.11.113)
手順に関する補足
- プロンプトが以下の場合はserv111(プライマリ)側のみでコマンドを実行します。
[root@serv111 ~]#
- プロンプトが以下の場合はserv112(セカンダリ)側のみでコマンドを実行します。
[root@serv112 ~]#
- プロンプトが以下の場合はserv111(プライマリ), serv112(セカンダリ)の両方でコマンドを実行します。
#
DRBDのインストール・設定
DRBDパーティンションの作成
DRBD用のパーティンション作成
- fdiskコマンドで「/dev/sdb」にパーティションを作成します。
# fdisk /dev/sdb コマンド (m でヘルプ): n コマンドアクション e 拡張 p 基本領域 (1-4) p 領域番号 (1-4): 1 最初 シリンダ (1-652, default 1): 1 終点 シリンダ または +サイズ または +サイズM または +サイズK (1-652, default 652): 652
- パーティション情報をセーブして終了します。
コマンド (m でヘルプ): w 領域テーブルは交換されました! ioctl() を呼び出して領域テーブルを再読込みします。 ディスクを同期させます。
これでパーティション「/dev/sdb1」が作成されました。
DRBDのインストール
- DRBDはyumで8.3をインストールします。
# yum install drbd83 # yum install kmod-drbd83
DRBDの設定
drbd.confの設定
- drbdの設定を行います。
# vi /etc/drbd.conf global { usage-count no; } common { syncer { rate 10M; } } resource r0 { protocol C; # データ同期のプロトコル startup { wfc-timeout 120; } disk { on-io-error pass_on; } on serv111 { # uname -n device /dev/drbd0; disk /dev/sdb1; address 192.168.11.111:7788; meta-disk internal; } on serv112 { # uname -n device /dev/drbd0; disk /dev/sdb1; address 192.168.11.112:7788; meta-disk internal; } }※データ書き込みについては、ローカルディスクとリモートディスクの両方にデータを書き込んだらディスクへの書き込みが完了したと判断する、プロトコルCを利用します。 [#qf5ceca8]
- 設定項目については以下を参照して下さい。
drbd.conf
- その他の設定項目は公式サイトを参考にして下さい。
http://www.drbd.jp/users-guide/re-drbdconf.html
メタファイルの作成
- meta-diskに「internal」を指定した場合、ext3などのファイルシステムが作成されているとメタファイルの作成に失敗する事があるため、ddコマンドを利用してmeta-diskのデバイスをゼロで埋めます。
詳細は公式サイトFAQ(英文)を参照# dd if=/dev/zero bs=1M count=1 of=/dev/sdb1; sync
- メタファイルを作成します。
# drbdadm create-md r0 Writing meta data... initializing activity log NOT initialized bitmap New drbd meta data block successfully created.
自動起動の設定
- 自動起動をonに設定します
# chkconfig drbd on
- chkconfigコマンドで自動起動のonを確認します。
# chkconfig --list drbd drbd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
DRBDの起動
- もう1台のDRBDが起動していないため、最初に起動したサーバでは以下のような警告が出ますが、
yesとタイプして先に進みます。起動に成功したら、もう1台も起動します。# /etc/init.d/drbd start Starting DRBD resources: [ d(r0) ].......... *************************************************************** DRBD's startup script waits for the peer node(s) to appear. - In case this node was already a degraded cluster before the reboot the timeout is 0 seconds. [degr-wfc-timeout] - If the peer was available before the reboot the timeout will expire after 120 seconds. [wfc-timeout] (These values are for resource 'r0'; 0 sec -> wait forever) To abort waiting enter 'yes' [ 13]:yes
- 各サーバのDRBDを起動したら、以下のようにして状態を確認します。
# cat /proc/drbd version: 8.3.2 (api:88/proto:86-90) GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:02:24 0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent B r---- ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:307200000
「ro:Secondary/Secondary」の通り、起動時は両方ともセカンダリで接続されています。
プライマリ設定とデータ同期(プライマリ側のみ)
- プライマリにしたいサーバで、以下のコマンドを実行するとプライマリへの昇格とデータ同期が実施されます。
[root@serv111 ~]# drbdadm -- --overwrite-data-of-peer primary r0
- 次にデータの同期状態を以下のコマンドで確認します。
[root@serv111 ~]# /etc/init.d/drbd status drbd driver loaded OK; device status: version: 8.3.2 (api:88/proto:86-90) GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:02:24 m:res cs ro ds p mounted fstype 0:r0 SyncTarget Primary/Secondary Inconsistent/UpToDate C ... sync'ed: 73.6% (115780/431172)K
DRBDボリュームのマウント(プライマリ側のみ)
- DRBDボリュームにファイルシステムを作成後、マウントします。
[root@serv111 ~]# mke2fs -j /dev/drbd0 [root@serv111 ~]# mount -t ext3 /dev/drbd0 /data/
- ファイルシステムのマウントを確認します。
[root@serv111 ~]# /etc/init.d/drbd status drbd driver loaded OK; device status: version: 8.3.2 (api:88/proto:86-90) GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:02:24 m:res cs ro ds p mounted fstype 0:r0 Connected Primary/Secondary UpToDate/UpToDate C /data ext3
これでDRBDボリュームが利用可能になります。
DRBDの動作確認
プライマリ側で作成したテストファイルがセカンダリ側へミラーリングされる事を確認します。
- プライマリ側でテストファイルを作成後、セカンダリに降格させる。
尚、セカンダリに降格させるためには、DRBDボリュームをアンマウントさせる必要があります。[root@serv111 ~]# echo test > /data/test.txt [root@serv111 ~]# umount /data [root@serv111 ~]# drbdadm secondary r0
- セカンダリ側をプライマリに昇格させて、テストファイルを確認します。
[root@serv112 ~]# drbdadm primary r0 [root@serv112 ~]# mount -t ext3 /dev/drbd0 /data [root@serv112 ~]# cat /data/test.txt test
プライマリ側で作成したファイルが見れれば、DRBDの動作に問題はありません。
- Heartbeatと連携させるため、DRBDボリュームをアンマウントしておきます。
[root@serv112 ~]# umount /data
Heartbeatとの連携
Heartbeatのインストール
- yumでインストールします。 先にstonithをインストールしないとheartbeatのインストールに失敗する事があります。
# yum install heartbeat-stonith # yum install heartbeat
Heartbeatの設定
heartbeatの設定は特に記述がない限り、プライマリとセカンダリで全く同じ設定を行います。
準備
- heartbeatの設定で利用するファイルは以下の通りです。
ファイル名 説明 備考 /etc/ha.d/ha.cf クラスタ構成を定義するメイン設定ファイル /etc/ha.d/haresources Version1用のリソース設定ファイル Version2用のリソース設定ファイルを作成するために利用します。 /var/lib/heartbeat/crm/cib.xml Version2用のリソース設定ファイル /etc/ha.d/authkeys 認証設定ファイル - 設定ファイルはサンプルがあるのでコピーします。
# cp /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/ # cp /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/ # cp /usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d/
ha.cfの設定
- ha.cfを編集します。ほとんどの設定がコメントアウトを解除しただけです。
# vi /etc/ha.d/ha.cf crm on # Version2の設定を利用するための記述 logfile /var/log/ha-log logfacility local0 keepalive 2 deadtime 30 warntime 10 initdead 120 udpport 694 #baud 19200 # シリアルケーブル用の設定(今回は利用しない) #serial /dev/ttyS0 # シリアルケーブル用の設定(今回は利用しない) ucast eth0 192.168.11.112 #eth0 から192.168.11.112へユニキャストで確認する auto_failback on node serv111 #uname -n node serv112 #uname -n
haresourcesの設定
- 共有リソースの設定はDRBDに関する設定を一行追加します。
- 書式 [node-name resource1 resource2 ... resourceN]
- resourceの部分は「/etc/ha.d/resource.d」配下のファイル名を記載します。
- 各リソースに渡す引数は「::」で区切って記述します。
- リソースがIPADDRの場合はリソース名を省略可能です。
# vi /etc/ha.d/haresources serv111 192.168.11.113/24 drbddisk::r0 Filesystem::/dev/drbd0::/data::ext3
cib.xmlの設定
- cib.xmlをゼロから作成することは非常に困難なため、haresources2cib.pyという移行ツールを利用してharesourcesからcib.xmlを作成します。
# /usr/lib/heartbeat/haresources2cib.py /etc/ha.d/haresources
- 作成されたcib.xmlは、haresources2cib.pyのバグによりnicとcidr_netmaskの値が逆に設定されるため、修正を行います。
<nvpair id="IPaddr_192_168_11_113_attr_1" name="nic" value="24"/> ↓ 修正 <nvpair id="IPaddr_192_168_11_113_attr_1" name="cidr_netmask" value="24"/>
- 最終的なcib.xml
# vi /var/lib/heartbeat/crm/cib.xml <?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="0"/> <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-startup-fencing" name="startup-fencing" value="true"/> <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="20s"/> <nvpair id="cib-bootstrap-options-is-managed-default" name="is-managed-default" value="true"/> <nvpair id="cib-bootstrap-options-cluster-delay" name="cluster-delay" value="60s"/> <nvpair id="cib-bootstrap-options-pe-error-series-max" name="pe-error-series-max" value="-1"/> <nvpair id="cib-bootstrap-options-pe-warn-series-max" name="pe-warn-series-max" value="-1"/> <nvpair id="cib-bootstrap-options-pe-input-series-max" name="pe-input-series-max" value="-1"/> </attributes> </cluster_property_set> </crm_config> <nodes/> <resources> <group id="group_1"> <primitive class="ocf" id="IPaddr_192_168_11_113" provider="heartbeat" type="IPaddr"> <operations> <op id="IPaddr_192_168_11_113_mon" interval="5s" name="monitor" timeout="5s"/> </operations> <instance_attributes id="IPaddr_192_168_11_113_inst_attr"> <attributes> <nvpair id="IPaddr_192_168_11_113_attr_0" name="ip" value="192.168.11.113"/> <nvpair id="IPaddr_192_168_11_113_attr_1" name="cidr_netmask" value="24"/> </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="r0"/> </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="/data"/> <nvpair id="Filesystem_3_attr_2" name="fstype" value="ext3"/> </attributes> </instance_attributes> </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="serv111"/> </rule> </rsc_location> </constraints> </configuration> <status/> </cib>
authkeysの設定
- 認証の設定を行います。認証は現時点で最もセキュリティレベルの高いsha1を利用します。
# vi /etc/ha.d/authkeys auth 2 2 sha1 test
- セキュリティを確保するため、ファイルパーミッションを変更します。セカンダリ側も同様に設定します。
# chmod 600 /etc/ha.d/authkeys
Heartbeatの起動
自動起動の設定
- 自動起動をonに設定します。セカンダリ側も同様に設定します。
# chkconfig heartbeat on
Heartbeatの起動
- DRBDボリュームはHeartbeat経由でマウントされるため、起動前にアンマウントしておきます。
# umount /data
- Heartbeatを起動します。セカンダリ側も同様に起動させます。
# /etc/init.d/heartbeat start
- 各ノードがonlineになっている事を確認します。
[root@serv111 ~]# crm_mon Defaulting to one-shot mode You need to have curses available at compile time to enable console mode ============ Last updated: Sat Jan 16 12:07:04 2010 Current DC: serv112 (f8d0bc86-5b18-4211-8750-443c2d49e0d2) 2 Nodes configured. 1 Resources configured. ============ Node: serv111 (169cd449-8918-4abb-ad3c-6c7363df99ac): online Node: serv112 (f8d0bc86-5b18-4211-8750-443c2d49e0d2): online Resource Group: group_1 IPaddr_192_168_11_113 (heartbeat::ocf:IPaddr): Started serv111 drbddisk_2 (heartbeat:drbddisk): Started serv111 Filesystem_3 (heartbeat::ocf:Filesystem): Started serv111
Heartbeatの動作確認
プライマリ側のHeartbeatを停止させてフェイルオーバー、フェイルバックの動作確認を行います。
初期状態の確認
- serv111の状態を確認します。
プライマリ側のため、仮想IPが割り当てられ、DRBD領域をマウントしています。[root@serv111 ~]# ifconfig -a eth0:0 eth0:0 Link encap:Ethernet HWaddr 00:0C:29:82:38:64 inet addr:192.168.11.113 Bcast:192.168.11.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:177 Base address:0x1400 [root@serv111 ~]# /etc/init.d/drbd status drbd driver loaded OK; device status: version: 8.3.2 (api:88/proto:86-90) GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:02:24 m:res cs ro ds p mounted fstype 0:r0 Connected Primary/Secondary UpToDate/UpToDate C /data ext3 - serv112の状態を確認します。
セカンダリのため、仮想IPが割り当てられず、DRBD領域もマウントされていません。[root@serv112 ~]# ifconfig -a eth0:0 eth0:0 Link encap:Ethernet HWaddr 00:0C:29:74:23:12 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:177 Base address:0x1400 [root@serv112 ~]# /etc/init.d/drbd status drbd driver loaded OK; device status: version: 8.3.2 (api:88/proto:86-90) GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:02:24 m:res cs ro ds p mounted fstype 0:r0 Connected Secondary/Primary UpToDate/UpToDate C
フェイルオーバーの確認
- フェイルオーバーの確認をするため、serv111(プライマリ側)のheartbeatを停止させます。
[root@serv111 ~]# /etc/init.d/heartbeat stop Stopping High-Availability services: [ OK ] - serv111の状態を確認します。
Heartbeatを終了させたため、仮想IPが割り当てられず、DRBD領域もアンマウントされています。[root@serv111 ~]# ifconfig -a eth0:0 eth0:0 Link encap:Ethernet HWaddr 00:0C:29:82:38:64 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:177 Base address:0x1400 [root@serv111 ~]# /etc/init.d/drbd status drbd driver loaded OK; device status: version: 8.3.2 (api:88/proto:86-90) GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:02:24 m:res cs ro ds p mounted fstype 0:r0 Connected Secondary/Primary UpToDate/UpToDate C - serv112の状態を確認します。
serv111側でHeartbeatを終了させたため、仮想IPが割り当てられ、DRBD領域がマウントされています。[root@serv112 ~]# ifconfig -a eth0:0 eth0:0 Link encap:Ethernet HWaddr 00:0C:29:74:23:12 inet addr:192.168.11.113 Bcast:192.168.11.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 Interrupt:177 Base address:0x1400 [root@serv112 ~]# /etc/init.d/drbd status drbd driver loaded OK; device status: version: 8.3.2 (api:88/proto:86-90) GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:02:24 m:res cs ro ds p mounted fstype 0:r0 Connected Primary/Secondary UpToDate/UpToDate C /data ext3
フェイルバックの確認
- serv111側で停止させたHeartbeatを起動させてフェイルバックの確認を行います。
[root@serv111 ~]# /etc/init.d/heartbeat start [root@serv111 ~]# /etc/init.d/drbd status drbd driver loaded OK; device status: version: 8.3.2 (api:88/proto:86-90) GIT-hash: dd7985327f146f33b86d4bff5ca8c94234ce840e build by mockbuild@v20z-x86-64.home.local, 2009-08-29 14:02:24 m:res cs ro ds p mounted fstype 0:r0 Connected Primary/Secondary UpToDate/UpToDate C /data ext3
Heartbeatの追加パッケージ
hb-monitor
heartbeat追加パッケージで、クラスタ状況をより詳細に表示する機能
インストール
# yum install libtool-ltdl # wget "http://sourceforge.jp/frs/redir.php?m=osdn&f=%2Flinux-ha%2F44519%2Fhb-monitor-1.01-1.i386.rpm" # rpm -ivh hb-monitor-1.01-1.i386.rpm
使用例
- 拡張情報を含め、ノード単位で1秒毎に繰り返し表示する場合
# hb_monitor -e -i 1 -n
FAQ
メタファイル作成時にエラーが表示される
- Q.
メタファイル作成時に下記のようなエラーが表示されてメタファイルが作成できない。# drbdadm create-md r0 md_offset 2146758656 al_offset 2146725888 bm_offset 2146660352 Found ext3 filesystem which uses 2096448 kB current configuration leaves usable 2096348 kB Device size would be truncated, which would corrupt data and result in 'access beyond end of device' errors. You need to either * use external meta data (recommended) * shrink that filesystem first * zero out the device (destroy the filesystem) Operation refused. Command 'drbdmeta 0 v08 /dev/sdb1 internal create-md' terminated with exit code 40 drbdadm create-md r0: exited with code 40
- A.
ext3などのファイルシステムが作成されているとmetaファイルの作成に失敗する事があります。
その場合はddコマンドを利用してmeta-diskのデバイスをゼロで埋めた後でメタファイルを作成して下さい。# dd if=/dev/zero bs=1M count=1 of=/dev/sdb1; sync # drbdadm create-md r0
DRBDが起動しない
- Q.
DRBDを起動すると下記エラーが出て起動できない。# /etc/init.d/drbd start Starting DRBD resources: Can not load the drbd module.
- A.
DRBDのモジュールがインストールされていない可能性があります。
下記の通りインストールしてください。# yum install kmod-drbd83
参考
- DRBD日本語サイト
http://www.drbd.jp/index.html
