Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5352190
  • 博文数量: 1144
  • 博客积分: 11974
  • 博客等级: 上将
  • 技术积分: 12312
  • 用 户 组: 普通用户
  • 注册时间: 2005-04-13 20:06
文章存档

2017年(2)

2016年(14)

2015年(10)

2014年(28)

2013年(23)

2012年(29)

2011年(53)

2010年(86)

2009年(83)

2008年(43)

2007年(153)

2006年(575)

2005年(45)

分类: LINUX

2006-03-06 20:40:45

Software Raid-[0,1,5]学习笔记


RAID 0

This level of RAID makes it faster to read and write to the hard drives. However, RAID 0 provides no data redundancy. It requires at least two hard disks.

Reads and writes to the hard disks are done in parallel, in other words, to two or more hard disks simultaneously. All hard drives in a RAID 0 array are filled equally. But since RAID 0 does not provide data redundancy, a failure of any one of the drives will result in total data loss. RAID 0 is also known as 'striping without parity.'

特征:并行读写数据,性能高,但没有数据冗余,阵列中任何一个硬盘坏掉,意味着所有数据丢失
容量:所有硬盘容量之和
条件:至少两块硬盘,做为RAID的分区大小必须是几乎相同的.

首先将各个分区的分区类型标识为FD:
[root@LFS ~]#fdisk /dev/hda
 Command (m for help):t
Partition number (1-4):1
Hex code (type L to list codes):fd
Changed system type of partition 1 to fd (Linux raid autodetect)
 Command (m for help):p
/dev/hda1       1       646  325552+  fd  Linux raid autodetect

使用raidtools-1.00.3创建raid-0:

编写raid的配置文件/etc/raidtab:
在/usr/share/doc/raidtools-1.00.3下有样例文件

raiddev /dev/md0
raid-level 0
nr-raid-disks 2
nr-spare-disks 0
persistent-superblock 1
chunk-size 4

device  /dev/hda1
raid-disk 0
device  /dev/hdb1
raid-disk 1

mkraid依据raidtab创建raid:
[root@LFS ~]#mkraid /dev/md0
......
raid0: done.
raid0 : md_size is 650880 blocks
raid0 : conf ->hash_spacing is 650880 blocks
raid0 : nb_zone is 1.
raid0 : Allocating 4 byte for hash

使用mdadm创建raid-0:
[root@LFS ~]#mdadm --create --verbose /dev/md0 --level=raid0 \
--raid-devices=2 --chunk=4  /dev/hda1 /dev/hdb1
......
raid0: done.
raid0 : md_size is 650880 blocks
raid0 : conf ->hash_spacing is 650880 blocks
raid0 : nb_zone is 1.
raid0 : Allocating 4 byte for hash
mdadm: array /dev/md0 started .
[root@LFS ~]#

查看状态:
[root@LFS ~]#cat /proc/mdstat
Personalities : [raid0]
md0 : active raid0 hdb1[1] hda1[0]
       650880 blocks 4k rounding

unused devices:
[root@LFS ~]#

创建文件系统,挂载:
[root@LFS ~]#mkreiserfs /dev/md0
[root@LFS ~]#mount -t reiserfs /dev/md0 /mnt/raid0

加入到/etc/fstab,系统启动自动挂载:
/dev/md0      /mnt/raid0   reiserfs    defaults     1  2

 Commands in raidtab

Command

Description

nr-raid-disks

Number of RAID disks to use

nr-spare-disks

Number of spare disks to use

persistent-superblock

Required for autodetection

chunk-size

Amount of data to read/write

parity-algorithm

How RAID 5 should use parity


 

RAID 1

This level of RAID mirrors information to two or more other disks. In other words, the same set of information is written to two different hard disks. If one disk is damaged or removed, you still have all of the data on the other hard disk. The disadvantage of RAID 1 is that data has to be written twice, which can reduce performance. You can come close to maintaining the same level of performance if you also use separate hard disk controllers. That prevents the hard disk controller from becoming a bottleneck.

<>And it is expensive. To support RAID 1, you need an additional hard disk for every hard disk worth of data. RAID 1 is also known as disk mirroring.

特征:数据冗余,可靠性强。任何一块硬盘坏掉,不会丢失数据。写入慢,读取快。
容量:所有硬盘容量/2
条件:至少两块硬盘,做为RAID的分区大小必须是几乎相同的.

raidtools-1.00.3:

编写/etc/raidtab :

raiddev /dev/md1
raid-level 1
nr-raid-disks 2
nr-spare-disks 1
persistent-superblock 1
chunk-size 4

device  /dev/hda2
raid-disk 0
device  /dev/hdb2
raid-disk 1
device  /dev/hdc2
spare-disk 0
[root@LFS ~]#mkraid /dev/md1

使用mdadm创建raid-1:
[root@LFS ~]#mdadm --create --verbose /dev/md1 --level=raid1 \
--raid-devices=2 --spare-devices=1 --chunk=4  /dev/hda2 /dev/hdb2 /dev/hdc2

[root@LFS ~]#cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 hdc2[2] hdb2[1] hda2[0]
       325440 blocks  [2/2] [UU]

unused devices:
[root@LFS ~]#mkreiserfs /dev/md1
[root@LFS ~]#mount -t reiserfs /dev/md1 /mnt/raid1

