1: 复制样例配置文件为即将使用的配置文件.
[root@node1 ~]# cp /usr/share/doc/drbd83-8.3.8/drbd.conf /etc/
2:将文件global_common.conf 备份一份
[root@node1 ~]# cd /etc/drbd.d/
[root@node1 drbd.d]# ll
-rwxr-xr-x 1 root root 1418 Jun 4 2010 global_common.conf
[root@node1 drbd.d]# cp global_common.conf global_common.conf.bak
3:编辑global_common.conf
[root@node1 drbd.d]# vim global_common.conf
global {
usage-count no; 不开启统计
}
common {
protocol C;
handlers {
pri-on-incon-degr "/usr/lib/drbd/notify-pri-on-incon-degr.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
pri-lost-after-sb "/usr/lib/drbd/notify-pri-lost-after-sb.sh; /usr/lib/drbd/notify-emergency-reboot.sh; echo b > /proc/sysrq-trigger ; reboot -f";
local-io-error "/usr/lib/drbd/notify-io-error.sh; /usr/lib/drbd/notify-emergency-shutdown.sh; echo o > /proc/sysrq-trigger ; halt -f";
}
startup {
wfc-timeout 120; 等待连接的超时时间
degr-wfc-timeout 120; 等待降级的节点连接的超时时间
}
disk {
on-io-error detach; 当出现I/O错误,节点要拆掉drbd设备
}
net {
cram-hmac-alg "sha1"; 使用sha1加密算法实现节点认证
shared-secret "mydrbdlab"; 认证码,两个节点内容要相同
}
syncer {
rate 100M; 定义同步数据时的速率
}
}
4:定义mysql的资源
[root@node1 drbd.d]# vim mysql.res
resource mysql {
on node1.linuxidc.com {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.2.10:7789;
meta-disk internal;
}
on node2.linuxidc.com {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.2.20:7789;
meta-disk internal;
}
}
5:将以上的drbd.*文件都拷贝到node2上面
[root@node1 drbd.d]# scp -r /etc/drbd.* node2:/etc/
6:node1初始化定义的mysql的资源并启动相应的服务
[root@node1 drbd.d]# drbdadm create-md mysql
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
[root@node1 drbd.d]# service drbd start
7:node2初始化定义的mysql的资源并启动相应的服务
[root@node2 drbd.d]# drbdadm create-md mysql
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
[root@node2 drbd.d]# service drbd start
8: 使用drbd-overview命令来查看启动状态
[root@node1 drbd.d]# drbd-overview
0:mysql Connected Secondary/Secondary Inconsistent/Inconsistent C r----
从上面的信息中可以看出此时两个节点均处于Secondary状态。于是,我们接下来需要将其中一个节点设置为Primary,这里将node1设置为主节点,故要在node1上执行如下命令:
[root@node1 drbd.d]# drbdadm -- --overwrite-data-of-peer primary mysql
[root@node1 drbd.d]# drbd-overview 再次查看启动的状态
0:mysql SyncSource Primary/Secondary UpToDate/Inconsistent C r----
[>...................] sync'ed: 8.7% (906616/987896)K delay_probe: 4
[root@node2 drbd.d]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.CentOS.org, 2010-06-04 08:04:16
0: cs:Connected ro:Secondary/Primary ds:UpToDate/UpToDate C r----
ns:0 nr:987896 dw:987896 dr:0 al:0 bm:61 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
注:
Primary/Secondary 说明当前节点为主节点
Secondary/Primary 说明当前节点为从节点
9:然后查看同步过程
[root@node1 drbd.d]# watch -n 1 'cat /proc/drbd'
10:创建文件系统(只可以在primary节点上进行)
[root@node1 drbd.d]# mkfs -t ext3 /dev/drbd0 格式化
[root@node1 drbd.d]# mkdir /mysqldata 创建挂载点
[root@node1 drbd.d]# mount /dev/drbd0 /mysqldata/ 进行挂载
[root@node1 drbd.d]#cd /mysqldata
[root@node1 mysqldata]#touch f1 f2 创建2个文件
[root@node1 drbd.d]# ls /mysqldata/
-rw-r--r-- 1 root root 0 May 9 15:45 f1
-rw-r--r-- 1 root root 0 May 9 15:45 f2
drwx------ 2 root root 16384 May 9 15:41 lost+found
[root@node1 ~]#umount /mysqldata 卸载drbd设备
[root@node1 ~]# drbdadm secondary mysql 将node1设置为secondary节点
[root@node1 ~]# drbd-overview
0:mysql Connected Secondary/Secondary UpToDate/UpToDate C r----
11:将node2设置为primary节点
[root@node2 ~]# drbdadm primary mysql
[root@node2 ~]# drbd-overview
0:mysql Connected Primary/Secondary UpToDate/UpToDate C r----
[root@node2 ~]#mkdir /mysqldata
[root@node2 ~]#mount /dev/drbd0 /mysqldata
[root@node2 ~]# ll /mysqldata/
total 16
-rw-r--r-- 1 root root 0 May 9 15:45 f1
-rw-r--r-- 1 root root 0 May 9 15:45 f2
drwx------ 2 root root 16384 May 9 15:41 lost+found
[root@node2 ~]# umount /mysqldata/ 卸载设备
至此我们的drbd已经正常安装完成!!!