全部博文(389)
分类: LINUX
2014-08-13 11:02:29
DRBD部署实践
DRBD作为廉价的存储级别复制方案,在很多场合被使用,比如Mysql HA,使用DRBD比较多
环境: rhel 5.8,使用相同的ntp服务器同步时间(这一步很重要)
dg1 192.168.245.101
dg1 192.168.245.102
以下两台服务器都需要安装
[root@dg1 ~]# rpm -Uvh drbd83-8.3.15-2.el5.centos.x86_64.rpm
warning: drbd83-8.3.15-2.el5.centos.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID e8562897
Preparing... ########################################### [100%]
1:drbd83 ########################################### [100%]
[root@dg1 ~]# rpm -Uvh kmod-drbd83-8.3.15-3.el5.centos.x86_64.rpm
warning: kmod-drbd83-8.3.15-3.el5.centos.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID e8562897
Preparing... ########################################### [100%]
1:kmod-drbd83 ########################################### [100%]
[root@dg1 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 7832 62910508+ 83 Linux
查看drbd内核模块是否已经被加载
[root@dg1 ~]# lsmod | grep drbd
[root@dg1 ~]# modprobe drbd
[root@dg1 ~]# lsmod | grep drbd
drbd 321608 0
定义配置文件/etc/drbd.conf
resource r0{
protocol C;
startup { wfc-timeout 0; degr-wfc-timeout 120;}
disk { on-io-error detach;}
net{
timeout 60;
connect-int 10;
ping-int 10;
max-buffers 2048;
max-epoch-size 2048;
}
syncer { rate 50M;} --同步速度
on dg1{
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.245.101:7788;
meta-disk internal;
}
on dg2{
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.245.102:7788
meta-disk internal;
}
}
创建drbd设备
[root@dg1 ~]# drbdadm create-md r0
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
--== Creating metadata ==--
As with nodes, we count the total number of devices mirrored by DRBD
at .
The counter works anonymously. It creates a random number to identify
the device and sends that random number, along with the kernel and
DRBD version, to usage.drbd.org.
* If you wish to opt out entirely, simply enter 'no'.
* To continue, just press [RETURN]
yes
再次创建
[root@dg1 ~]# drbdadm create-md r0
You want me to create a v08 style flexible-size internal meta data block.
There appears to be a v08 flexible-size internal meta data block
already in place on /dev/sdb1 at byte offset 10733953024
Do you really want to overwrite the existing v08 meta-data?
[need to type 'yes' to confirm] yes
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
启动drbd服务
[root@dg1 ~]# service drbd start
Starting DRBD resources: [ d(r0) ].......
[root@dg1 ~]# service drbd status
drbd driver loaded OK; device status:
version: 8.3.15 (api:88/proto:86-97)
GIT-hash: 0ce4d235fc02b5c53c1c52c53433d11a694eab8c build by , 2013-03-27 16:01:26
m:res cs ro ds p mounted fstype
0:r0 Connected Secondary/Secondary Inconsistent/Inconsistent C
设置主设备,主设备就是当前正在使用的设备,
[root@dg1 ~]# drbdsetup /dev/drbd0 primary --force
[root@dg1 ~]# service drbd status
drbd driver loaded OK; device status:
version: 8.3.15 (api:88/proto:86-97)
GIT-hash: 0ce4d235fc02b5c53c1c52c53433d11a694eab8c build by , 2013-03-27 16:01:26
m:res cs ro ds p mounted fstype
... sync'ed: 1.0% (10144/10236)M
0:r0 SyncSource Primary/Secondary UpToDate/Inconsistent C
[root@dg1 ~]#
当前正在同步,ro为1.0%,所以第二个设备状态是Inconsistent
[root@dg1 ~]# service drbd status
drbd driver loaded OK; device status:
version: 8.3.15 (api:88/proto:86-97)
GIT-hash: 0ce4d235fc02b5c53c1c52c53433d11a694eab8c build by , 2013-03-27 16:01:26
m:res cs ro ds p mounted fstype
0:r0 Connected Primary/Secondary UpToDate/UpToDate C
稍过一段时间,再次查看,发现两边的设备已经同步完成了.接下来就是格式化和挂载了.