raid含义
raid简称“独立冗余磁盘整列”,意思是一种把多块独立的硬盘(物理硬盘)按不同的方式组合起来形成一个硬盘组(逻辑硬盘),从而提供比单个硬盘更高的存储性能和提供数据备份技术。
在Linux中创建软raid
实验环境
一台centos7.2虚拟机,三块硬盘,在此环境创建raid0,raid1,raid5
强调:在生产环境中需要用相同型号规格的硬盘做raid,否则容易出现问题
1:确认系统是否安装了mdadm软件,因为在Linux中是通过mdadm软件来实现做raid的
命令:rpm -qa | grep mdadm
2:查看硬盘信息,对硬盘进行分区,并设置分区类型为raid的
先将sdb1分区格式化掉,然后重新在sdb,sdc,sdd各分两个分区
删除sdb1命令:partx -d --nr 1 /dev/sdb
同步硬盘信息:partx -a /dev/sdb,得到如图所示
开始对sdb,sdc,sdd各分两个分区
命令:fdisk /dev/sdb
[root@localhost ~]# 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 0x92d070b9. 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-10485759, default 2048): Last sector, +sectors or +size{K,M,G} (4194304-10485759, default 10485759): +1G #指定分区容量为1GB Partition 1 of type Linux and of size 2 GiB is set Command (m for help): P #输出新创建分区的信息 Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x92d070b9 Device Boot Start End Blocks Id System /dev/sdb1 4194304 8388607 2097152 83 Linux Command (m for help): T #查看分区的文件类型 Selected partition 1 Hex code (type L to list all codes): fd #fd代表raid得文件类型 Changed type of partition 'Linux' to 'Linux raid autodetect' Command (m for help): p Disk /dev/sdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x92d070b9 Device Boot Start End Blocks Id System /dev/sdb1 4194304 8388607 2097152 fd Linux raid autodetect Command (m for help): w #保存并退出 The partition table has been altered! Calling ioctl() to re-read partition table.
sdc,sdd都按照着上面分区,最终分区如图所示
3:配置raid0,这里使用sdb1和sdc1组成raid0
命令:mdadm -C -a yes /dev/md0 -l 0 -n 2 /dev/sd{b1,c1}
命令说明:
-C:创建阵列;
-a:同意创建设备,如不加此参数时必须先使用mknod 命令来创建一个RAID设备,不过推荐使用-a yes参数一次性创建;
-l:阵列等级(0,1,5,6,10)
-n:阵列中活动磁盘的数目,该数目加上备用磁盘的数目应该等于阵列中总的磁盘数目
-x:表示备用盘
/dev/md0:阵列的设备名称,如果还有其他阵列组可以以此类推
使用 mdadm -D /dev/md0查看具体信息
然后创建挂载目录
命令:mkdir /mnt/raid0
将/dev/md0文件类型改为ext4
命令:mkfs.ext4 /dev/md0
配置/etc/fstab文件,将md0的UUID加到fstab文件中
vim /etc/fstab,
挂载到之前创的/mnt/raid0目录下
命令:mount /dev/md0 /mnt/raid0
测试下往raid0写入个f1文件1G数据的速度有多快
命令:dd if=/dev/zero of=/mnt/raid/f1 bs=1M count=1024
测试下从raid0读取1g的速度有多快
命令:dd if=/mnt/raid0/f1 of=/dev/null