RAID简介

时间:2021-05-15 16:53:14

RAID(独立磁盘冗余阵列)可以提供较普通磁盘更高的速度,安全性,所以服务器在安装时会选择创建RAID.RAID的创建有两种方式:软RAID(通过操作系统软件来实现)和硬raid(使用硬件整列卡)

raid0:striping(条带模式),至少需要两块磁盘,做RAID分区的大小最好是相同的(可以充分发挥并发优势);数据分散存储于不同的磁盘上,在读写的时候可以实现并发,所以相对其读写性能最好;但是没有容错功能,任何一个磁盘的损坏将损坏全部数据;磁盘利用率为100%!

raid1:mirroring(镜像卷),至少需要两块磁盘,raid大小等于两个raid分区中最小的容量(最好将分区大小分为一样),数据有冗余,在存储时同时写入两块硬盘,实现了数据备份。 磁盘利用率为50%,两块100G的磁盘构成raid1只能提供100G的可用空间。

raid5:需要三块或以上硬盘,可以提供热备实现故障的恢复;只损坏一块,没有问题。但如果同时损坏两块磁盘,则数据将都会损坏。

raid0

例1.

1)创建raid0

2)导出阵列配置文件

3)格式化并挂载到指定目录

4)修改/etc/fatab永久挂载

环境:添加一个sdb硬盘,分两个1G的主分区。sdb1和sdb2

创建分区:fdisk /dev/sdb

[root@localhost ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x3a3cbc76.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag  will be corrected by w(rite)

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): p

Disk /dev/sdb:  bytes
 heads,  sectors/track,  cylinders
Units = cylinders of  *  =  bytes
Sector size (logical/physical):  bytes /  bytes
I/O size (minimum/optimal):  bytes /  bytes
Disk identifier: 0x3a3cbc76

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (-)
p
Partition number (-):
First cylinder (-, ):
Using
Last cylinder, +cylinders or +size{K,M,G} (-, ): 1G

Command (m for help): n
Command action
   e   extended
   p   primary partition (-)
p
Partition number (-):
First cylinder (-, ): p^H
First cylinder (-, ):
Using
Last cylinder, +cylinders or +size{K,M,G} (-, ): +1G

Command (m for help): p

Disk /dev/sdb:  bytes
 heads,  sectors/track,  cylinders
Units = cylinders of  *  =  bytes
Sector size (logical/physical):  bytes /  bytes
I/O size (minimum/optimal):  bytes /  bytes
Disk identifier: 0x3a3cbc76

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1                                       Linux
/dev/sdb2                                  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# ll /dev/sdb*
brw-rw---- 1 root disk 8, 16 9月  23 08:14 /dev/sdb
brw-rw---- 1 root disk 8, 17 9月  23 08:14 /dev/sdb1
brw-rw---- 1 root disk 8, 18 9月  23 08:14 /dev/sdb2

注:8等于文件号       指硬盘

创建raid  mdadm常用参数:

  • -C或--creat        建立一个新阵列
  • -A                    激活磁盘阵列
  • -D或--datail       打印阵列设备的详细信息
  • -s或--scan        扫描配置文件或/proc/mdstat得到阵列缺失信息
  • -f                    将设备状态定位故障
  • -a或--add         添加设备到阵列
  • -v                    --verbose 显示详细信息
  • -r                    移动设备
  • -l 或--level        设定磁盘整列的级别
  • -n或--raid-devices     指定阵列成员(分区/磁盘)的数量
  • -x或--spare-devicds=   指定阵列中热备盘的数量
  • -c 或--chunk         设定整列的块 chunk 大小,单位为KB
  • -G或--grow          改变阵型大小或形状

热备份盘:为了加强容错的功能以及使系统在磁盘故障的情况下迅速的重建数据,以维持系统的性能一般的磁盘阵列系统都可以使用热备份功能

创建:

[root@localhost ~]# mdadm -C -v /dev/md0 -l  -n  /dev/sdb1 /dev/sdb2
mdadm: chunk size defaults to 512K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@localhost ~]#
注:md0 等于raid0  是个名字而已
[root@localhost ~]# mdadm -Ds      //扫描下阵列的信息
ARRAY /dev/md0 metadata= UUID=05d6ddfe:334b0565:9fc4a47b:352e04f1
[root@localhost ~]# 
[root@localhost ~]# mdadm -D /dev/md0      //查看阵列具体信息
/dev/md0:
        Version : 1.2
  Creation Time : Wed Sep  ::
     Raid Level : raid0
     Array Size :  (1042.68 MiB 1093.14 MB)
   Raid Devices :
  Total Devices :
    Persistence : Superblock is persistent

    Update Time : Wed Sep  ::
          State : clean
 Active Devices :
Working Devices :
 Failed Devices :
  Spare Devices : 

     Chunk Size : 512K

           Name : localhost.localdomain:  (local to host localhost.localdomain)
           UUID : 05d6ddfe:334b0565:9fc4a47b:352e04f1
         Events : 

    Number   Major   Minor   RaidDevice State
                                   active sync   /dev/sdb1
                                   active sync   /dev/sdb2
[root@localhost ~]# 

[root@localhost ~]# mdadm -Ds > /etc/mdadm.conf    //生成配置文件
[root@localhost ~]# cat /etc/mdadm.conf
ARRAY /dev/md0 metadata= UUID=05d6ddfe:334b0565:9fc4a47b:352e04f1
[root@localhost ~]# 

raid创建成功后,怎么才可以用呢?

先分区:

[root@localhost ~]# fdisk /dev/md0

[root@localhost ~]# ll /dev/md*
brw-rw----  root disk   ,  9月   : /dev/md0
brw-rw----  root disk ,  9月   : /dev/md0p1

注: 等于 raid阵列

格式化:

[root@localhost ~]# mkfs.ext4 /dev/md0p1    //格式化
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
66672 inodes, 266624 blocks
13331 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=276824064
9 block groups
32768 blocks per group, 32768 fragments per group
7408 inodes per group
Superblock backups stored on blocks:
	32768, 98304, 163840, 229376

正在写入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 31 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

挂载使用:

[root@localhost ~]# mkdir /raid0
[root@localhost ~]# mount /dev/md0p1 /raid0/    //挂载
[root@localhost ~]# ll /raid0/
总用量
drwx------  root root  9月   : lost+found

开机自动挂载:

[root@localhost ~]# vim /etc/fstab

#
# /etc/fstab
# Created by anaconda on Sun Jun 21 04:27:16 2015
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root /                       ext4    defaults        1 1
UUID=34862a27-ad9d-4313-acc5-bc450fed7468 /boot                   ext4    defaults        1 2
/dev/mapper/VolGroup-lv_swap swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
~
~
~
~

raid1  raid5类似于raid0  请大家自己琢磨!