DRBD( Distributed Replicated Block Device 分布式复制块设备)
操作系统:RedHat 5.4
安装软件:drbd83-8.3.8-1.el5.centos.i386.rpm
kmod-drbd83-8.3.8-1.el5.centos.i686.rpm
一:分别配置server1.server2的IP和host文件以及主机名
server1
(1)IP配置
(2)主机名
shell>honame server1.gz.com
shell>vim /etc/sysconfig/network
HOSTNAME=server1.gz.com
(3)hosts文件
shell>vim etc/hosts (添加主机名于IP的映射)
192.168.2.10 server1.gz.com server1
192.168.2.20 server2.gz.com server2
server2:
(1)IP配置
(2)主机名
shell>honame server2.gz.com
shell>vim /etc/sysconfig/network
HOSTNAME=server1.gz.com
(3)hosts文件
shell>vim etc/hosts (添加主机名于IP的映射)
192.168.2.10 server1.gz.com server1
192.168.2.20 server2.gz.com server2
二:在server1和server2都安装
drbd83-8.3.8-1.el5.centos.i386.rpm
kmod-drbd83-8.3.8-1.el5.centos.i686.rpm
三:在server1和server2上都添加一个相同大小的新分区(这里用500M模拟)
shell>fdisk /dev/sda
四:在server1和server2的都进行相同的配置
shell>vim /etc/drbd.conf #主配置文件
include "drbd.d/global_common.conf";
include "drbd.d/*.res";
shell>cd /etc/drbd.d/
shell>vim global_common.conf #全局配置文件
global {
usage-count yes;
}
common {
protocol C;
startup {
wfc-timeout 120;
degr-wfc-timeout 120;
}
disk {
on-io-error detach;
fencing resource-only;
}
net {
cram-hmac-alg "sha1";
shared-secret "mydrbdlab";
}
syncer {
rate 10M;
}
}
shell> vim web.res #资源配置文件
resource web {
on server1.gz.com {
device /dev/drbd0;
disk /dev/sda4;
address 192.168.3.10:7789;
meta-disk internal;
}
on server2.gz.com {
device /dev/drbd0;
disk /dev/sda4;
address 192.168.3.20:7789;
meta-disk internal;
}
}
五:开启服务以及主节点设置
shell>service drbd start
shell>drbdadm create-md web
注意:只有在主节点上能实现挂载
使节点成为主节点的命令是 shell>drbdadm primary web (这里的web是上步定义的服务)
使节点成为主节点的命令是 shell>drbdadm primary web
在这里使server1成为主节点
shell>drbdadm -- --overwrite-data-of-peer primary web
在主节点上的DRBD的块设备上建立文件系统并创建挂点
shell>mkfs -t ext3 /dev/drbd0
shell>mkdir /mnt/drbd
shell>mount /dev/drbd0 /mount/drbd/
shell>scp drbd83-8.3.8-1.el5.centos.i386.rpm /mnt/drbd
六测试:
在server1卸载块设备的挂载,并使它成为备份设备
shell>umount /mnt/drbd
shell>drbdadm secondary web 使它成为备份设备
在server2上使server2变为主设备,并挂载drdb块设备
shell>mk/mnt/drbd
shell>drbdadm primary web
shell>mount /dev/drbd0 /mnt/drbd/
shell>cd /mnt/drbd
shell>ll