yum -y install gcc kernel-devel kernel-headers flex
wget http://oss.linbit.com/drbd/8.4/drbd-8.4.1.tar.gz
tar xzf drbd-8.4.1.tar.gz
cd drbd-8.4.1
./configure --prefix=/usr/local/drbd --with-km
make KDIR=/usr/src/kernels/2.6.32-220.17.1.el6.x86_64/
make install
mkdir -p /usr/local/drbd/var/run/drbd
cp /usr/local/drbd/etc/rc.d/init.d/drbd /etc/rc.d/init.d
chkconfig --add drbd
chkconfig drbd on
KDIR=中指定的系统内核源码路径,根据实际情况设置
cd drbd
make clean
make KDIR=/usr/src/kernels/2.6.32-220.17.1.el6.x86_64/
cp drbd.ko /lib/modules/`uname -r`/kernel/lib/
depmod
vi /usr/local/drbd/etc/drbd.d/global_common.conf
global {
usage-count yes;
}
common {
net {
protocol C;
}
}
当然,还可以有其它配置,这是最基本的。
vi /usr/local/drbd/etc/drbd.d/r0.res
resource r0{
on masterNode{
device /dev/drbd1; #逻辑设备的路径
disk /dev/sda3; #物理设备
address 192.168.58.128:7788;
meta-disk internal;
}
on backupNode{
device /dev/drbd1;
disk /dev/sda3;
address 192.168.58.129:7788;
meta-disk internal;
}
}
需要把上面用到的防火墙7788端口打开,这个端口是自定义的,如果嫌麻烦可以直接关掉防火墙。
说明:
device 是自定义的物理设备的逻辑路径
disk 是磁盘设备,或者是逻辑分区
address 是机器监听地址和端口
meta-disk 这个还没弄明白,看到的资料都是设为:internal
modprobe drbd //载入 drbd 模块
lsmod | grep drbd //确认 drbd 模块是否载入
dd if=/dev/zero of=/dev/sda3 bs=1M count=100 //把一些资料塞到 sda3 內 (否则 create-md 时会报错)
drbdadm create-md r0 //建立 drbd resource
drbdadm up r0
[root@backupNode /]# drbdadm up r0
1: Failure: (104) Can not open backing device.
Command 'drbdsetup attach 1 /dev/sda3 /dev/sda3 internal' terminated with exit code
umount /dev/sda3
问题解决。
drbdadm primary --force r0
[root@backupNode /]# cat /proc/drbd
version: 8.4.1 (api:1/proto:86-100)
GIT-hash: 91b4c048c1a0e06777b5f65d312b38d47abaea80 build by root@masterNode, 2012-05-27 18:34:27
1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r-----
ns:4 nr:9504584 dw:9504588 dr:1017 al:1 bm:576 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
已经变成了主服务器。
[root@masterNode /]# mkfs.ext4 /dev/drbd1
输出:
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
589824 inodes, 2358959 blocks
117947 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=2415919104
72 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 21 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@masterNode /]# mount /dev/drbd1 /drbdData
[root@masterNode /]# umount /dev/drbd1
[root@masterNode /]# drbdadm secondary r0
[root@masterNode /]# ssh backupnode
Last login: Sun May 27 19:57:17 2012 from masternode
[root@backupNode ~]# drbdadm primary r0
[root@backupNode ~]# mount /dev/drbd1 /drbdData/
3、最后,进入/drbdData目录,就可以看到之前在另外一台机器上放入的数据了,如果没有看到,说明同步失败!