mysql heartbeat 共享存储_DRBD+Heartbeat+NFS文件共享存储架构

四、配置

1. 配置 /etc/drbd.conf ,可参考位置:/usr/share/doc/drbd82-8.2.6/drbd.conf,这里我们先在TM-Master 节点直接编辑它:

[root@TM-Master ~] vi /etc/drbd.conf

resource r0

{

protocol C;

startup {

wfc-timeout 0;

degr-wfc-timeout 120;

}

disk {

on-io-error detach;

}

syncer {

rate 10M;

}

on TM-Master {

device /dev/drbd1;

disk /dev/sdb1;

address 192.168.137.132:7789;

meta-disk internal;

}

on TM-Master S {

device /dev/drbd1;

disk /dev/sdb1;

address 192.168.137.133:7789;

meta-disk internal;

}

}

配置说明:

resource r0; 资源组名称 r0

degr-wfc-timeout 120; 连接超时时间

on-io-error detach; 当磁盘有错误时,不连接

rate 10M; 设置主备节点同步时的网络速率最大值

on TM-Master ; 节点的主机名

device /dev/drbd1; 创建的drbd设备

2. 复制TM-Master 的配置文件到TM-Slave 上:

[root@TM-Slave ~]# scp root@TM-Slave:/etc/drbd.conf /etc/drbd.conf

3. 在两台服务器上分别初始化分区,并启动服务:

# drbdadm create-md r0

Writing meta data…

initialising activity log

NOT initialized bir0ap

New drbd meta data block sucessfully created.

备注:

1) “r0”是在drbd.conf里定义的资源名称.

2) 当执行命令”drbdadm create-md r0”时,出现以下错误信息。

Device size would be truncated, which

would corrupt data and result in

‘access beyond end of device’ errors.

You need to either

* use external meta data (recommended)

* shrink that filesystem first

* zero out the device (destroy the filesystem)

Operation refused.

Command ‘drbdmeta 0 v08 /dev/xvdb internal create-md’ terminated with exit code 40

drbdadm create-md r0: exited with code 40

解决办法:初始化磁盘文件格式, dd if=/dev/zero of=/dev/sdxx bs=1M count=100

# dd if=/dev/zero of=/dev/sdb1 bs=1M count=100

100+0 records in

100+0 records out

104857600 bytes (105 MB) copied, 1.92004 seconds, 54.6 MB/s

启动:

# /etc/init.d/drbd start

Starting DRBD resources: [ d(r0) s(r0) n(r0) ].

……….

这里我用到了r0, 你也可以用你的资源组名称,譬如本例的 db。

查看两台机器的状态,用cat /proc/drbd 或 /etc/init.d/drbd status:

[root@TM-Master ~]# /etc/init.d/drbd status

drbd driver loaded OK; device status:

version: 8.2.6 (api:88/proto:86-88)

GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn@c5-x8664-build, 2008-10-03 11:30:17

m:res cs st ds p mounted fstype

0:r0 Connected Secondary/Secondary Inconsistent/Inconsistent C

[root@TM-Slave ~]# /etc/init.d/drbd status

drbd driver loaded OK; device status:

version: 8.2.6 (api:88/proto:86-88)

GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn@c5-x8664-build, 2008-10-03 11:30:17

m:res cs st ds p mounted fstype

0:r0 Connected Secondary/Secondary Inconsistent/Inconsistent C

现在两机器都是处于Secondary,即备机状态。(红色部分标记),如果是Unknow,则检查两台是否配置一样。

5. 设置primary主机:

[root@TM-Master ~] drbdadm primary r0

第一次可能会设置失败,可以使用:

[root@TM-Master ~]# drbdsetup /dev/drbd0 primary -o

将把 TM-Master 作为主机,把 TM-Master 中的数据以块的方式同步到 TM-Slave 中。其中 r0 为资源名,可再次查看状态:

[root@TM-Master ~]# /etc/init.d/drbd status

drbd driver loaded OK; device status:

version: 8.2.6 (api:88/proto:86-88)

GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn@c5-x8664-build, 2008-10-03 11:30:17

m:res cs st ds p mounted fstype

… sync’ed: 8.8% (9350/10236)M

0:r0 SyncSource Primary/Secondary UpToDate/Inconsistent C

[root@TM-Slave ~]# /etc/init.d/drbd status

drbd driver loaded OK; device status:

version: 8.2.6 (api:88/proto:86-88)

GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn@c5-x8664-build, 2008-10-03 11:30:17

m:res cs st ds p mounted fstype

… sync’ed: 13.7% (8847/10236)M

0:r0 SyncTarget Secondary/Primary Inconsistent/UpToDate C

通过/proc/drbd,可以查看磁盘的复制状态:

[root@TM-Master ~]# cat /proc/drbd

version: 8.2.6 (api:88/proto:86-88)

GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn@c5-x8664-build, 2008-10-03 11:30:17

0: cs:SyncSource st:Primary/Secondary ds:UpToDate/Inconsistent C r—

ns:2151328 nr:0 dw:0 dr:2151328 al:0 bm:131 lo:0 pe:0 ua:0 ap:0 oos:8330696

[===>................] sync’ed: 20.6% (8135/10236)M

finish: 0:12:48 speed: 10,804 (10,244) K/sec

[root@TM-Slave ~]# cat /proc/drbd

version: 8.2.6 (api:88/proto:86-88)

GIT-hash: 3e69822d3bb4920a8c1bfdf7d647169eba7d2eb4 build by buildsvn@c5-x8664-build, 2008-10-03 11:30:17

0: cs:SyncTarget st:Secondary/Primary ds:Inconsistent/UpToDate C r—

ns:0 nr:1791904 dw:1791904 dr:0 al:0 bm:109 lo:0 pe:0 ua:0 ap:0 oos:8690120

[==>.................] sync’ed: 17.2% (8486/10236)M

finish: 0:11:18 speed: 12,792 (10,236) K/sec

至此,镜像分区已创建完成,我们在两台服务器上设置为开机自启动:

# chkconfig drbd on

挂载使用

在 Primary 主节点上,即 TM-Master ,格式化文件系统并挂载

[root@TM-Master ~]# mkfs.ext3 /dev/drbd0

[root@TM-Master ~]# tune2fs -c 0 -i 0 /dev/drbd0

[root@TM-Master ~]# mkdir /home/drbd

[root@TM-Master ~]# mount /dev/drbd0 /home/drbd

[root@TM-Master ~]# mount

/dev/drbd0 on /home/drbd type ext3 (rw)

注:drbd 设备只能在 Primary 端使用,为避免误操作,当机器重启后,默认都处于 Secondary 状态,如要使用drbd设备,需手动把其设置为Primary。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值