Centos 6.8 上 DRBD安装和使用

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/silenceray/article/details/65437672
环境:两台虚拟机
os:centos 64位 6.8
node1:192.168.11.64
node2:192.168.11.69
安装drbd前在两个虚拟机上加两个大小相同的物理磁盘分区,我这里是/dev/sdb1(注意:未经格式化的)
分区如下(在两个节点都操作)
[root@node1 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xa5927bb4.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G

Command (m for help): w
The partition table has been altered!
[root@node1 /]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0007f236

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2              64        6528    51915776   8e  Linux LVM

Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x2eb7246b

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1305    10482381   83  Linux

Disk /dev/mapper/VolGroup-lv_root: 51.1 GB, 51078234112 bytes
255 heads, 63 sectors/track, 6209 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/VolGroup-lv_swap: 2080 MB, 2080374784 bytes
255 heads, 63 sectors/track, 252 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

源码安装(两台机器上都安装)
[root@node1 tmp]# tar -xvf drbd-8.3.16.tar.gz
[root@node1 drbd-8.3.16]# ./configure --with-km
出现错误
To (re)make the documentation: make doc
make[1]: Leaving directory `/tmp/drbd-8.3.16/documentation'

	Userland tools build was successful.
    SORRY, kernel makefile not found.
    You need to tell me a correct KDIR,
    Or install the neccessary kernel source packages.

make: *** [check-kdir] Error 1
解决方法:安装kernel-devel   (我这是网上下载的)
[root@node1 tmp]# rpm -ivh kernel-devel-2.6.32-642.el6.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:kernel-devel           ########################################### [100%] 
   出现这个错误
 Cannot build utils without flex, either install flex or pass the --without-utils option.
解决方法:安装flex
[root@node1 drbd-8.3.16]# yum -y install flex
[root@node1 drbd-8.3.16]# make KDIR=/usr/src/kernels/2.6.32-642.el6.x86_64/
[root@node1 drbd-8.3.16]# make install
加载drbd模块到内核
[root@node2 etc]# depmod 
[root@node1 drbd-8.3.16]# modprobe drbd
[root@node1 drbd-8.3.16]#  lsmod | grep -i drbd
drbd                  332493  0 
创建挂载点:创建一个用于挂载drbd设备的挂载点(两个节点都执行)
[root@node1 etc]# mkdir /pg
[root@node2 etc]# mkdir /pg
配置drbd(两个节点都执行)
配置全局变量
[root@node1 drbd-8.3.16]# vim /usr/local/etc/drbd.d/global_common.conf
     syncer {
                rate 100M;
                # rate after al-extents use-rle cpu-mask verify-alg csums-alg
        }
rate设置同步速度上限,100M则表示同步速率限制在100M/s以内。
创建资源配置文件(两个节点均配置)
[root@node1 ~]# vim /usr/local/etc/drbd.d/r0.res
resource r0 {
  on SPEC-PGdatabase {
    device    /dev/drbd0;
    disk      /dev/sda1;
    address   1772.19.93.4:7789;
    meta-disk internal;
  }
  on SPEC-PGback1 {
    device    /dev/drbd0;
    disk      /dev/sda1;
    address   1772.19.93.19:7789;
    meta-disk internal;
  }
}

启动drdb
[root@node1 ~]# service drbd start
Starting DRBD resources: [ d(r0) s(r0) n(r0) ].
[root@node1 ~]# cat /proc/drbd 
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by root@node1, 2017-03-22 14:53:18
 0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r-----
    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:10482024
设置主节点
[root@node1 ~]#  drbdsetup /dev/drbd0 primary -o
[root@node1 ~]# cat /proc/drbd
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by root@node1, 2017-03-22 14:53:18
 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r-----
    ns:483328 nr:0 dw:0 dr:484000 al:0 bm:29 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:9998696
	[>....................] sync'ed:  4.7% (9764/10236)M
	finish: 0:03:47 speed: 43,936 (43,936) K/sec
[root@node1 ~]# service drbd status
drbd driver loaded OK; device status:
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by root@node1, 2017-03-22 14:53:18
m:res  cs          ro                 ds                     p  mounted  fstype
0:r0   SyncSource  Primary/Secondary  UpToDate/Inconsistent  C
...    sync'ed:    12.4%              (8980/10236)M
[root@node1 ~]# service drbd status
drbd driver loaded OK; device status:
version: 8.3.16 (api:88/proto:86-97)
[root@node1 ~]# service drbd status
drbd driver loaded OK; device status:
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by root@node1, 2017-03-22 14:53:18
m:res  cs         ro                 ds                 p  mounted  fstype
0:r0   Connected  Primary/Secondary  UpToDate/UpToDate  C
格式化磁盘
[root@node1 ~]# mkfs.ext3 /dev/drbd0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 2620506 blocks
131025 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2684354560
80 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

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 39 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@node1 ~]#  mount /dev/drbd0 /pg
测试同步
在node1上向drbd写入一个测试文件
[root@node1 ~]# cd /pg
[root@node1 pg]# ls
lost+found
[root@node1 pg]# touch test.txt
[root@node1 pg]# ll
total 16
drwx------ 2 root root 16384 Mar 23 09:29 lost+found
-rw-r--r-- 1 root root     0 Mar 23 09:32 test.txt
在node1上卸载drbd磁盘
[root@node1 /]# umount /pg/
在node1上将primary降为secondary:
[root@node1 /]#  drbdadm secondary r0
在node2上将secondary升为primary:
[root@node2 ~]# drbdadm primary r0
[root@node2 ~]# service drbd status
drbd driver loaded OK; device status:
version: 8.3.16 (api:88/proto:86-97)
GIT-hash: a798fa7e274428a357657fb52f0ecf40192c1985 build by root@node2, 2017-03-22 13:37:13
m:res  cs         ro                 ds                 p  mounted  fstype
0:r0   Connected  Primary/Secondary  UpToDate/UpToDate  C
将drbd设备挂载到node2节点:
[root@node2 ~]# mount /dev/drbd0 /pg
查看测试文件是否在:
[root@node2 ~]# cd /pg/
[root@node2 pg]# ls
lost+found  test.txt
文件存在,说明drbd配置没问题

猜你喜欢

转载自blog.csdn.net/silenceray/article/details/65437672