Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
[iyunv@heartbeat01 ~]# fdisk -cu /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x198bc436.
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)
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders, total 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x198bc436
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First sector (2048-4194303, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-4194303, default 4194303):
Using default value 4194303
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
4、编辑drbd配置文件
根据drbd的官方文档,drbd的配置文件是/etc/drbd.conf,但是这个文件中只有简单的2行内容,它引用了/etc/drbd.d/下的global_common.conf和*.res文件,这点和nginx、apache的配置文件类似,我们可以把多个resource相同的定义放到global中去,然后添加不同的res文件,从而更有效和方便的管理drbd的配置文件。
下面是/etc/drbd.conf的默认配置:
[iyunv@heartbeat01 ~]# egrep -v "#|^$" /etc/drbd.conf
include "drbd.d/global_common.conf";
include "drbd.d/*.res";
下面是/etc/drbd.d/global_common.conf的默认配置:
[iyunv@heartbeat01 ~]# egrep -v "#|^$" /etc/drbd.d/global_common.conf
global {
usage-count yes;
}
common {
protocol C;
handlers {
}
startup {
}
disk {
}
net {
}
syncer {
}
}
下面是我新建的一个配置文件test.res的内容:
resource test
{
startup {
wfc-timeout 30;
outdated-wfc-timeout 20;
degr-wfc-timeout 30;
}
net {
cram-hmac-alg sha1;
shared-secret sync_disk;
}
syncer {
rate 10M;
al-extents 257;
on-no-data-accessible io-error;
}
on heartbeat01.contoso.com {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.49.133:7788;
flexible-meta-disk internal;
}
on heartbeat02.contoso.com {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.49.134:7788;
meta-disk internal;
}
}
然后可以将此配置文件使用scp拷贝到节点2上去,两边的配置文件需要保持一致。
[iyunv@heartbeat01 drbd.d]# scp test.res heartbeat02:/etc/drbd.d/
The authenticity of host 'heartbeat02 (192.168.49.134)' can't be established.
RSA key fingerprint is f9:ce:14:5d:cd:bb:3c:b4:0d:0b:fc:21:3a:92:43:6b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'heartbeat02,192.168.49.134' (RSA) to the list of known hosts.
root@heartbeat02's password:
test.res 100% 444 0.4KB/s 00:00
5、启动drbd
1
2
drbdadm create-md clusterdb #初始化metadata数据存储
service drbd start #启动drbd服务
上面的操作需要到两台server上运行,这里以其中一台为例演示结果:
[iyunv@heartbeat01 drbd.d]# drbdadm create-md test
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
success
[iyunv@heartbeat01 drbd.d]# service drbd start
Starting DRBD resources: [ d(test) s(test) n(test) ]..........
***************************************************************
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 30 seconds. [degr-wfc-timeout]
- If the peer was available before the reboot the timeout will
expire after 30 seconds. [wfc-timeout]
(These values are for resource 'test'; 0 sec -> wait forever)
To abort waiting enter 'yes' [ 11]:
.
这里给出很多信息,大多是因为对端节点并没有启动,所以配置文件中的等待时间生效,但是在节点1启动后,我们再启动节点2时的信息就没有这么多了,因为节点1已经启动,所以无须等待。