环境:hostname        ip

         db1         192.168.0.122

         db2         192.168.0.123

centos 6.5

uname -r   2.6.32-431.el6.x86_64(两台系统一样)

两台主机个添加一块硬盘,分区为/dev/sdb1

关闭防火墙与selinux

两台主机同样配置:

[root@db1 ~]# vi /etc/hosts

192.168.0.122 db1

192.168.0.123 db2

安装配置:
[root@db1 src]# tar zxf drbd-8.4.2.tar.gz 

[root@db1 src]# cd drbd-8.4.2

[[email protected]]# ./configure --prefix=/usr/local/drbd --with-km

报错:

checkingfor dpkg-buildpackage... no

checkingfor udevadm... /sbin/udevadm

checkingfor udevinfo... false

configure:error: Cannot build utils without flex, either install flex or pass the--without-utils option.

解决:

[root@db1src]# tar zxf flex-2.5.35.tar.gz 

[root@db1src]# cd flex-2.5.35

[[email protected]]# ./configure --prefix=/usr

[[email protected]]# make  && make install

[[email protected]]# cd /usr/local/src/drbd-8.4.2

[[email protected]]# uname -r

2.6.32-431.el6.x86_64

[[email protected]]# make KDIR=/usr/src/kernels/2.6.32-431.el6.x86_64

报错:

make: ***[check-kdir] Error 1

解决:

[root@db1 src]#yum install -y kernel-devel(可能安装的和系统版本不符,我这边是下载的rpm包)

[root@db1src]# rpm -ivh kernel-devel-2.6.32-431.el6.x86_64.rpm

[root@db1 drbd-8.4.2]# make install

[[email protected]]# cp /usr/local/drbd/etc/rc.d/init.d/drbd /etc/rc.d/init.d/

[[email protected]]# chkconfig --add drbd

[[email protected]]# chkconfig drbd on

 

[[email protected]]# cd  drbd

[root@db1drbd]# pwd

/usr/local/src/drbd-8.4.2/drbd

[root@db1drbd]# make clean

[root@db1drbd]# make KDIR=/usr/src/kernels/2.6.32-431.el6.x86_64/

[root@db1drbd]# cp drbd.ko /lib/modules/2.6.32-431.el6.x86_64/kernel/lib/

[root@db1drbd]# depmod #创建模块依赖关系的列表

[root@db1drbd]# cd /usr/local/drbd/etc/drbd.d/

[[email protected]]#mv global_common.conf global_common.conf.old

[[email protected]]#vi global_common.conf

global {

 usage-count yes;

}

common {

  net{

   protocol C;

  }

}

[[email protected]]#vi r0.res

resource r0{

       on db1{

               device         /dev/drbd1;

               disk           /dev/sdb1;

               address        192.168.0.122:7788;

               meta-disk      internal;

       }

       on db2{

               device         /dev/drbd1;

               disk           /dev/sdb1;

               address        192.168.0.123:7788;

               meta-disk      internal;

       }

}

说明:

device    是自定义的物理设备的逻辑路径

disk      是磁盘设备,或者是逻辑分区

address   是机器监听地址和端口

meta-disk 这个不是很清楚,

建立resource,初始化:

[[email protected]]# modprobe drbd    #载入模块

[[email protected]]# lsmod | grep drbd   #确认模块是否载入

drbd                 314438  0 

libcrc32c              1246  1 drbd

[root@db1 drbd.d]#ddif=/dev/zero of=/dev/sdb1 bs=1M count=100

[[email protected]]#drbdadm create-md r0  建立 drbd resource,此命令后有交互,键入yes即可

[[email protected]]#drbdadm up r0   启动drbd,也可以/etc/init.d/drbdstart

/usr/local/drbd/var/run/drbd:No such file or directory

/usr/local/drbd/var/run/drbd:No such file or directory

报没有这些目录

[[email protected]]# mkdir -p/usr/local/drbd/var/run/drbd  建立这些目录

再[[email protected]]#drbdadm up r0

[[email protected]]# cat /proc/drbd  查看状态信息

version:8.4.2 (api:1/proto:86-101)

GIT-hash:7ad5f850d711223713d6dcadc3dd48860321070c build by [email protected],2012-09-29 15:21:32

 

 1:cs:WFConnection ro:Secondary/Unknown ds:Inconsistent/DUnknown C r----s

   ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:1044124

 

以上的这些操作也要在db2执行一次,保持各个配置文件的相同。

 

设置primary node:

将db1设置成主服务

[[email protected]]# drbdadm primary --forcer0

[[email protected]]# cat /proc/drbd       状态已改变       

version:8.4.2 (api:1/proto:86-101)

GIT-hash:7ad5f850d711223713d6dcadc3dd48860321070c build by [email protected],2012-09-29 15:21:32

 

 1:cs:Connected ro:Primary/Secondary ds:UpToDate/Diskless C r-----

   ns:0 nr:0 dw:0 dr:672 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:foos:1044124

在db1上创建drbd文件系统:

[[email protected]]# mkfs.ext4 /dev/drbd1 

[[email protected]]# mkdir /opt/ceshi 创建挂载目录

[root@db1 drbd.d]# mount/dev/drbd1 /opt/ceshi/

[root@db1 drbd.d]# cd/opt/ceshi/

[root@db1 ceshi]# touchaa.txt

[root@db1 ~]# umount/dev/drbd1 

[root@db1 ~]# drbdadmsecondary r0 

切换到db2

[[email protected]]# drbdadm primary r0

[[email protected]]# mkdir /opt/bb

[[email protected]]# mount /dev/drbd1 /opt/bb/

[[email protected]]# cd /opt/bb/

[root@db2bb]# ls

aa.txt lost+found

同步成功