DRBD磁盘镜像小实验
2009.12.19 Tsengyia#126.com http://tsengyia.blog.chinaunix.net/
##############################################################
系统环境:RHEL5 [ 2.6.18-9.el5 ]
host1(主机):IP地址:192.168.4.11 镜像分区:/dev/sdb1,40GB
host2(备机):IP地址:192.168.4.12 镜像分区:/dev/sdb1,40GB
软件环境:
RHEL5自带RPM包:
kernel-headers-2.6.18-8.el5
kernel-devel-2.6.18-8.el5
需另下载的软件包:
drbd-8.3.6.tar.gz
##############################################################
一、安装drbd软件包(host1,host2)
1. 安装内核开发环境(kernel-headers、kernel-devel)
使用RHEL5光盘自带的RPM包
2. 安装drbd软件包
[root@localhost ~]# tar zxvf drbd-8.3.6.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/drbd-8.3.6
[root@localhost drbd-8.3.6]# ./configure --prefix=/ --with-km //--with-km表示安装为内核模块
[root@localhost drbd-8.3.6]# make
[root@localhost drbd-8.3.6]# make install
3.调整drbd服务脚本
[root@localhost ~]# vi /etc/init.d/drbd //在服务脚本的start)部分添加模块加载语句
……
case "$1" in
start)
insmod /lib/modules/2.6.18-8.el5/kernel/drivers/block/drbd.ko
……
[root@localhost ~]# chkconfig --add drbd //添加给chkconfig、ntsysv管理
[root@localhost ~]# chkconfig --level 35 drbd on
二、建立/etc/drbd.conf配置文件(host1,host2)
具体配置可参考dhcpd.conf文件中的注释或者man手册页
[root@localhost ~]# vi /etc/drbd.conf
global { usage-count yes; } //是否参加DRBD使用者统计
common {
protocol C; //类型包括A、B、C三种,C表示收到远程主机的写入确认后,视为写入完成
syncer { rate 100M; } //同步速率
}
resource r1 {
device minor 1;
meta-disk internal;
net {
cram-hmac-alg sha1; //设置网络传输加密算法
shared-secret "secret string"; //认证字串
}
on host1 { //on 主机名
device /dev/drbd1; //drbd设备
disk /dev/sdb1; //对应的分区
address 192.168.4.11:7801; //IP地址及端口
}
on host2 {
device /dev/drbd1;
disk /dev/sdb1;
address 192.168.4.12:7801;
}
}
三、建立drbd设备,启动drbd服务(host1,host2)
1. 建立md设备
[root@localhost ~]# drbdadm create-md r1
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
2. 启动drbd服务程序
[root@localhost ~]# /etc/init.d/drbd start
3. 确认drbd状态
[root@localhost ~]# cat /proc/drbd
version: 8.3.6 (api:88/proto:86-91)
GIT-hash: f3606c47cc6fcf6b3f086e425cb34af8b7a81bbf build by , 2009-12-18 13:28:03
1: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsisten C r----
ns:0 nr:0 dw:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:4008024
—— Secondary/Secondary 表示两个节点都处于辅助(从)状态
四、初始化Primary机(host1)
1. 设为主导状态(同步发起端)
[root@localhost ~]# drbdsetup /dev/drbd1 primary -o
block drbd1: Forced to consider local data as UpToDate!
—— //如需降级为备机,可执行umount /dev/drbd1 ;drbdadm secondary r1
2. 再次确认host1的drbd状态
[root@localhost ~]# cat /proc/drbd
version: 8.3.6 (api:88/proto:86-91)
GIT-hash: f3606c47cc6fcf6b3f086e425cb34af8b7a81bbf build by , 2009-12-18 13:28:03
1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsisten C r----
ns:44608 nr:0 dw:0 dr:44608 al:0 bm:0 lo:0 pe:1 ua:0 ap:0 ep:1 wo:b oos:3963
[>............] sync'ed: 2.3% (3921720/4008024)
finish:3:06:44 speed: 340 (320) K/sec
—— 表示正处于同步过程中
3. 同步完成后,可再次确认drbd状态
[root@localhost ~]# cat /proc/drbd
version: 8.3.6 (api:88/proto:86-91)
GIT-hash: f3606c47cc6fcf6b3f086e425cb34af8b7a81bbf build by , 2009-12-18 13:28:03
1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsisten C r----
ns:4137868 nr:0 dw:129844 dr:4008242 al:49 bm:245 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
五、验证磁盘镜像结果(host2)
1. host1主机中
[root@localhost ~]# mkfs -t ext3 /dev/sdb1
[root@localhost ~]# mkdir /mnt/sdb1
[root@localhost ~]# mount /dev/drbd1 /mnt/sdb1
[root@localhost ~]# ls > /mnt/sdb1/test.file
[root@localhost ~]# ls /mnt/sdb1
lost+found test.file
2. host2主机中
[root@localhost ~]# service drbd stop
[root@localhost ~]# mount /dev/sdb1 /mnt/sdb1
[root@localhost ~]# ls /mnt/sdb1
lost+found test.file
阅读(1720) | 评论(0) | 转发(0) |