通过几篇文章的介绍,来到了RAID的学习,本篇文章将介绍RAID,以及学会创建RAID,并且使用它,下面就进入学习吧。
RAID是“Redundant Array of Independent Disk”的缩写,中文意思是独立冗余磁盘阵列。冗余磁盘阵列技术诞生于1987年,由美国加州大学伯克利分校提出。简单地解释,就是将N台硬盘通过RAID Controller(分Hardware,Software)结合成虚拟单台大容量的硬盘使用。RAID的采用为存储系统(或服务器的内置存储)带来巨大利益,其中提高和传输速率提供容错功能是最大的优点。
RAID0 条带集 2块磁盘以上,读写速率快100%*N,单不容错。
RAID1 镜像集 2块磁盘,容量50%,读写速率一般,容错
RAID5 带奇偶校检条带集 3块磁盘以上,利用率(n-1)/n读写速率块,容错,一份数据产生N-1个条带,同时还有一份校验数据,共N份数据在N盘上循环均衡存储
N快盘同时读写,读写性很高,但由于校验机制,写性能不是很高,可靠性高,但是只允许1快盘坏,不影响所有数据
。
通过ll /dev/sd*查看已有磁盘。
通过lsblk查看磁盘操作信息,注意创建RAID必须要用没有任何操作的原始磁盘或者分区。
//检查是否安装mdadm
命令:yum -y install mdadm
//创建RAID名为md1,它由sde,sdg,sdh,sdi组成
命令:mdadm -C /dev/md1 -l5 -n3 -x1 /dev/sd{e,g,h,i}
各字段的详解:
- -C:创建RAID
- /dev/md0:第一个RAID设备
- -l5:RAID5
- -n:RAID成员的数量
- -x:热备磁盘的数量
- 可用空间2G
代码如下(示例):
- [root@localhost ~]# yum -y install mdadm
- 已加载插件:fastestmirror, langpacks
- Loading mirror speeds from cached hostfile
- Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
- 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"
-
-
- One of the configured repositories failed (未知),
- and yum doesn't have enough cached data to continue. At this point the only
- safe thing yum can do is fail. There are a few ways to work "fix" this:
- 1. Contact the upstream for the repository and get them to fix the problem.
- 2. Reconfigure the baseurl/etc. for the repository, to point to a working
- upstream. This is most often useful if you are using a newer
- distribution release than is supported by the repository (and the
- packages for the previous distribution release still work).
- 3. Run the command with the repository temporarily disabled
- yum --disablerepo=
... -
- 4. Disable the repository permanently, so yum won't use it by default. Yum
- will then just ignore the repository until you permanently enable it
- again or use --enablerepo for temporary usage:
-
- yum-config-manager --disable
- or
- subscription-manager repos --disable=
-
- 5. Configure the failing repository to be skipped, if it is unavailable.
- Note that yum will try to contact the repo. when it runs most commands,
- so will have to try and fail each time (and thus. yum will be be much
- slower). If it is a very temporary problem though, this is often a nice
- compromise:
-
- yum-config-manager --save --setopt=
.skip_if_unavailable=true -
- Cannot find a valid baseurl for repo: base/7/x86_64
-
- [root@localhost ~]# mdadm -C /dev/md0 -l5 -n3 -x1 /dev/sd{f,g,h,i}
- mdadm:Defaulting to version 1.2 metadata
- mdadm:arrt /dev/md1 started.
命令和分区的格式化挂载一致。
mkfs.ext4 /dev/md1
- [root@localhost ~]# mkfs.ext4 /dev/md1
- mke2fs 1.42.9 (28-Dec-2013)
- 文件系统标签=
- OS type: Linux
- 块大小=4096 (log=2)
- 分块大小=4096 (log=2)
- Stride=128 blocks, Stripe width=256 blocks
- 655360 inodes, 2618880 blocks
- 130944 blocks (5.00%) reserved for the super user
- 第一个数据块=0
- Maximum filesystem blocks=2151677952
- 80 block groups
- 32768 blocks per group, 32768 fragments per group
- 8192 inodes per group
- Superblock backups stored on blocks:
- 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
-
- Allocating group tables: 完成
- 正在写入inode表: 完成
- Creating journal (32768 blocks): 完成
- Writing superblocks and filesystem accounting information: 完成
命令:mount /dev/md1 /mnt/raid5 //raid5是之前创建的一个目录
如图df -hT查看挂载信息,有md1的挂载信息挂载点是raid5。
命令: mdadm -D /dev/md0 //-D查看详细信息
- [root@localhost ~]# mdadm -D /dev/md1
- /dev/md0:
- Version : 1.2
- Creation Time : Wed Oct 26 14:36:41 2022
- Raid Level : raid5 //raid类型
- Array Size : 10475520 (9.99 GiB 10.73 GB)
- Used Dev Size : 5237760 (5.00 GiB 5.36 GB)
- Raid Devices : 3 //组中设备数量
- Total Devices : 4 //总设备数
- Persistence : Superblock is persistent
-
- Update Time : Wed Oct 26 14:58:11 2022
- State : clean //状态
- Active Devices : 3 //活跃3个
- Working Devices : 4 //4个在工作
- Failed Devices : 0 //损坏数量,坏一个危险,坏两个就完蛋
- Spare Devices : 1 //热备1个
-
- Layout : left-symmetric
- Chunk Size : 512K //校检码大小
-
- Consistency Policy : resync
-
- Name : localhost.localdomain:0 (local to host localhost.localdomain)
- UUID : d7c102bb:390cd8ce:041cc2a9:9dc9b741
- Events : 18
-
- Number Major Minor RaidDevice State
- 0 8 64 0 active sync /dev/sde //同步
- 1 8 96 1 active sync /dev/sdg //同步
- 4 8 112 2 active sync /dev/sdh /同步
-
- 3 8 128 - spare /dev/sdi //热备
命令:[root@localhost ~]# mdadm /dev/md1 -f /dev/sde -r /dev/sde
- -f fial
- -r remove
如图可以看出热备磁盘的作用,当一个磁盘损坏,热备磁盘胡替补原来磁盘的位置成为数据磁盘,同时恢复原本磁盘内的数据信息。
命令:umount /dev/md1 //一定要卸载
挂载信息没有md1的挂载信息,卸载成功!
命令:mdadm -S /dev/md1
- [root@localhost ~]# mdadm -S /dev/md1
- mdadm: stopped /dev/md1
命令:mdadm --zero-superblock /dev/sd{g,h,i}
- [root@localhost ~]# mdadm --zero-superblock /dev/sd{g,h,i}
- [root@localhost ~]# lsblk
- NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
- md0 9:0 0 10G 0 raid5
- sda 8:0 0 20G 0 disk
- ├─sda1 8:1 0 1000M 0 part /boot
- └─sda2 8:2 0 19G 0 part
- ├─centos-root 253:0 0 17G 0 lvm /
- └─centos-swap 253:1 0 2G 0 lvm [SWAP]
- sdb 8:16 0 5G 0 disk
- ├─sdb1 8:17 0 2G 0 part
- ├─sdb2 8:18 0 200M 0 part
- ├─sdb3 8:19 0 200M 0 part
- ├─sdb4 8:20 0 1K 0 part
- ├─sdb5 8:21 0 200M 0 part
- └─sdb6 8:22 0 2.4G 0 part
- sdc 8:32 0 5G 0 disk
- └─sdc1 8:33 0 2G 0 part
- sdd 8:48 0 5G 0 disk
- └─vg1-lv1 253:2 0 8G 0 lvm
- sde 8:64 0 5G 0 disk
- sdf 8:80 0 5G 0 disk
- └─vg1-lv1 253:2 0 8G 0 lvm
- sdg 8:96 0 5G 0 disk
- sdh 8:112 0 5G 0 disk
- sdi 8:128 0 5G 0 disk
- sr0 11:0 1 4.4G 0 rom /run/media/root/CentOS 7 x86_64
本篇文章带大家了解RAID的一些相关信息,并学会如何创建RAID和如何卸载RAID,了解RAID中的一些特性和用法。
创作不易,动动小手给个点赞加关注吧,有什么意见评论区告诉我,一起学习。