DRBD安装详细过程

DRBD(Distributed Replicated Block Device),分布式复制块设备,是一种通过TCP/IP网络实现块设备数据实时镜像的方案

 

linux version: 2.6.9-5.EL
drbd version:  drbd-8.3.1.tar.gz
     下载地址: http://oss.linbit.com/drbd/

主机
  主机名:iptx1
      IP:172.16.16.15
drbd分区:/dev/sda6 200M

备机
  主机名:iptx2
      IP:172.16.16.11
drbd分区:/dev/sda6 200M

 

修改/etc/hosts
172.16.16.15    iptx1
172.16.16.11    iptx2

 

1. DRBD安装
# tar zxvf drbd-8.3.1.tar.gz
# cd drbd-8.3.1
# make
# make install

 

2. 测试DRBD模块是否加载成功
# cd drbd-8.3.1
# insmod drbd/drbd.ko 或者 # modprobe drbd
# lsmod | grep drbd
  提示: drbd                  267132   0

 

3. 配置DRBD
# vi /etc/drbd.conf
-----------------------------
global { usage-count yes; }
       common { syncer { rate 100M; } }
       resource r0 {
            protocol C;
            net {
                 cram-hmac-alg sha1;
                 shared-secret "FooFunFactory";
                 allow-two-primaries;
            }
            on iptx1 {
                 device    /dev/drbd0;
                 disk      /dev/sda6;
                 address   172.16.16.15:7789;
                 meta-disk  internal;
            }
            on iptx2 {
                 device    /dev/drbd0;
                 disk      /dev/sda6;
                 address   172.16.16.11:7789;
                 meta-disk  internal;
            }
       }
-----------------------------
将该文件分别拷贝到两台主机上的/etc下面,两台主机上一样

 

4. DRBD启动


1) 创建供DRBD记录信息的数据块
# drbdadm create-md r0
创建块设备后不需要格式化磁盘分区
删除磁盘分区格式
# dd if=/dev/zero bs=1M count=1 of=/dev/sda6

 

2) 启动drbd服务
# service drbd start 或者 /etc/init.d/drbd start
正常情况提示:Starting DRBD resources: [ ].
如果提示找不到peer,请输入yes永久等待,请检查/etc/hosts和iptables

 

查看状态: service drbd status
[root@iptx1 mnt]# /etc/init.d/drbd status
drbd driver loaded OK; device status:
version: 8.3.1 (api:88/proto:86-89)
GIT-hash: fd40f4a8f9104941537d1afc8521e584a6d3003c build by root@localhost , 2010-11-19 14:49:22
m:res  cs         ro                 ds                 p  mounted  fstype
0:r0   Connected  Secondary/ Secondary  UpToDate/UpToDate  C

 

3) 初始化一个为主机(在iptx1上执行)
drbdsetup /dev/drbd0 primary -o
等待同步完成……

[root@iptx1 mnt]# /etc/init.d/drbd status
drbd driver loaded OK; device status:
version: 8.3.1 (api:88/proto:86-89)
GIT-hash: fd40f4a8f9104941537d1afc8521e584a6d3003c build by root@localhost , 2010-11-19 14:49:22
m:res  cs         ro                 ds                 p  mounted  fstype
0:r0   Connected  Primary /Secondary  UpToDate/UpToDate  C

 

5. DRBD验证
1) 在主机上执行
格式化块设备(只需要格式化主机上的drbd0)
# mkfs.ext3 /dev/drbd0
挂载
# mount /dev/drbd0 /mnt/drbd
创建一个文件
# dd if=/dev/zero of=/mnt/drbd0/tempfile1.tmp bs=104857600 count=2

 

2) 操作完成后,在备机上执行
先停止DRBD
# /etc/init.d/drbd stop

将sda6进行挂载
# mount /dev/sda6 /mnt/drbd

# ls /mnt/drbd -hl
total 201M
drwx------  2 root root  12K Jul 28 23:44 lost+found
-rw-r--r--  1 root root 200M Jul 29 00:20 tempfile1.tmp

# umount /mnt/drbd

 

6.DRBD的主备机切换
有时,你需要将DRBD的主备机互换一下.可以执行下面的操作:
在主机上,先要卸载掉DRBD设备.
[root@iptx1 /]# umount /mnt/drbd

 

将主机降级为”备机”.
[root@iptx1 /]# drbdadm secondary r0
[root@iptx1 /]# cat /proc/drbd
version: 8.3.1 (api:88/proto:86-89)
GIT-hash: fd40f4a8f9104941537d1afc8521e584a6d3003c build by root@localhost , 2010-11-19 14:49:22
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----
    ns:211748 nr:0 dw:11000 dr:208733 al:27 bm:14 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0

 

现在,两台主机都是”备机”.

在备机iptx2上,将它升级为”主机”.
[root@iptx2 /]# drbdadm primary r0
[root@iptx2 /]# cat /proc/drbd
GIT-hash: fd40f4a8f9104941537d1afc8521e584a6d3003c build by root@iptx2 , 2010-11-18 15:18:44
 0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r---
    ns:0 nr:37 dw:37 dr:0 al:0 bm:1 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
        resync: used:0/31 hits:0 misses:0 starving:0 dirty:0 changed:0
        act_log: used:0/127 hits:0 misses:0 starving:0 dirty:0 changed:0

你可能感兴趣的:(Linux)