Edited at

CentOS6.7上でのDRBD構築メモ

More than 3 years have passed since last update.


環境

CentOS6.5

vm1: 192.168.50

vm2: 192.168.52

* 検証環境のためNICは一本


drbdのインストール

こちらでお好きなrpmを選択

http://ftp.kddilabs.jp/Linux/RPMS/elrepo/elrepo/el6/x86_64/RPMS/

今回は

drbd84-utils-8.9.2-1.el6.elrepo.x86_64.rpm

kmod-drbd84-8.4.6-1.el6.elrepo.x86_64.rpm

を選択

cd /tmp

wget http://ftp.kddilabs.jp/Linux/RPMS/elrepo/elrepo/el6/x86_64/RPMS/drbd84-utils-8.9.2-1.el6.elrepo.x86_64.rpm
wget http://ftp.kddilabs.jp/Linux/RPMS/elrepo/elrepo/el6/x86_64/RPMS/kmod-drbd84-8.4.6-1.el6.elrepo.x86_64.rpm
rpm -ivh *drbd*.rpm


hosts

#cat /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.1.50 vm1
192.168.1.52 vm2


その他事前準備


iptables,selinuxの無効化

service iptables stop

chkconfig iptables off

cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted

設定を反省させるために再起動


設定ファイルの編集


global_common.conf

# cat /etc/drbd.d/global_common.conf

global {
usage-count no;
}

common {
handlers {

}

startup {
}

options {
}

disk {
resync-rate 50M;
}

net {
protocol C;
csums-alg sha1;
verify-alg sha1;
}
}


r0.res

#cat /etc/drbd.d/r0.res

resource r0 {
meta-disk internal;
device /dev/drbd0;
disk /dev/sdb1;

on vm1 {
address 192.168.1.50:7788;
}
on vm2 {
address 192.168.1.52:7788;
}
}


仮想ディスクの追加

今回はESXi上でvm1/vm2に対して、新規仮想ディスクを追加


ディスクの認識(vmを再起動しない場合)

for i in $(find /sys/class/scsi_host -name 'scan') $(find /sys/devices -name 'scan') ;do echo "- - -" > $i ; done

認識されていることを確認

fdisk -l /dev/sdb

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


partitionの作成

fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xef042cab.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610):
Using default value 2610

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xef042cab

Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 83 Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


meta dataの作成

drbdadm create-md r0

initializing activity log
NOT initializing bitmap
Writing meta data...
New drbd meta data block successfully created.


serviceの起動

chkconfig drbd on

service drbd start
Starting DRBD resources: [
create res: r0 r1
prepare disk: r0 r1
adjust disk: r0 r1
adjust net: r0 r1
]
WARN: nothing stacked for this host (xxx), nothing to do in stacked mode!


  • WARNは無視してOKです


primaryの昇格(primary側でのみ実行)

#drbdadm -- --overwrite-data-of-peer primary r0

同期が始まることを確認
#cat /proc/drbd
version: 8.4.6 (api:1/proto:86-101)
GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R6, 2015-04-09 14:35:00
0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
ns:11597 nr:0 dw:10573 dr:5343023 al:7 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:11402368
[=====>..............] sync'ed: 32.0% (11132/16360)M
finish: 0:05:12 speed: 36,444 (38,504) K/sec


フォーマット

#mkfs.xfs /dev/drbd0

mkfs.xfs: /dev/drbd0 appears to contain an existing filesystem (xfs).
mkfs.xfs: Use the -f option to force overwrite.
# mkfs.xfs -f /dev/drbd0
meta-data=/dev/drbd0 isize=256 agcount=4, agsize=1310258 blks
= sectsz=512 attr=2, projid32bit=0
data = bsize=4096 blocks=5241029, 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


動作確認

# mount /dev/drbd0 /mnt

# echo "test" > /mnt/test.txt
# cat /mnt/test.txt
test
# umount /dev/drbd0


操作一覧


Primary => secondary 降格

/dev/drbd0をマウントしている場合は、アンマウントする必要があります。

#drbdadm secondary r0


Secondary -> Primary 昇格

drbdadm primary r0

mount /dev/drbd0 /mnt
元secondary側でmountできることを確認する

あとはheartbeatと連携させる