分类: LINUX
2012-07-05 16:30:08
红帽企业存储管理之DRBD应用详解
软件包下载地址:
DRBD基础知识详解(概念和安装)
DRBD在企业网络中的应用
一.案例应用背景
在方案中,通过DRBD保证了服务器数据的完整性和一致性。DRBD类似于一个网络RAID-1功能。当你将数据写入本地文件系统时,数据还将会被发送到网络中另一台主机上,以相同的形式记录在一个另文件系统中。主节点与备节点的数据可以保证实时相互同步。当本地主服务器出现故障时,备份服务器上还会保留有一份相同的数据,可以继续使用。
二.案例应用简化拓扑图
软件包下载地址:
三.案例应用具体实现步骤:
1. 基本配置
1.1 node1基本配置&新建磁盘
1.1.1查看系统信息,同步时间
[root@node1 ~]# uname -rv
2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:54 EDT 2009
[root@node1 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
[root@node1 ~]# hwclock -s
[root@node1 ~]# date
Wed Feb 8 13:55:50 CST 2012
1.1.2查看主机名称,修改查看ip地址
[root@node1 ~]# hostname
node1.junjie.com
[root@node1 ~]# cat /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=node1.junjie.com
[root@node1 ~]#setup
[root@node1 ~]# service network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
[root@node1 ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:AE:83:D1
inet addr:192.168.101.211 Bcast:192.168.101.255 Mask:255.255.255.0
1.1.3配置/etc/hosts文件(就不用dns了)
[root@node1 ~]# echo "192.168.101.211 node1.junjie.com node1" >>/etc/hosts
[root@node1 ~]# echo "192.168.101.212 node2.junjie.com node2" >>/etc/hosts
1.1.4构建一个新的磁盘空间有利于实现DRBD技术
[root@node1 ~]# fdisk -l
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 1318 10482412+ 83 Linux
/dev/sda3 1319 1579 2096482+ 82 Linux swap / Solaris
[root@node1 ~]# fdisk /dev/sda
p/n/p//+1000M/p/w
[root@node1 ~]# fdisk -l
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 1318 10482412+ 83 Linux
/dev/sda3 1319 1579 2096482+ 82 Linux swap / Solaris
/dev/sda4 1580 1702 987997+ 83 Linux
[root@node1 ~]# partprobe /dev/sda
[root@node1 ~]# cat /proc/partitions
major minor #blocks name
8 0 20971520 sda
8 1 104391 sda1
8 2 10482412 sda2
8 3 2096482 sda3
8 4 987997 sda4
1.2 node2基本配置&新建磁盘
1.2.1查看系统信息,同步时间
2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:54 EDT 2009
[root@node2 ~]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
1.2.2查看主机名称,修改查看ip地址
[root@node2 ~]# cat /etc/sysconfig/network
[root@node2 ~]# service network restart
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
[root@node2 ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 00:0C:29:D1:D4:32
inet addr:192.168.101.212 Bcast:192.168.101.255 Mask:255.255.255.0
1.2.3配置/etc/hosts文件(就不用dns了)
[root@node2 ~]# echo "192.168.101.211 node1.junjie.com node1" >>/etc/hosts
[root@node2 ~]# echo "192.168.101.212 node2.junjie.com node2" >>/etc/hosts
1.2.4构建一个新的磁盘空间有利于实现DRBD技术
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 1318 10482412+ 83 Linux
/dev/sda3 1319 1579 2096482+ 82 Linux swap / Solaris
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 1318 10482412+ 83 Linux
/dev/sda3 1319 1579 2096482+ 82 Linux swap / Solaris
/dev/sda4 1580 1702 987997+ 83 Linux
[root@node2 ~]# cat /proc/partitions
major minor #blocks name
8 0 20971520 sda
8 1 104391 sda1
8 2 10482412 sda2
8 3 2096482 sda3
8 4 987997 sda4
1.3 在node1和node2上配置ssh密钥信息,
1.3.1 在node1上配置ssh密钥信息
[root@node1 ~]# ssh-keygen -t rsa
[root@node1 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node2.junjie.com
1.3.2 在node2上配置ssh密钥信息
[root@node2 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node2.junjie.com
2、DRBD安装配置
2.1、安装DRBD 套件
[root@node1 ~]# rpm -ivh drbd83-8.3.8-1.el5.centos.i386.rpm
[root@node1 ~]# rpm -ivh kmod-drbd83-8.3.8-1.el5.centos.i686.rpm
[root@node2 ~]# rpm -ivh drbd83-8.3.8-1.el5.centos.i386.rpm
[root@node2 ~]# rpm -ivh kmod-drbd83-8.3.8-1.el5.centos.i686.rpm
[root@node1 ~]# modprobe drbd
[root@node1 ~]# lsmod | grep drbd
[root@node1 ~]#
[root@node2 ~]# modprobe drbd
[root@node2 ~]# lsmod | grep drbd
[root@node2 ~]#
2.3、修改配置文件
drbd.conf配置文件DRBD运行时,会读取一个配置文件/etc/drbd.conf.这个文件里描述了DRBD设备与硬盘分区的映射关系
[root@node1 ~]# cd /etc/drbd.d/
[root@node1 drbd.d]# ll
total 4
-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
2.3.2 复制配置到node2上:
[root@node1 drbd.d]# scp /etc/drbd.conf node2:/etc/
drbd.conf 100% 133 0.1KB/s 00:00
[root@node1 drbd.d]# scp /etc/drbd.d/* node2:/etc/drbd.d/
global_common.conf 100% 427 0.4KB/s 00:00
global_common.conf.bak 100% 1418 1.4KB/s 00:00
nfs.res 100% 330 0.3KB/s 00:00
[root@node1 drbd.d]#
2.4、 检测配置文件
// 检测配置文件
[root@node1 drbd.d]# drbdadm adjust nfs
0: Failure: (119) No valid meta-data signature found.
==> Use 'drbdadm create-md res' to initialize meta-data area. <==
Command 'drbdsetup 0 disk /dev/sda4 /dev/sda4 internal --set-defaults --create-device --fencing=resource-only --on-io-error=detach' terminated with exit code 10
[root@node1 drbd.d]# drbdadm adjust nfs
drbdsetup 0 show:5: delay-probe-volume 0k => 0k out of range [4..1048576]k.
[root@node1 drbd.d]#
2.5、创建nfs 的资源
2.5.1 在node1上创建nfs 的资源
[root@node1 drbd.d]# drbdadm create-md nfs
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
[root@node1 drbd.d]# ll /dev/drbd0
brw-r----- 1 root disk 147, 0 Feb 8 14:27 /dev/drbd0
2.5.2 在node2上创建nfs 的资源
[root@node1 drbd.d]# ssh node2.junjie.com 'drbdadm create-md nfs'
NOT initialized bitmap
Writing meta data...
initializing activity log
New drbd meta data block successfully created.
[root@node1 drbd.d]# ssh node2.junjie.com 'ls -l /dev/drbd0'
brw-r----- 1 root disk 147, 0 Feb 8 14:19 /dev/drbd0
2.6 启动DRBD服务
[root@node1 drbd.d]# service drbd start
Starting DRBD resources: drbdsetup 0 show:5: delay-probe-volume 0k => 0k out of range [4..1048576]k.
[root@node1 drbd.d]# ssh node2.junjie.com 'service drbd start'
Starting DRBD resources: drbdsetup 0 show:5: delay-probe-volume 0k => 0k out of range [4..1048576]k.
[root@node1 drbd.d]#
2.7 启动DRBD服务,查看DRBD状态
[root@node1 drbd.d]# 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:nfs Connected Secondary/Secondary Inconsistent/Inconsistent C
[root@node1 drbd.d]# ssh node2.junjie.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:nfs Connected Secondary/Secondary Inconsistent/Inconsistent C
[root@node1 drbd.d]#
[root@node1 drbd.d]# drbd-overview
0:nfs Connected Secondary/Secondary Inconsistent/Inconsistent C r----
[root@node1 drbd.d]# ssh node2.junjie.com 'drbd-overview'
0:nfs Connected Secondary/Secondary Inconsistent/Inconsistent C r----
[root@node1 drbd.d]#
[root@node1 drbd.d]# chkconfig drbd on
[root@node1 drbd.d]# chkconfig --list drbd
drbd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@node1 drbd.d]# ssh node2.junjie.com 'chkconfig drbd on'
[root@node1 drbd.d]# ssh node2.junjie.com 'chkconfig --list drbd'
drbd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
2.8 在node1主节点上进行以下配置,并查看挂载信息。
[root@node1 drbd.d]# mkdir /mnt/nfs
[root@node1 drbd.d]# ssh node2.junjie.com 'mkdir /mnt/nfs'
[root@node1 drbd.d]# drbdsetup /dev/drbd0 primary -o
[root@node1 drbd.d]# mkfs.ext3 /dev/drbd0
[root@node1 drbd.d]# mount /dev/drbd0 /mnt/nfs/
[root@node1 drbd.d]# drbdadm role nfs
Primary/Secondary
[root@node1 drbd.d]# ssh node2.junjie.com 'drbdadm role nfs'
Secondary/Primary
[root@node1 drbd.d]# ll /mnt/nfs/
total 16
drwx------ 2 root root 16384 Feb 8 14:57 lost+found
[root@node1 drbd.d]# echo "20120508" >> /mnt/nfs/f1
[root@node1 drbd.d]# drbdadm secondary nfs
0: State change failed: (-12) Device is held open by someone
Command 'drbdsetup 0 secondary' terminated with exit code 11
[root@node1 drbd.d]# umount /mnt/nfs/
[root@node1 drbd.d]# drbdadm secondary nfs
[root@node1 drbd.d]# drbdadm role nfs
Secondary/Secondary
[root@node1 drbd.d]# ssh node2.junjie.com 'drbdadm role nfs'
Secondary/Secondary
[root@node1 drbd.d]# ssh node2.junjie.com 'drbdadm primary nfs'
[root@node1 drbd.d]# ssh node2.junjie.com 'drbdadm role nfs'
Primary/Secondary
[root@node1 drbd.d]# drbdadm role nfs
Secondary/Primary
[root@node1 drbd.d]# ssh node2.junjie.com 'mount /dev/drbd0 /mnt/nfs'
[root@node1 drbd.d]# ssh node2.junjie.com 'ls -l /mnt/nfs'
total 20
-rw-r--r-- 1 root root 9 Feb 8 15:32 f1
drwx------ 2 root root 16384 Feb 8 14:57 lost+found
[root@node1 drbd.d]# ssh node2.junjie.com 'cat /mnt/nfs/f1'
20120508
[root@node1 drbd.d]# ssh node2.junjie.com 'echo "--xj" >>/mnt/nfs/f1'
[root@node1 drbd.d]# ssh node2.junjie.com 'cat /mnt/nfs/f1'
20120508
--xj
[root@node1 drbd.d]# ssh node2.junjie.com 'touch /mnt/nfs/f2'
[root@node1 drbd.d]# ssh node2.junjie.com 'ls -l /mnt/nfs'
total 20
-rw-r--r-- 1 root root 14 Feb 8 15:34 f1
-rw-r--r-- 1 root root 0 Feb 8 15:34 f2
drwx------ 2 root root 16384 Feb 8 14:57 lost+found
[root@node1 drbd.d]#
[root@node1 drbd.d]# ssh node2.junjie.com 'umount /mnt/nfs'
[root@node1 drbd.d]# ssh node2.junjie.com 'drbdadm secondary nfs'
[root@node1 drbd.d]# ssh node2.junjie.com 'drbdadm role nfs'
Secondary/Secondary
[root@node1 drbd.d]# drbdadm primary nfs
[root@node1 drbd.d]# drbdadm role nfs
Primary/Secondary
[root@node1 drbd.d]# mount /dev/drbd0 /mnt/nfs/
[root@node1 drbd.d]# ll /mnt/nfs/
total 20
-rw-r--r-- 1 root root 14 Feb 8 15:34 f1
-rw-r--r-- 1 root root 0 Feb 8 15:34 f2
drwx------ 2 root root 16384 Feb 8 14:57 lost+found
[root@node1 drbd.d]# cat /mnt/nfs/f1
20120508
--xj
[root@node1 drbd.d]#
[root@node1 drbd.d]# drbd-overview
0:nfs Connected Primary/Secondary UpToDate/UpToDate C r---- /mnt/nfs ext3 950M 18M 885M 2%
[root@node1 drbd.d]# ssh node2.junjie.com 'drbd-overview'
0:nfs Connected Secondary/Primary UpToDate/UpToDate C r----
[root@node1 drbd.d]#
《完》
--xjzhujunjie
--2012/05/08