DRBD简介
Distributed Replicated Block Device(DRBD)是一个用软件实现的、无共享的、服务器之间镜像块设备内容的存储复制解决方案。
数据镜像:实时、透明、同步(所有服务器都成功后返回)、异步(本地服务器成功后返回)
DBRD的核心功能通过Linux的内核实现,最接近系统的IO栈,但它不能神奇地添加上层的功能比如检测到EXT3文件系统的崩溃。
DBRD的位置处于文件系统以下,比文件系统更加靠近操作系统内核及IO栈。
以上信息,来自于互联网,请尊重版权。接下来笔者将向您展示如何配置heartbeat+drbd的实例。
环境要求:某企业为了实现高可用性的群集文件系统,出于成本的考虑采用drbd技术。
实验拓扑:
实验步骤:
一、准备环境
1.系统环境
# uname –r //内核版本
2.6.18-164.el5
# cat /etc/redhat-release //查看系统信息
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
2.修改主机名称等
在节点1上进行修改
# hostname node1.a.com //修改主机名称
# vim /etc/sysconfig/network //修改文件
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=node1.a.com
之后退出再次登陆。
# hostname //查看名称
node1.a.com
# vim /etc/hosts //修改hosts文件
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.1.3 node1.a.com
192.168.1.4 node2.a.com
在节点2上进行修改
# hostname node2.a.com //修改主机名称
# vim /etc/sysconfig/network //修改文件
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=node2.a.com
之后退出再次登陆。
# hostname //查看名称
node2.a.com
# vim /etc/hosts //修改hosts文件
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.1.3 node1.a.com
192.168.1.4 node2.a.com
3.安装所需的文件
预先将所需的文件上传到管理员家目录。以下操作在node1.a.com和node2.a.com上都进行操作。
为了方便你的使用,笔者已将全部所需文件上传到笔者空间,提供您免费下载:http://down.51cto.com/data/401397
# ll
total 3084
-rw------- 1 root root 1291 Feb 8 02:05 anaconda-ks.cfg
-rw-r--r-- 1 root root 221868 May 7 2012 drbd83-8.3.8-1.el5.centos.i386.rpm
-rw-r--r-- 1 root root 1637238 Mar 14 2010 heartbeat-2.1.4-9.el5.i386.rpm
-rw-r--r-- 1 root root 293349 Mar 14 2010 heartbeat-devel-2.1.4-9.el5.i386.rpm
-rw-r--r-- 1 root root 230890 Mar 14 2010 heartbeat-gui-2.1.4-9.el5.i386.rpm
-rw-r--r-- 1 root root 111742 Mar 14 2010 heartbeat-ldirectord-2.1.4-9.el5.i386.rpm
-rw-r--r-- 1 root root 92070 Mar 14 2010 heartbeat-pils-2.1.4-10.el5.i386.rpm
-rw-r--r-- 1 root root 179199 Mar 14 2010 heartbeat-stonith-2.1.4-10.el5.i386.rpm
-rw-r--r-- 1 root root 35236 Feb 8 02:04 install.log
-rw-r--r-- 1 root root 3995 Feb 8 02:02 install.log.syslog
-rw-r--r-- 1 root root 125974 May 7 2012 kmod-drbd83-8.3.8-1.el5.centos.i686.rpm
-rw-r--r-- 1 root root 56817 Mar 14 2010 libnet-1.1.4-3.el5.i386.rpm
-rw-r--r-- 1 root root 92071 Mar 14 2010 perl-MailTools-1.77-1.el5.noarch.rpm
# yum localinstall *.rpm --nogpgcheck –y //使用yum进行安装可以有效的解决包的依赖性问题。
4.同步时钟
要求两个节点上的始终必须要一致。
# hwclock -s //同步始终
# date //查看日期
Wed Feb 8 03:38:44 CST 2012
#
5.加载模块
在两个节点上都去进行如下操作。
# modprobe drbd //加载drbd模块
#
# lsmod |grep drbd //查看模块
drbd 228528 0
#
6.创建新分区
以下操作要求在node1.a.com和node2.a.com上都进行。同时要求两个节点所创建的新分区大小一致。
# fdisk -l //查看有关情况
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1415 1020127+ 82 Linux swap / Solaris
# fdisk /dev/sda
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Command (m for help): n //创建新分区
Command action
e extended
p primary partition (1-4)
p //创建主分区
Selected partition 4
First cylinder (1416-2610, default 1416):
Using default value 1416
Last cylinder or +size or +sizeM or +sizeK (1416-2610, default 2610): +1G //两个节点的分区大小要一致。
Command (m for help): p //显示
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1415 1020127+ 82 Linux swap / Solaris
/dev/sda4 1416 1538 987997+ 83 Linux
Command (m for help): w 保存
# fdisk -l //再次查看
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1415 1020127+ 82 Linux swap / Solaris
/dev/sda4 1416 1538 987997+ 83 Linux
#
# partprobe /dev/sda //重新加载
二、DRBD配置
以下操作要求在节点node1和node2上都做。
1.修改conf配置文件
# cd /usr/share/doc/drbd83-8.3.8/
#ls
ChangeLog COPYING drbd.conf file.list README
#cp drbd.conf /etc/ 复制配置文件到相关目录
cp: overwrite `/etc/drbd.conf'? y
#cd /etc/drbd.d/
# ls
global_common.conf
# cp -p global_common.conf global_common.conf.bak //最好对文件进行备份
# vim global_common.conf
//第一列是行的序号
1 global {
2 usage-count no;
3 }
4
5 common {
6 protocol C;
7 startup {
8 wfc-timeout 120;
9 degr-wfc-timeout 120;
10 }
11 disk {
12 on-io-error detach;
13 fencing resource-only;
14 }
15 net {
16 cram-hmac-alg "sha1";
17 shared-secret "mydrbdlab";
18 }
19 syncer {
20 rate 100M;
21 }
22 }
2.修改资源文件
# cd /etc/drbd.d/
# vim web.res
1 resource web {
2 on node1.a.com {
3 device /dev/drbd0;
4 disk /dev/sda4;
5 address 192.168.1.3:7789;
6 meta-disk internal;
7 }
8 on node2.a.com {
9 device /dev/drbd0;
10 disk /dev/sda4;
11 address 192.168.1.4:7789;
12 meta-disk internal;
13 }
14 }
3.创建资源
#drbdadm create-md web
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
4.启动服务、测试
# service drbd start
Starting DRBD resources: drbdsetup 0 show:5: delay-probe-volume 0k => 0k out of range [4..1048576]k.
# drbdadm adjust web //测试
drbdsetup 0 show:5: delay-probe-volume 0k => 0k out of range [4..1048576]k.
查看服务的情况
# service drbd status
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
m:res cs ro ds p mounted fstype
0:web Connected Secondary/Secondary Inconsistent/Inconsistent C
当然也可以使用下面的指令进行查看。
# drbd-overview
0:web Connected Secondary/Secondary Inconsistent/Inconsistent C r----
5.指定主设备
以下操作要求只是在一个节点上进行完成。笔者只在node1.a.com上进行完成,指定node1为主要的节点
# drbdadm -- --overwrite-data-of-peer primary web //指定node1为资源主节点
# watch -n 1 'cat /proc/drbd' //使用此命令,可以动态的查看具体的同步过程
# mkfs -t ext3 -L drbdweb /dev/drbd0 //格式化
# mkdir /web
# mount /dev/drbd0 /web //挂载
#
# service drbd status //在node1.a.com上查看状态
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
m:res cs ro ds p mounted fstype
0:web Connected Primary/Secondary UpToDate/UpToDate C /web ext3
#
切换到node2.a.com上进行查看
# service drbd status
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
m:res cs ro ds p mounted fstype
0:web Connected Secondary/Primary UpToDate/UpToDate C
#
三、NFS配置
两台服务器的nfs配置必须要一致。
1.修改相关文件
# vim /etc/exports
/web *(rw,sync,insecure,no_root_squash,no_wdelay)
2.执行相关操作。
#service portmap start && chkconfig portmap on
#service nfs start && chkconfig nfs on
3.修改nfs启动脚本
# vim /etc/init.d/nfs
122 killproc nfsd –9
四、Heartbeat配置
Heartbeat的配置要求两个节点的配置一致。在node1和node2上进行如下操作
1.复制模版文件
# cd /usr/share/doc/heartbeat-2.1.4/
# cp authkeys ha.cf haresources /etc/ha.d/
2.修改相关的配置信息
# cd /etc/ha.d/ //切换到相关目录
# vim ha.cf
24 debugfile /var/log/ha-debug
29 logfile /var/log/ha-log
34 logfacility local0
48 keepalive 2
56 deadtime 10
76 udpport 694
121 bcast eth0 //此行可以添加在任意一行
157 auto_failback off
211 node node1.a.com
212 node node2.a.com
3.修改资源文件
# echo "node1.a.com IPaddr::192.168.1.1/24/eth0 drbddisk::web Filesystem::/dev/drbd0::/web::ext3 killnfsd">>/etc/ha.d/haresources
4.修改key文件
# vim authkeys
23 auth 1
24 1 crc
5.手工创建文件
# cd /etc/ha.d/resource.d/
# echo "killall -9 nfsd ; /etc/init.d/nfs restart ; exit 0" >>/etc/ha.d/resource.d/killnfsd
6.修改配置文件的权限
# chmod 600 /etc/ha.d/authkeys
# chmod 755 /etc/ha.d/resource.d/killnfsd
7.启动服务
# service heartbeat start
五、测试
使用客户端进行测试
1.挂载
#mkdir /mnt/nfs
#mount 192.168.1.1:/web /mnt/nfs
#mount 192.168.1.1:/web /mnt/nfs
2.创建测试脚本文件
#vim /mnt/test.sh
//此配置脚本文件的主要作用是为了反复的读写操作
while true
do
echo --\>trying touch x:`date`
touch x
echo \<-----done touch x:`date`
echo
sleep 2
done
3.执行测试文件
#cd /mnt/nfs/
# bash /mnt/test.sh
--->trying touch x:Sun May 6 07:49:20 CST 2012
<-----done touch x:Sun May 6 07:49:20 CST 2012
--->trying touch x:Sun May 6 07:49:22 CST 2012
<-----done touch x:Sun May 6 07:49:22 CST 2012
--->trying touch x:Sun May 6 07:49:24 CST 2012
<-----done touch x:Sun May 6 07:49:24 CST 2012
--->trying touch x:Sun May 6 07:49:26 CST 2012
<-----done touch x:Sun May 6 07:49:26 CST 2012
--->trying touch x:Sun May 6 07:49:28 CST 2012
<-----done touch x:Sun May 6 07:49:30 CST 2012
--->trying touch x:Sun May 6 07:49:32 CST 2012
<-----done touch x:Sun May 6 07:49:32 CST 2012
--->trying touch x:Sun May 6 07:49:34 CST 2012
<-----done touch x:Sun May 6 07:49:34 CST 2012
--->trying touch x:Sun May 6 07:49:36 CST 2012
<-----done touch x:Sun May 6 07:49:36 CST 2012
//让客户端一直执行脚本文件,到服务器节点node1上关闭heartbeat服务,之后在客户端会发现丢弃现象,之后文件系统又恢复正常。
--->trying touch x:Sun May 6 07:50:22 CST 2012
<-----done touch x:Sun May 6 07:50:22 CST 2012
--->trying touch x:Sun May 6 07:50:24 CST 2012
touch: cannot touch `x': Stale NFS file handle
<-----done touch x:Sun May 6 07:50:30 CST 2012
--->trying touch x:Sun May 6 07:50:33 CST 2012
touch: cannot touch `x': Stale NFS file handle
<-----done touch x:Sun May 6 07:50:33 CST 2012
--->trying touch x:Sun May 6 07:50:35 CST 2012
touch: cannot touch `x': Stale NFS file handle
<-----done touch x:Sun May 6 07:50:35 CST 2012
--->trying touch x:Sun May 6 07:50:37 CST 2012
<-----done touch x:Sun May 6 07:50:37 CST 2012
--->trying touch x:Sun May 6 07:50:39 CST 2012
<-----done touch x:Sun May 6 07:50:39 CST 2012
转载于:https://blog.51cto.com/pheonix/856567