device  /dev/hdc2
spare-disk 0
表示用/dev/hdc2做为spare disk,当hda2或hdb2坏掉时,raid会自动启用/dev/hdc2做为镜像.

特征:采用奇偶效验,可靠性强。只有当两块硬盘坏掉时才会丢失数据。并行读写数据,性能也很高。
容量:所有硬盘容量-1
条件:至少三块硬盘,做为RAID的分区大小必须是几乎相同的。

使用raidtools-1.00.3创建raid-5:

编写/etc/raidtab:

raiddev /dev/md5
raid-level 5
nr-raid-disks 3
nr-spare-disks 0
persistent-superblock 1
chunksize 32

parity-algorithm left-symmetric
device  /dev/hda3
raid-disk 0
device  /dev/hdb3
raid-disk 1
device  /dev/hdc3
raid-disk 2
[root@LFS ~]#mkraid /dev/md5

使用mdadm创建raid-5:
[root@LFS ~]#mdadm --create --verbose /dev/md5 --level=raid5 \
--raid-devices=3 --chunk=32 /dev/hda3 /dev/hdb3 /dev/hdc3
[root@LFS ~]#mkreiserfs /dev/md5
[root@LFS ~]#mount -t reiserfs /dev/md5 /mnt/raid5

parity-algorithm left-symmetric
parity-algorithm表示raid5的奇偶效验的运算法则,可用选择有:
left-symmetric  left-asymmetric
right-symmetric right-asymmetric
最佳性能的是:left-symmetric

LVM+RAID :
LVM的物理卷(PV)可以是标准硬盘分区也可以是RAID设备,因此可以在RAID上使用LVM管理分区。
创建PV:
[root@LFS ~]#pvcreate /dev/md5
Physical volume "/dev/md5" successfully created
创建VG:
[root@LFS ~]#vgcreate raid_lvm /dev/md5
Volume group "raid_lvm" successfully created
创建LV:
[root@LFS ~]#lvcreate -L 300M -n "lv_data" raid_lvm
Logical volume "lv_data" created
创建reiserfs:
[root@LFS ~]#mkreiserfs /dev/raid_lvm/lv_data
[root@LFS ~]#mkdir /mnt/data
[root@LFS ~]#mount -t reiserfs /dev/raid_lvm/lv_data /mnt/data

About chunk-size :

The chunk-size deserves an explanation. You can never write completely parallel to a set of disks. If you had two disks and wanted to write a byte, you would have to write four bits on each disk, actually, every second bit would go to disk 0 and the others to disk 1. Hardware just doesn't support that. Instead, we choose some chunk-size, which we define as the smallest "atomic" mass of data that can be written to the devices. A write of 16 kB with a chunk size of 4 kB, will cause the first and the third 4 kB chunks to be written to the first disk, and the second and fourth chunks to be written to the second disk, in the RAID-0 case with two disks. Thus, for large writes, you may see lower overhead by having fairly large chunks, whereas arrays that are primarily holding small files may benefit more from a smaller chunk size.

The argument to the chunk-size option in /etc/raidtab specifies the chunk-size in kilobytes. So "4" means "4 kB".

补充几个问题:
Q:如何得知当前内核是否支持RAID?
A:cat /proc/mdstat 有输出信息则表示内核已经支持
或者dmesg |grep -i raid    dmesg |grep -i md 都可以看到。

Q:如何得知当前内核支持哪几种RAID?
A:安装当前内核源码包,将当前内核配置文件cp到内核源码目录下
cp /boot/config-xxx /usr/src/linux && make menuconfig
看看Device Drivers --->Multi-device support (RAID and LVM)这里的选项就知道了。
或者cat /lib/modules/`uname -r`/modules.alias |grep raid0
raid0为查看的级别:raid1,raid5...
如果有输出则表示内核已经支持,并且/必须是做为模块加载的。

Q:raidtool和mdadm应该使用哪个?哪里有下载?
A:mdadm可能更方便一些。mdadm与raidtool的区别:
The  key differences between mdadm and raidtools are:
      
       mdadm is a single program and not a collection of programs.

       mdadm can perform (almost) all of its functions without having
           a  configuration  file  and does not use one by default.  Also
       mdadm helps with management of the configuration file.

       mdadm can  provide  information  about  your  arrays  (through
           Query, Detail, and Examine) that raidtools cannot.

       mdadm does not use /etc/raidtab, the raidtools configuration file,
       at all.  It has a different configuration file  with  a  different
       format and an different purpose.
另外我看的这本书里,讲解的是raidtool,这是在RHEL3中所使用的,但是我在RHEL4中做这个lab
发现四张盘里没有raidtool,只有mdadm,看来RH也是偏向于使用mdadm的 :)
下载地址:
mdadm:
~neilb/source/mdadm/RPM/
~neilb/source/mdadm/
raidtool:
ftp://194.199.20.114/linux/fedora/core/2/i386/os/Fedora/RPMS/raidtools-1.00.3-8.i386.rpm

OK,这个lab完成啦。
有机会一定要在真实硬盘上试试raid-0+lvm+reiserfs,看看是什么感觉 ^_^

 

阅读(932) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~