1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
| [root@primary ~]# cd /etc/drbd.d [root@primary drbd.d]# vim global_common.conf # 此配置文件提供全局配置,及多个drbd设备相同的配置 global { usage-count no; # 是否加入改进计划 } common { handlers { } startup { } options { } disk { on-io-error detach; # IO出问题时,就将节点卸载 } net { cram-hmac-alg "sha1"; # 使用的算法 shared-secret "mydrbdshared123"; # 共享密钥,建议用随机数生成 } syncer { rate 500M; # 同步速率 } } # glocal:全局属性,定义drbd自己的工作特性。common:通用属性,定义多组drbd设备通用特性
[root@primary drbd.d]# vim mystore.res # 此文件为自建文件 resource mystore { # 首先定义公共配置,这一段可以被下面的多段使用 device /dev/drdb0; # 定义设备 disk /dev/sdb1; # 定义磁盘,定义这两项就让磁盘与设备关联了? meta-disk internal; # 在自己的dev内部构建使用 # 下面定义单个节点的属性 on primary { address 192.168.2.132:7789; } on secondary { address 192.168.2.132:7789; } } [root@primary drbd.d]# drbdadm create-md mystore initializing activity log NOT initializing bitmap Writing meta data... New drbd meta data block successfully created. # 初始化资源,mystore是资源名,是在mystore.res文件中定义的。在两个节点上分别执行 [root@primary drbd.d]# drbdadm create-md mystore initializing activity log NOT initializing bitmap Writing meta data... New drbd meta data block successfully created. [root@primary drbd.d]# service drbd start Starting DRBD resources: [ create res: mystore prepare disk: mystore adjust disk: mystore adjust net: mystore ] .... # 启动一个节点后,它会等待另一个节点也启动此服务,这时两个节点才会一起启动服务 [root@primary drbd.d]# cat /proc/drbd version: 8.4.6 (api:1/proto:86-101) GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R6, 2015-04-09 14:35:00 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:3140544 # 查看运行状态,现在两个都是Secondary,没有同步 [root@primary drbd.d]# drbd-overview 0:mystore/0 Connected Secondary/Secondary Inconsistent/Inconsistent # 使用此命令也可以 [root@primary drbd.d]# drbdadm primary --force mystore # 设置节点1为主节点 [root@primary drbd.d]# cat /proc/drbd version: 8.4.6 (api:1/proto:86-101) GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R6, 2015-04-09 14:35:00 0: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r----- ns:1067676 nr:0 dw:0 dr:1069720 al:0 bm:0 lo:0 pe:2 ua:2 ap:0 ep:1 wo:f oos:2074560 [=====>..............] sync'ed: 34.1% (2074560/3140544)K finish: 0:00:52 speed: 39,708 (39,480) K/sec # 显示同步过程,有两种状态,primary和secondary,主和从,左边为自己的状态右边是对方的状态 [root@primary drbd.d]# cat /proc/drbd version: 8.4.6 (api:1/proto:86-101) GIT-hash: 833d830e0152d1e457fa7856e71e11248ccf3f70 build by phil@Build64R6, 2015-04-09 14:35:00 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----- ns:3140544 nr:0 dw:0 dr:3141208 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0 # 同步完成,这是状态为Primary/Secondary [root@primary drbd.d]# mke2fs -t ext4 /dev/drbd0 mke2fs 1.41.12 (17-May-2010) 文件系统标签= 操作系统:Linux 块大小=4096 (log=2) 分块大小=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 196608 inodes, 785136 blocks 39256 blocks (5.00%) reserved for the super user 第一个数据块=0 Maximum filesystem blocks=805306368 24 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912
正在写入inode表: 完成 Creating journal (16384 blocks): 完成 Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 26 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. # 在主节点格式化磁盘,从节点也会自动格式化,因为是按位同步的
|