独立硬盘冗余阵列(RAID, Redundant Array of Independent Disks),旧称廉价磁盘冗余阵列(Redundant Array of Inexpensive Disks),简称磁盘阵列。其基本思想就是把多个相对便宜的硬盘组合起来,成为一个硬盘阵列组,使性能达到甚至超过一个价格昂贵、容量巨大的硬盘。根据选择的版本不同,RAID比单颗硬盘有以下一个或多个方面的好处:增强数据集成度,增强容错功能,增加处理量或容量。另外,磁盘阵列对于电脑来说,看起来就像一个单独的硬盘或逻辑存储单元。分为RAID-0,RAID-1,RAID-1E,RAID-5,RAID-6,RAID-7,RAID-10,RAID-50,RAID-60。—— [RAID - 维基百科]
-
实现方式:
- 外接式磁盘阵列:通过扩展卡提供适配能力
- 内接式RAID:主板集成RAID控制器
- 软件RAID:通过OS实现
-
实验内容:用虚拟机CentOS 7.3实现软RAID-10
-
实验条件:CentOS7.3虚拟机,添加四块硬盘
-
实验命令:
-
mdadm [mode] <raiddevice> [options] <component-devices
模式 | 主要功能 | 选项 |
---|---|---|
Create | 使用空闲的设备创建一个新的阵列,每个设备具有元数据块 | -C |
Manage | 管理已经存储阵列中的设备 | -f, -r, -a |
1、lsblk查看当前硬盘分区情况
可以看到sdb、sdc、sdd、sde未使用
[root@CentOS7 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 97.7G 0 part /
├─sda3 8:3 0 48.8G 0 part /app
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 2G 0 part [SWAP]
└─sda6 8:6 0 10G 0 part /home
sdb 8:16 0 50G 0 disk
sdc 8:32 0 50G 0 disk
sdd 8:48 0 50G 0 disk
sde 8:64 0 40G 0 disk
sr0 11:0 1 7.7G 0 rom
2、分区
由于RAID要求每块硬盘大小相同,而sde大小为40G,其他三块硬盘为50G。因此分别对sdb、sdc、sdd、sde划分分区,每个硬盘划分一个40G的分区,并修改Hex code为fd。
[root@CentOS7 ~]#fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x74a61da7.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-104857599, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +40G
Partition 1 of type Linux and of size 40 GiB is set
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): p
Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x74a61da7
Device Boot Start End Blocks Id System
/dev/sdb1 2048 83888127 41943040 fd Linux raid autodetect
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
其他硬盘分区 过程略,分区后如下:
[root@CentOS7 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 97.7G 0 part /
├─sda3 8:3 0 48.8G 0 part /app
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 2G 0 part [SWAP]
└─sda6 8:6 0 10G 0 part /home
sdb 8:16 0 50G 0 disk
└─sdb1 8:17 0 40G 0 part
sdc 8:32 0 50G 0 disk
└─sdc1 8:33 0 40G 0 part
sdd 8:48 0 50G 0 disk
└─sdd1 8:49 0 40G 0 part
sde 8:64 0 40G 0 disk
└─sde1 8:65 0 40G 0 part
sr0 11:0 1 7.7G 0 rom
3、创建RAID-1
sdb1、sdc1组成一组RAID-1,RAID设备名为/dev/md0
[root@CentOS7 sys]#mdadm -C /dev/md0 -a yes -l 1 -n 2 /dev/sd{c1,b1}
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store '/boot' on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
Continue creating array? yes
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
sdd1、sde1组成一组RAID-1,RAID设备名为/dev/md1
[root@CentOS7 sys]#mdadm -C /dev/md1 -a yes -l 1 -n 2 /dev/sdd1 /dev/sde1
...略
查看进度:
[root@CentOS7 sys]#cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 sde1[1] sdd1[0]
41909248 blocks super 1.2 [2/2] [UU]
[======>..............] resync = 32.9% (13801472/41909248) finish=2.2min speed=205884K/sec
md0 : active raid1 sdb1[1] sdc1[0]
41910272 blocks super 1.2 [2/2] [UU]
查看RAID信息:
[root@CentOS7 sys]#mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Mon Jun 26 20:22:24 2017
Raid Level : raid1
Array Size : 41910272 (39.97 GiB 42.92 GB)
Used Dev Size : 41910272 (39.97 GiB 42.92 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Mon Jun 26 20:25:54 2017
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Name : CentOS7.LMJ.com:0 (local to host CentOS7.LMJ.com)
UUID : 3d852350:c70e388a:ea33f443:37b1e32c
Events : 17
Number Major Minor RaidDevice State
0 8 33 0 active sync /dev/sdc1
1 8 17 1 active sync /dev/sdb1
4、创建RAID-0
用/dev/md0和/dev/md1创建RAID-0:
[root@CentOS7 sys]#mdadm -C /dev/md2 -a yes -l 0 -n 2 /dev/md{0,1}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md2 started.
5、生成配置文件
当raid重新启用时,会读取该配置文件
[root@CentOS7 sys]#mdadm -Ds /dev/md0 > /etc/mdadm.conf
[root@CentOS7 sys]#mdadm -Ds /dev/md1 >> /etc/mdadm.conf
[root@CentOS7 sys]#mdadm -Ds /dev/md2 >> /etc/mdadm.conf
[root@CentOS7 sys]#cat /etc/mdadm.conf
ARRAY /dev/md0 metadata=1.2 name=CentOS7.LMJ.com:0 UUID=3d852350:c70e388a:ea33f443:37b1e32c
ARRAY /dev/md1 metadata=1.2 name=CentOS7.LMJ.com:1 UUID=3ee6e29f:84b58d88:f19ba866:fdc451fa
ARRAY /dev/md2 metadata=1.2 name=CentOS7.LMJ.com:2 UUID=d27e4a09:17b5b2c1:0e82eb95:5833b5aa
6、创建文件系统
[root@CentOS7 sys]#mkfs.ext4 /dev/md2
7、挂载
[root@CentOS7 sys]#mount /dev/md2 /mnt/raid
[root@CentOS7 sys]#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 98G 4.4G 94G 5% /
devtmpfs 474M 0 474M 0% /dev
tmpfs 489M 84K 489M 1% /dev/shm
tmpfs 489M 14M 475M 3% /run
tmpfs 489M 0 489M 0% /sys/fs/cgroup
/dev/sda6 9.8G 138M 9.1G 2% /home
/dev/sda3 49G 36M 49G 1% /app
/dev/sda1 1014M 169M 846M 17% /boot
tmpfs 98M 16K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/0
/dev/md2 79G 57M 75G 1% /mnt/raid
[root@CentOS7 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 1G 0 part /boot
├─sda2 8:2 0 97.7G 0 part /
├─sda3 8:3 0 48.8G 0 part /app
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 2G 0 part [SWAP]
└─sda6 8:6 0 10G 0 part /home
sdb 8:16 0 50G 0 disk
└─sdb1 8:17 0 40G 0 part
└─md0 9:0 0 40G 0 raid1
└─md2 9:2 0 79.9G 0 raid0
sdc 8:32 0 50G 0 disk
└─sdc1 8:33 0 40G 0 part
└─md0 9:0 0 40G 0 raid1
└─md2 9:2 0 79.9G 0 raid0
sdd 8:48 0 50G 0 disk
└─sdd1 8:49 0 40G 0 part
└─md1 9:1 0 40G 0 raid1
└─md2 9:2 0 79.9G 0 raid0
sde 8:64 0 40G 0 disk
└─sde1 8:65 0 40G 0 part
└─md1 9:1 0 40G 0 raid1
└─md2 9:2 0 79.9G 0 raid0
sr0 11:0 1 7.7G 0 rom
网友评论