RAID:
Redundant Arrays of Inexpensive(Independence) Disks
Berkeley: A case for Redundent Arrays of Inexpensive Disks RAID
提高IO能力:
磁盘并行读写
提高耐用性:
磁盘冗余来实现
级别:多块磁盘组织在一起的工作方式有所不同;
RAID实现的方式:
外接式磁盘阵列:通过扩展卡提供适配能力
内接式RAID:主板集成RAID控制器
Software RAID:
级别:level
- RAID-0:0, 条带卷,strip;
- RAID-1: 1, 镜像卷,mirror;
- RAID-2
.. - RAID-5:1块校验盘
- RAID-6:2块校验盘
- RAID10
- RAID01
-
RAID-0:
读、写性能提升;
可用空间:N*min(S1,S2,...)
无容错能力
最少磁盘数:2, 2+ -
RAID-1:
读性能提升、写性能略有下降;
可用空间:1*min(S1,S2,...)
有冗余能力(数据备份)
最少磁盘数:2, 2+ -
RAID-4:
至少3个盘,一个盘作检验盘 -
RAID-5:
读、写性能提升
可用空间:(N-1)*min(S1,S2,...)
有容错能力:1块磁盘
最少磁盘数:3, 3+
循环存放校验数据 -
RAID-6:
读、写性能提升
可用空间:(N-2)*min(S1,S2,...)
有容错能力:2块磁盘
最少磁盘数:4, 4+
混合类型
-
RAID-10:
读、写性能提升
可用空间:N*min(S1,S2,...)/2
有容错能力:每组镜像最多只能坏一块;
最少磁盘数:4, 4+ -
RAID-01:
-
RAID-50、RAID7
JBOD:Just a Bunch Of Disks
功能:将多块磁盘的空间合并一个大的连续空间使用;
可用空间:sum(S1,S2,...)
常用级别:RAID-0, RAID-1, RAID-5, RAID-10, RAID-50, JBOD
实现方式:
硬件实现方式
软件实现方式
CentOS 6上的软件RAID的实现:
结合内核中的md(multi devices)
mdadm:模式化的工具
命令的语法格式:
mdadm [mode] <raiddevice> [options] <component-devices>
支持的RAID级别:LINEAR, RAID0, RAID1, RAID4, RAID5, RAID6, RAID10;
模式:
创建:-C
装配: -A
监控: -F
管理:-f, -r, -a
<raiddevice>: /dev/md#
<component-devices>: 任意块设备
-C: 创建模式
-n #: 使用#个块设备来创建此RAID;
-l #:指明要创建的RAID的级别;
-a {yes|no}:自动创建目标RAID设备的设备文件;
-c CHUNK_SIZE:A suffix of 'K', 'M' or 'G' can be given
-x #: 指明空闲盘的个数;
例如:创建一个10G可用空间的RAID5;
-D:显示raid的详细信息;
mdadm -D /dev/md#
管理模式:
-f: 标记指定磁盘为损坏;
-a: 添加磁盘
-r: 移除磁盘
-
观察md的状态:
cat /proc/mdstat
-
停止md设备:
mdadm -S /dev/md#
watch命令:
-n #: 刷新间隔,单位是秒
watch -n# 'COMMAND'
报错
[root@localhost ~]# blkid
/dev/sdb5: LABEL="backup" UUID="5176d653-a095-4f5e-8646-2d0e26fc3315" TYPE="ext4"
/dev/sdb6: LABEL="backup" UUID="1304b977-620e-41fc-9d7c-5b58d8b8500b" TYPE="ext4"
/dev/sdb7: LABEL="backup" UUID="7e70c845-41f4-4330-b85d-18e4e2a36a24" TYPE="ext4"
/dev/sdb8: LABEL="backup" UUID="beeb1218-e4bc-4d6d-ae5d-592a47a6f086" TYPE="ext4"
/dev/sda1: UUID="6e0c483a-767f-4836-9722-4ee11ad0e354" TYPE="xfs"
/dev/sda2: UUID="5l05VF-4oRE-Nbpz-YnuF-76il-fjGc-EfTwst" TYPE="LVM2_member"
/dev/sr0: UUID="2018-11-25-23-54-16-00" LABEL="CentOS 7 x86_64" TYPE="iso9660" PTTYPE="dos"
/dev/mapper/centos-root: UUID="bd000f98-9676-4f6d-810c-9c52a4f8f20c" TYPE="xfs"
/dev/mapper/centos-swap: UUID="383176d7-ce29-4055-bfdc-93832f4610e8" TYPE="swap"
/dev/mapper/centos-home: UUID="f061c27e-d48b-491f-bdf3-28545428d3b5" TYPE="xfs"
[root@localhost ~]# mke2fs -t ext3 /dev/sdb{5,6,7,8}
mke2fs 1.42.9 (28-Dec-2013)
mke2fs: invalid blocks '/dev/sdb6' on device '/dev/sdb5'
[root@localhost ~]# mdadm -C -n 3 -l 1 -a yes -c 128K -x 1 /dev/sdb{5,6,7}
mdadm: device /dev/sdb5 exists but is not an md array.
[root@localhost ~]# mdadm -C /dev/md0 -n 3 -l 1 -a yes -c 128K -x 1 /dev/sdb{5,6,7}
mdadm: You haven't given enough devices (real or missing) to create this array
练习
1.创建一个可用空间为5G的RAID1设备,要求其chunk大小为128k,文件系统为ext4,有一个空闲盘,开机可自动挂载至/backup目录;
2.创建一个可用空间为10G的RAID10设备,要求其chunk大小为256k,文件系统为ext4,开机可自动挂载至/mydata目录;
A1
创建4个5G的分区并标为RAID并重读分区表
[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.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): e
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Extended and of size 20 GiB is set
Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 5
First sector (4096-41943039, default 4096):
Using default value 4096
Last sector, +sectors or +size{K,M,G} (4096-41943039, default 41943039): +5G
Partition 5 of type Linux and of size 5 GiB is set
Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 6
First sector (10491904-41943039, default 10491904):
Using default value 10491904
Last sector, +sectors or +size{K,M,G} (10491904-41943039, default 41943039): +5G
Partition 6 of type Linux and of size 5 GiB is set
Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 7
First sector (20979712-41943039, default 20979712):
Using default value 20979712
Last sector, +sectors or +size{K,M,G} (20979712-41943039, default 41943039): +5G
Partition 7 of type Linux and of size 5 GiB is set
Command (m for help): n
Partition type:
p primary (0 primary, 1 extended, 3 free)
l logical (numbered from 5)
Select (default p): l
Adding logical partition 8
First sector (31467520-41943039, default 31467520):
Using default value 31467520
Last sector, +sectors or +size{K,M,G} (31467520-41943039, default 41943039):
Using default value 41943039
Partition 8 of type Linux and of size 5 GiB is set
Command (m for help): t
Partition number (1,5-8, default 8): 5
Hex code (type L to list all codes): fd
Changed type of partition 'VMware VMFS' to 'Linux raid autodetect'
Command (m for help): t
Partition number (1,5-8, default 8): 6
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): t
Partition number (1,5-8, default 8): 7
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): t
Partition number (1,5-8, default 8):
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 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: 0x13ceef16
Device Boot Start End Blocks Id System
/dev/sdb1 2048 41943039 20970496 5 Extended
/dev/sdb5 4096 10489855 5242880 fd Linux raid autodetect
/dev/sdb6 10491904 20977663 5242880 fd Linux raid autodetect
/dev/sdb7 20979712 31465471 5242880 fd Linux raid autodetect
/dev/sdb8 31467520 41943039 5237760 fd Linux raid autodetect
[root@localhost ~]# partx -a /dev/sdb
partx: /dev/sdb: error adding partition 1
partx: /dev/sdb: error adding partitions 5-8
[root@localhost ~]# cat /proc/partitions
major minor #blocks name
2 0 4 fd0
8 16 20971520 sdb
8 17 1 sdb1
8 21 5242880 sdb5
8 22 5242880 sdb6
8 23 5242880 sdb7
8 24 5237760 sdb8
8 0 125829120 sda
8 1 1048576 sda1
8 2 124779520 sda2
11 0 4481024 sr0
253 0 52428800 dm-0
253 1 2097152 dm-1
253 2 70246400 dm-2
格式化RAID
[root@localhost ~]# mke2fs -t ext4 -L backUp /dev/md0
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=backUp
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1309440 blocks
65472 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 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
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
挂载
[root@localhost ~]# mount -L backUp /backup
[root@localhost ~]# mount
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)
...
/dev/md0 on /backup type ext4 (rw,relatime,seclabel,data=ordered)
设置开机自动挂载
[root@localhost ~]# backUp /backup ext4 defaults 0 0 >> /etc/fstab
A2
组成RAID10
[root@localhost ~]# mdadm -C /dev/md0 -l 10 -n 4 -a yes -c 256K /dev/sdb{5,6,7,8}
mdadm: /dev/sdb5 appears to contain an ext2fs file system
size=5242880K mtime=Wed Dec 31 19:00:00 1969
mdadm: /dev/sdb5 appears to be part of a raid array:
level=raid1 devices=2 ctime=Sun Feb 17 08:35:31 2019
mdadm: /dev/sdb6 appears to contain an ext2fs file system
size=5242880K mtime=Wed Dec 31 19:00:00 1969
mdadm: /dev/sdb6 appears to be part of a raid array:
level=raid1 devices=2 ctime=Sun Feb 17 08:35:31 2019
mdadm: /dev/sdb7 appears to contain an ext2fs file system
size=5242880K mtime=Wed Dec 31 19:00:00 1969
mdadm: /dev/sdb7 appears to be part of a raid array:
level=raid1 devices=2 ctime=Sun Feb 17 08:35:31 2019
mdadm: /dev/sdb8 appears to contain an ext2fs file system
size=5237760K mtime=Sun Feb 17 08:40:08 2019
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid1] [raid10]
md0 : active raid10 sdb8[3] sdb7[2] sdb6[1] sdb5[0]
10465280 blocks super 1.2 256K chunks 2 near-copies [4/4] [UUUU]
unused devices: <none>
[root@localhost ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Sun Feb 17 08:58:06 2019
Raid Level : raid10
Array Size : 10465280 (9.98 GiB 10.72 GB)
Used Dev Size : 5232640 (4.99 GiB 5.36 GB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Sun Feb 17 08:58:21 2019
State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Layout : near=2
Chunk Size : 256K
Consistency Policy : resync
Name : localhost.localdomain:0 (local to host localhost.localdomain)
UUID : 777c686f:0bac4cbb:2ab8268d:585480b0
Events : 17
Number Major Minor RaidDevice State
0 8 21 0 active sync set-A /dev/sdb5
1 8 22 1 active sync set-B /dev/sdb6
2 8 23 2 active sync set-A /dev/sdb7
3 8 24 3 active sync set-B /dev/sdb8
格式化md0
[root@localhost ~]# mke2fs -t ext4 -L myData /dev/md0
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=myData
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=64 blocks, Stripe width=128 blocks
654080 inodes, 2616320 blocks
130816 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2151677952
80 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
挂载
root@localhost ~]# mount -L myData /mydata
[root@localhost ~]# fdisk -l /dev/md0
Disk /dev/md0: 10.7 GB, 10716446720 bytes, 20930560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 262144 bytes / 524288 bytes
设置fstab文件
[root@localhost ~]# myData /mydata ext4 defaults 0 0 >> /etc/fstab
网友评论