RAID可以透过一个技术(软件或硬件),将多个较小的磁盘整合成为一个较大的磁盘装置;而这个较大的磁盘功能不只是存储,还具有数据保护的功能。RAID选择的level不同,使得整合后的磁盘具有不同的功能。
常见的level: RAID-0(等量模式):性能最佳 RAID-1(映像模式):完整备份 RAID 0+1
RAID 5:性能与数据备份的均衡考虑 Spare Disk:预备磁盘的功能
磁盘阵列的优点: 当磁盘损毁时,数据能够安全的恢复 RAID 0可以加强读写性能 可以让多个磁盘组合起来,单一的文件系统可以有相当大的容量
软件磁盘阵列的设定:
设定很简单,只要使用mdadm这个指令即可。
我实验的环境都是在vmware下进行的,所以添加一块10G的硬盘(这个应该很简单)做测试
[Shell] 纯文本查看 复制代码
[iyunv@minilinux ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006bd09
Device Boot Start End Blocks Id System
/dev/sda1 * 1 2481 19921920 83 Linux
/dev/sda2 2481 2611 1046529 5 Extended
/dev/sda5 2481 2611 1046528 82 Linux swap / Solaris
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb8b17d21
Device Boot Start End Blocks Id System
我希望做成的RAID 5环境: 利用4个partition组成RAID 5 每个partition约为1G,需确定每个partition一样大 利用1个partition设定为spare disk 这个spare disk的大小与其他RAID所需partition一样大 将此RAID 5装置挂载到/mnt/raid目录下
建立所需的磁盘装置: [Shell] 纯文本查看 复制代码 需要5个1G的分区
[iyunv@minilinux ~]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +1G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (133-1305, default 133):
Using default value 133
Last cylinder, +cylinders or +size{K,M,G} (133-1305, default 1305): +1G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (265-1305, default 265):
Using default value 265
Last cylinder, +cylinders or +size{K,M,G} (265-1305, default 1305): +1G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First cylinder (397-1305, default 397):
Using default value 397
Last cylinder, +cylinders or +size{K,M,G} (397-1305, default 1305):
Using default value 1305
Command (m for help): n
First cylinder (397-1305, default 397):
Using default value 397
Last cylinder, +cylinders or +size{K,M,G} (397-1305, default 1305): +1G
Command (m for help): n
First cylinder (529-1305, default 529):
Using default value 529
Last cylinder, +cylinders or +size{K,M,G} (529-1305, default 1305): +1G
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb8b17d21
Device Boot Start End Blocks Id System
/dev/sdb1 1 132 1060258+ 83 Linux
/dev/sdb2 133 264 1060290 83 Linux
/dev/sdb3 265 396 1060290 83 Linux
/dev/sdb4 397 1305 7301542+ 5 Extended
/dev/sdb5 397 528 1060258+ 83 Linux
/dev/sdb6 529 660 1060258+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
1
[iyunv@minilinux ~]# partprobe
用mdadm建立RAID:
通过mdadm建立磁盘阵列
[iyunv@minilinux ~]# mdadm --create --auto=yes /dev/md0 --level=5 \
> --raid-devices=4 --spare-devices=1 /dev/sdb{1,2,3,5,6}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
查看阵列信息
[iyunv@minilinux ~]# mdadm --detail /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Tue Jul 9 16:51:39 2013
Raid Level : raid5
Array Size : 3176448 (3.03 GiB 3.25 GB)
Used Dev Size : 1058816 (1034.17 MiB 1084.23 MB)
Raid Devices : 4
Total Devices : 5
Persistence : Superblock is persistent
Update Time : Tue Jul 9 16:51:59 2013
State : clean
Active Devices : 4
Working Devices : 5
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Name : minilinux:0 (local to host minilinux)
UUID : 79a8d5ba:b04180ca:a72133ce:358877a4
Events : 18
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 18 1 active sync /dev/sdb2
2 8 19 2 active sync /dev/sdb3
5 8 21 3 active sync /dev/sdb5
4 8 22 - spare /dev/sdb6
注:RaidDevice指的就是在此RAID内的磁盘顺序
也可以通过/proc/mdstat查看磁盘阵列信息
[iyunv@minilinux ~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdb5[5] sdb6[4](S) sdb3[2] sdb2[1] sdb1[0]
3176448 blocks super 1.2 level 5, 512k chunk, algorithm 2 [4/4] [UUUU]
总共有3行,主要解释后两行。
第二行:指出md0为raid5 使用了sdb1 sdb2 sdb3 sdb5 sdb6 5个磁盘分区。每个分区后面中括号[]内的数字为此磁盘在RAID中的顺序(RaidDevice),sdb6[4]后面的[S]代表spare.
第三行:此磁盘阵列有3176448个block(每个block单位为1K),使用RAID 5,写入磁盘的小区块(chunk)大小为512K,使用algorithm 2磁盘阵列算法。[m/n]代表此磁盘阵列需要m个分区,且n个分区正常工作。此md0需要4个分区且4个分区都正常工作。后面的[UUUU]代表4个所需的分区的启动情况,U代表正常工作,若为_则代表不正常。
格式化与挂载使用RAID:
格式化/dev/md0
[iyunv@minilinux ~]# mkfs -t ext4 /dev/md0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=384 blocks
198800 inodes, 794112 blocks
39705 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=813694976
25 block groups
32768 blocks per group, 32768 fragments per group
7952 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
挂载/dev/md0
[iyunv@minilinux ~]# mkdir /mnt/raid
[iyunv@minilinux ~]# mount /dev/md0 /mnt/raid
[iyunv@minilinux ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 19609276 1340880 17272300 8% /
tmpfs 118188 0 118188 0% /dev/shm
/dev/md0 3126500 70192 2897488 3% /mnt/raid
发现多个一个/dev/md0的装置
|