二、drbd配置
注:两节点均做如下配置
1、添加磁盘/dev/sdb1
2、安装drbd
#rpm -ivh drbd83-8.3.8-1.el5.CentOS.i386.rpm
# rpm -ivh kmod-drbd83-8.3.8-1.el5.centos.i686.rpm
# modprobe drbd //加载drbd模块
# lsmod |grep drbd //查看模块加载情况
3、修改配置文件
#vim /etc/drbd.conf
# You can find an example in /usr/share/doc/drbd.../drbd.conf.example
include "drbd.d/global_common.conf";
include "drbd.d/*.res";
~ :r /usr/share/doc/drbd83-8.3.8/drbd.conf //末行模式下执行读命令来加载
#cp /etc/drbd.d/global_common.conf /etc/drbd.d/global_common.conf.bak
# vim /etc/drbd.d/global_common.conf (替换掉原来的内容)
global {
usage-count yes;
# minor-count dialog-refresh disable-ip-verification
}
common {
protocol C;
startup { //启动延时配置
wfc-timeout 120; //等待连接的超时时间
degr-wfc-timeout 120; //等待降级的节点连接的超时时间
}
disk {
on-io-error detach; //当出现I/O错误,节点要拆掉drbd设备
fencing resource-only;
}
net {
cram-hmac-alg "sha1"; //使用sha1加密算法实现节点认证
shared-secret "mydrbdlab"; //认证码,两个节点内容要相同
}
syncer {
rate 100M; //定义同步数据时的速率
}
}
# vim /etc/drbd.d/MySQL.res //定义资源
resource mysql { //资源名称
on node1.a.com {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.3.1:7789;
meta-disk internal;
}
on node2.a.com {
device /dev/drbd0;
disk /dev/sdb1;
address 192.168.3.2:7789;
meta-disk internal;
}
}
3、初始化,启动服务
#drbdadm create-md mysql
# service drbd start &&chkconfig drbd on //并设为开机启动
4、指定主节点 node1
#drbdadm -- --overwrite-data-of-peer primary mysql
#node1查看状态
[root@node11~]# drbd-overview
0:mysql Connected Primary/Secondary UpToDate/UpToDate C r----
#node2查看状态
[root@node12~]# drbd-overview
0:mysql Connected Secondary/Primary UpToDate/UpToDate C r----
5、仅在主节点上操作(node1)
#格式化为ext3文件系统
# mkfs.ext3 /dev/drbd0
#挂载
# mount /dev/drbd0 /mysql/
#进入目录,创建mysql存放的目录
# cd /mysql/
# mkdir data
6、使node2变为主节点
node1操作
#先卸载
# umount /mysql/
#变为备份节点
# drbdadm secondary mysql
node2操作
#变为主节点,实现挂载
# drbdadm -- --overwrite-data-of-peer primary mysql
# mkdir /mysql
# mount /dev/drbd0 /mysql
#不用再格式化了
# cd /mysql
[root@node2 mysql]# ll
总计 20
drwxr-xr-x 2 root root 4096 01-22 22:04 data
drwx------ 2 root root 16384 01-22 22:03 lost+found
#卸载
# umount /mysql
#并设为备份节点
# drbdadm secondary mysql
drbd测试成功,drbd已经安装完成