DRBD
DRBD是一种块设备,可以被用于高可用(HA)之中.它类似于一个网络RAID-1功能。当你将数据写入本地文件系统时,数据还将会被发送到网络中另一台主机上.以相同的形式记录在一个文件系统中。本地(主节点)与远程主机(备节点)的数据可以保证实时同步.当本地系统出现故障时,远程主机上还会保留有一份相同的数据,可以继续使用。
在高可用(HA)中使用DRBD功能,可以代替使用一个共享盘阵.因为数据同时存在于本地主机和远程主机上,切换时,远程主机只要使用它上面的那份备份数据,就可以继续进行服务了。
DRBD试用
安装:yum install drbd83 kmod-drbd83 kmod-drbd83-xen
资源准备:
[root@localhost ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created
[root@localhost ~]# vgcreate virvg /dev/sda3
Volume group "virvg" successfully created
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
virvg 1 0 0 wz--n- 45.00G 45.00G
[root@localhost ~]# lvcreate -L 2G -n lv1 virvg
Logical volume "lv1" created
网络配置:
vim /etc/sysconfig/network
HOSTNAME=node1.local
vim /etc/hosts
192.168.14.215 node2.local node2
192.168.19.13 node1.local node1
# /etc/init.d/network restart
# uname -n
node1.local
配置drbd:
vim /etc/drbd.conf:
include "/etc/drbd.d/global_common.conf";
include "/etc/drbd.d/*.res";
# cat /etc/drbd.d/lv1.res
resource lv1 {
device /dev/drbd1;
disk /dev/virvg/lv1;
meta-disk internal;
on node2.local {
address 192.168.14.215:7789;
}
on node1.local {
address 192.168.19.13:7789;
}
}
创建设备:#drbdadm create-md lv1
#/etc/init.d/drbd start
#drbdadm up lv1
[root@localhost ~]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by
[email protected], 2010-06-04 08:04:27
1: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C 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:2097052
设置一个为主设备:
# drbdsetup /dev/drbd1 primary -o
# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by
[email protected], 2010-06-04 08:04:27
1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r----
ns:17056 nr:0 dw:0 dr:17056 al:0 bm:1 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:2079996
[>....................] sync'ed: 1.0% (2079996/2097052)K delay_probe: 5
finish: 0:57:46 speed: 464 (320) K/sec
可以看到开始进行数据同步了。
主备机切换
主机上执行:drbdadm secondary lv1
备机上执行:drbdadm primary lv1
问题1:Found ext3 filesystem which uses 2097112 kB
[root@s0 ~]# drbdadm create-md r0
md_offset 2147438592
al_offset 2147405824
bm_offset 2147340288
Found ext3 filesystem which uses 2097112 kB
current configuration leaves usable 2097012 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 /dev/drbd1 v08 /dev/hdb1 internal create-md' terminated with exit code 40 drbdadm aborting
在对DRBD磁盘初始化之前将分区进行了ext3格式化,此处应该只分区不格式化。重新分区即可。
问题2:Starting DRBD resources: Can not load the drbd module
没有安装kmod-drbd,这是内核模块,必须安装。
问题3:如何实现主主模式
修改配置文件:(两台机器都需要)
resource <resource>
net {
allow-two-primaries;
}
...
}
修改完后执行:
Run drbdadm disconnect resource on both nodes.
Execute drbdadm connect resource on both nodes.
Finally, you may now execute drbdadm primary resource on both nodes, instead of on just one.
临时方法:drbdadm net-options --protocol=C --allow-two-primaries <resource>
增加下面的选项可以在开机时就进入primary模式:
resource <resource>
startup {
become-primary-on both;
}
...
}
注意:
缺省的最大同步带宽(sync-max)为 250KB/sec
作者:feiskyer 发表于2011-12-25 18:36:50
原文链接