http://www.drbd.org/docs/about/
http://oss.linbit.com/drbd/
安装drbd
# wget http://oss.linbit.com/drbd/8.4/drbd-8.4.3.tar.gz
# tar zxvf drbd-8.4.3.tar.gz
# cd drbd-8.4.3
# ./configure --prefix=/usr/local/drbd --with-km
# make KDIR=/usr/src/kernels/2.6.32-279.el6.x86_64/
yum -y install kernel-devel kernel-headers flex
注意:安装kernel-devel一定要和你uname -r 看到的内核版本一致,建议kernel-devel用本地源安装,不要用网络源安装
[root@node1 soft]# tar zxf drbd-8.4.3.tar.gz
[root@node1 soft]# cd drbd-8.4.3
[root@node1 drbd-8.4.3]# ./configure --prefix=/usr/local/drbd --with-km
注意:--with-km是启用内核模块
[root@node1 ~]# make KDIR=/usr/src/kernels/2.6.32-358.el6.i686
注意KDIR的路径 (这个内核源码路径需要根据自己的系统修改)
[root@node1 drbd-8.4.3]# make install
[root@node1 ~]# mkdir -p /usr/local/drbd/var/run/drbd
[root@node1 ~]# cp /usr/local/drbd/etc/rc.d/init.d/drbd /etc/rc.d/init.d/
[root@node1 ~]# chkconfig --add drbd
[root@node1 ~]# chkconfig drbd on
安装drbd模块
回到刚刚解压drbd的目录,然后
[root@node1 drbd-8.4.3]# cd drbd
[root@node1 drbd]# make clean
[root@node1drbd]# make KDIR=/usr/src/kernels/2.6.32-358.el6.i686
[root@node1 drbd]# cp drbd.ko /lib/modules/`uname -r`/kernel/lib/
[root@node1 drbd]# modprobe drbd
查看模块是否加载成功
[root@node1 drbd]# lsmod | grep drbd
drbd 292307 0
先看看系统的内核版本
# uname -r (目前的版本)
2.6.32-279.el6.x86_64
下面以安装drbd模块为例进行说明
正确安装drbd模块后,使用modprobe进行加载
# modprobe drbd
FATAL: Module drbd not found.
出现如上错误
原因:这是因为系统默认的内核并不支持此模块,所以需要更新内核
更新内核的方法:
可以用 yum install kernel* 方式来更新。
如果你要节约点时间的话可以只更新一下的几个包:
kernel-devel
kernel
kernel-headers
更新后,记得要重新启动操作系统!!!
# depmod
说明:在编译并准备好一个Linux内核加载模块后,modprobe前必须先执行命令depmod,此命令会生成新的modules.dep。
[root@bd2 ~]# depmod
[root@bd2 ~]# modprobe drbd
[root@bd2 ~]# lsmod|grep drbd
drbd 325786 0
libcrc32c 1246 1 drbd
编辑配文
[root@bd2 ~]# vi /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 30M;}
on bd1{
device /dev/drbd0;
disk /dev/sdb1;
address 172.16.2.1:7788;
meta-disk internal;
}
on bd2{
device /dev/drbd0;
disk /dev/sdb1;
address 172.16.2.2:7788;
meta-disk internal;
}
}
创建分区
# fdisk /dev/sdb
----------------
n-p-1-1-"+1G"-w
----------------
# mkdir /data
创建DRBD设备并激活ro资源:(Primary,Secondary)
# mknod /dev/drbd0 b 147 0
# drbdadm create-md r0
等待片刻,显示success表示drbd块创建成功
--== Thank you for participating in the global usage survey ==--
The server's response is:
you are the 19411th user to install this version
no resources defined!
因为配文错误应该是下面的位置,而不是/etc/drbd.conf
[root@bd2 ~]# vi /usr/local/drbd/etc/drbd.conf
[root@bd2 ~]# drbdadm create-md r0
Writing meta data...
initializing activity log
NOT initializing bitmap
New drbd meta data block successfully created.
success
命令汇总
[root@bd2 ~]# fdisk /dev/sdb
[root@bd2 ~]# mkdir /data
[root@bd2 ~]# depmod
[root@bd2 ~]# modprobe drbd
[root@bd2 ~]# lsmod |grep drbd
[root@bd2 ~]# mknod /dev/drbd0 b 147 0
[root@bd2 ~]# drbdadm create-md r0
[root@bd1 ~]# service drbd start
[root@bd2 ~]# drbdadm -- --overwrite-data-of-peer primary r0
[root@bd2 ~]# ps -ef|grep drbd
root 1405 2 0 Aug11 ? 00:00:00 [drbd-reissue]
root 1410 2 0 Aug11 ? 00:00:00 [drbd_submit]
root 1417 2 0 Aug11 ? 00:00:52 [drbd_w_r0]
root 1421 2 0 Aug11 ? 00:00:52 [drbd_r_r0]
root 1426 2 0 Aug11 ? 00:00:01 [drbd_a_r0]
root 1753 1692 0 12:02 pts/0 00:00:00 grep drbd
[root@bd1 ~]# netstat -anput |grep 7788
tcp 0 40 172.16.2.1:7788 172.16.2.2:48538 ESTABLISHED -
tcp 0 80 172.16.2.1:7788 172.16.2.2:53019 ESTABLISHED -
[root@bd1 ~]# drbdadm cstate r0
Connected
[root@bd1 ~]# drbdadm dstate r0
UpToDate/UpToDate
[root@bd1 ~]# drbdadm role r0
Secondary/Primary
[root@bd1 ~]# drbd-overview
0:r0 cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r-----
[root@bd2 ~]# service drbd status
drbd driver loaded OK; device status:
version: 8.4.3 (api:1/proto:86-101)
GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@bd2, 2014-08-11 14:53:29
m:res cs ro ds p mounted fstype
0:r0 SyncSource Primary/Secondary UpToDate/Inconsistent C
... sync'ed: 90.0% (1648/16376)M
[root@bd1 ~]# cat /proc/drbd
version: 8.4.3 (api:1/proto:86-101)
GIT-hash: 89a294209144b68adb3ee85a73221f964d3ee515 build by root@bd2, 2014-08-11 14:53:29
0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r---n-
ns:15643840 nr:0 dw:0 dr:15645336 al:0 bm:954 lo:0 pe:3 ua:1 ap:0 ep:1 wo:f oos:1129680
[=================>..] sync'ed: 93.3% (1100/16376)M
finish: 0:01:35 speed: 11,824 (11,492) K/sec
第一次数据同步完成之后,就可以创建文件系统并挂载使用了,只能挂primary,备机只能接收主机数据
[root@bd2 ~]# mkfs.ext3 /dev/drbd0
[root@bd2 /]# mount /dev/drbd0 /data/