DRBDは2台で設定を実施しますので、2台それぞれでの設定が必要になります。
【DRBDのインストール】
※ 以下の手順は2台ともに実施します。
[html]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[/html]
[html]
# cd /usr/local/src
[/html]
キーのインストール
[html]# rpm –import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
[/html]
レポジトリの追加
[html]# rpm -Uvh http://www.elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
[/html]
通常は利用しないので、以下の設定をしておきます。
[html]# vi /etc/yum.repos.d/elrepo.repo
[elrepo]
name=ELRepo.org Community Enterprise Linux Repository – el6
baseurl=http://elrepo.org/linux/elrepo/el6/$basearch/
http://mirrors.coreix.net/elrepo/elrepo/el6/$basearch/
http://jur-linux.org/download/elrepo/elrepo/el6/$basearch/
http://repos.lax-noc.com/elrepo/elrepo/el6/$basearch/
http://mirror.ventraip.net.au/elrepo/elrepo/el6/$basearch/
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo.el6
#enabled=1
enabled=0 # 通常利用しないので、0。
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
protect=0
[/html]
【DRBDをelrepoからインストール】
※ 以下は2台ともに実施します。
[html]
# yum –enablerepo=elrepo install drbd83-utils kmod-drbd83
略
Installed:
drbd83-utils.x86_64 0:8.3.16-1.el6.elrepo kmod-drbd83.x86_64 0:8.3.16-1.el6.elrepo
Dependency Installed:
perl.x86_64 4:5.10.1-136.el6 perl-Module-Pluggable.x86_64 1:3.90-136.el6 perl-Pod-Escapes.x86_64 1:1.04-136.el6
perl-Pod-Simple.x86_64 1:3.13-136.el6 perl-libs.x86_64 4:5.10.1-136.el6 perl-version.x86_64 3:0.77-136.el6
Complete!
[/html]
このようにインストールが完了します。
【不要サービス停止】
※ 以下は2台ともに実施します。
不用意に停止させる必要はありませんが、必要もない場合は問題の元ですので、停止させましょう。
とくにSElinuxは、場合によってパーミッションエラーを起こしたりします。
・iptables停止
[html]# /etc/init.d/iptables stop
[/html]
自動起動も停止
[html]# chkconfig iptables off
[/html]
・SElinux停止
[html]
動的に停止
# setenforce 0
静的に停止
# vi /etc/sysconfig/selinux
SELINUX=disabled に変更。
ここで再起動もしておくとよし。
[/html]
【DRBDの初期設定】
※ 以下は2台ともに実施します。
オリジナルの保存
[html]# cp -rp /etc/drbd.conf /etc/drbd.conf.org
[/html]
設定ファイルを編集します。
[html]# vi /etc/drbd.conf
global { usage-count yes; }
common { syncer { rate 20M; } }
resource drbd0 { protocol C;
disk { on-io-error detach; }
net { max-buffers 1600; }
on ip-172-xx-xx-1 { device /dev/drbd0; disk /dev/xvdf;
address 172.30.17.4:7788; meta-disk internal; }
on ip-172-xx-xx-2 { device /dev/drbd0; disk /dev/xvdf;
address 172.30.17.5:7788; meta-disk internal; }
}
[/html]
今回は「meta-disk」をinternalの設定にしています。
それぞれの設定値については、、記事の最後にある参照のURLを参考にしてください。
モジュールの読み込み
[html]# modprobe drbd[/html]
※ これをしていないと、メタデータの作成でエラーになります。
メタデータの作成
[html]# drbdadm create-md drbd0
md_offset 8589930496
al_offset 8589897728
bm_offset 8589635584
Found some data
==> This might destroy existing data! <==
Do you want to proceed?
[need to type ‘yes’ to confirm] yes
Writing meta data…
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
success
[/html]
出来ました。
[html]
# drbdadm adjust drbd0
[/html]
[html]
# cat /proc/drbd
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2013-09-27 16:00:43
0: cs:WFConnection ro:Secondary/Unknown ds:Inconsistent/DUnknown C r—-s
ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:8388316
[/html]
まだ片方しか出来ていないので、Secondary/Unknownになっています。
ここまでをもう片方でも実行します。
【自動起動確認】
※ 以下は2台ともに実施します。
[html]
# chkconfig –list drbd
drbd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[/html]
自動起動になってますね。
【初回同期をしてみる】
まずは、同期をしていない現状での状態です。
1台目
[html]
# /etc/init.d/drbd status
drbd driver loaded OK; device status:
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2013-09-27 16:00:43
m:res cs ro ds p mounted fstype
0:drbd0 WFConnection Secondary/Unknown Inconsistent/DUnknown C
[/html]
2台目
[html]
# /etc/init.d/drbd status
drbd driver loaded OK; device status:
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2013-09-27 16:00:43
m:res cs ro ds p mounted fstype
0:drbd0 WFConnection Secondary/Unknown Inconsistent/DUnknown C
[/html]
では、初期同期をしてみます。
[html]
# drbdadm — –overwrite-data-of-peer primary resource
‘resource’ not defined in your config.
[/html]
リソースをリソース名にしました。
[html]
# drbdadm — –overwrite-data-of-peer primary drbd0
[/html]
エラーは出さない。
[html]
# watch cat /proc/drbd
Every 2.0s: cat /proc/drbd Wed Aug 6 00:40:44 2014
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2013-09-27 16:00:43
0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r—–
ns:619008 nr:0 dw:0 dr:619672 al:0 bm:37 lo:6 pe:0 ua:6 ap:0 ep:1 wo:f oos:7769308
[>……………….] sync’ed: 7.5% (7584/8188)M
finish: 0:14:34 speed: 8,872 (9,520) K/sec
[/html]
こんな感じで同期の状況が確認できます。
ちなみに、secandary側も同様に同期の状況が確認できます。
同期が完了すると、以下のように表示されて
[html]
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2013-09-27 16:00:43
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r—–
ns:8388316 nr:0 dw:0 dr:8388980 al:0 bm:512 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[/html]
「Primary/Secondary」 という表示が見て取れます。
drbdの初期設定までできました。次からファイルシステムを設定してマウントまで進めます。
ここからは、
http://dev.classmethod.jp/cloud/amazon-linux-drbd/
を参照します。
ちなみに、drbdを停止してみる。
すると、プライマリ設定は外れて、Secondary/Secondary となる。
重要なのは、プライマリに昇格してからじゃないと、マウントしてはいけないということ。
[html]
# drbdadm — –overwrite-data-of-peer primary drbd0
[/html]
xfsファオーマットにして利用する。 ※ xfsは大容量データファイルの扱いに適している。
こちらも参考 http://www.e-agency.co.jp/column/20121107.html
[html]
# yum install xfs*
[/html]
これは、プライマリ側で実行
[html]# mkfs.xfs /dev/drbd0
meta-data=/dev/drbd0 isize=256 agcount=4, agsize=524270 blks
= sectsz=512 attr=2, projid32bit=0
data = bsize=4096 blocks=2097079, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[/html]
ちなみに、これをsecondary側で実行すると、
[html]# mkfs.xfs /dev/drbd0
mkfs.xfs: cannot open /dev/drbd0: Read-only file system
[/html]
とエラーになる。
マウントする。これもプライマリ側でしか実行できない。
[html]
$ sudo mkdir /data
$ sudo mount /dev/drbd0 /data
[/html]
次での検証のために、/data配下にファイルをおいておく。
[html]# ls /data
hello.txt
[/html]
【セカンダリを昇格させる】
セカンダリをプライマリへ昇格させて、もう片方のインスタンスにデータが同期されているか確認します。まずは、プライマリのデバイスをアンマウントしてセカンダリへ降格させます。
プライマリのデバイスをアンマウント
[html]$ sudo umount /data
[/html]
[html]# drbdadm secondary drbd0
# service drbd status
drbd driver loaded OK; device status:
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2013-09-27 16:00:43
m:res cs ro ds p mounted fstype
0:drbd0 Connected Secondary/Secondary UpToDate/UpToDate C
[/html]
プライマリ/セカンダリだったものが、セカンダリ/セカンダリになりました。
次にもう片方のインスタンスから以下のコマンドでプライマリへ昇格させます。
[html]
# cat /proc/drbd
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2013-09-27 16:00:43
0: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r—–
ns:0 nr:12642 dw:12642 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[/html]
[html]# drbdadm primary drbd0
[/html]
[html]# cat /proc/drbd
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by phil@Build64R6, 2013-09-27 16:00:43
0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r—–
ns:0 nr:12642 dw:12642 dr:664 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
[/html]
[html]
# mount /dev/drbd0 /data
[/html]
データの確認
[html]
# ls /data
hello.txt
[/html]
【参考】
How to Install DRBD on CentOs 6.2 | Learn Basics of Linux OS, commands, tutorials, Linux server administration, free linux training, mail server, dhcp, dns (bind)
http://www.broexperts.com/2012/06/how-to-install-drbd-on-centos-6-2/
Amazon LinuxでDRBD 8.3.11を構築する | Developers.IO
http://dev.classmethod.jp/cloud/amazon-linux-drbd/
DRBD+heartbeat+LVM(on Fedora Core10)によるクラスタリング : アシアルブログ
http://blog.asial.co.jp/599