RAID介绍
磁盘阵列(Redundant Arrays of Independent Disks,RAID),有“独立磁盘构成的具有冗余能力的阵列”之意,该技术通过将多个廉价的磁盘组合成一个磁盘阵列,以提高IO的读写效率,数据的冗余能力。
RAID有一下集中类型
RAID 0:也就是条带类型,是最基本的阵列方式,其组合方式至少两块硬盘,原理:在读取数据的时候,将数据分段并同时存入不同的磁盘上了,性能提升方面读写能力提升,但是没有冗余能力,空间利用率为N#。
RAID 1:也就是镜像技术,其组合方式也是至少两块硬盘,原理:在读取数据的时候,将同一份数据同时分别存入到不同的磁盘上。性能提升方面,写性能下降,读性能提升,有一定的冗余能力,空间利用率为1/2。
RAID 5:通过引入数据校验技术来确保数据的安全,所以最少需要三块盘,原理:将校验数据分别存放到不同的磁盘上。性能提升方面读写能力提示,有一定的冗余能力,空间的利用率为(n-1)/n。
不同的RAID组合方式如下
10 :采用条带技术和镜像技术,至少需要4块盘,性能提升方面读写能力提示,有一定的冗余能力,空间的利用率为1/2。
01 :采用条带技术和镜像技术,至少需要4块盘,性能提升方面读写能力提示,有一定的冗余能力,空间的利用率为1/2。
50 :采用条带技术和数据校验技术,至少需要6块盘,性能提升方面读写能力提示,有一定的冗余能力,空间的利用率为(n-2)/n。
另外一种jbod:,通俗的说当磁盘容量不够的时候,可以添加磁盘,但是性能上没有提示,没有冗余能力空间利用率100%
下面我们通过分区来演示RAID 0和RAID 1
用到的命令主要有mdadm fdisk mke2fs mount,这里重点介绍一下mdadm
mdadm 是模式化的命令,主要有创建模式,管理模式,监控模式,增长模式,装配模式。
创建模式 -c
专用模式:
-l:表示级别
-n #:设备个数
-a {yes|no}:自动创建设备文件
-c :CHUNK大小(块的大小),2^n 5默认是64k,6默认是512k
-x #:指定空闲盘个数
管理模式、
--add --reomve --fail
[[email protected] tmp]# fdisk /dev/sda
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/sda: 48.3 GB, 48318382080 bytes
64 heads, 32 sectors/track, 46080 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005361c
Device Boot Start End Blocks Id System
/dev/sda1 * 2 201 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 202 10201 10240000 83 Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3 10202 12201 2048000 82 Linux swap / Solaris
Partition 3 does not end on cylinder boundary.
/dev/sda4 12202 46080 34692096 5 Extended
Partition 4 does not end on cylinder boundary.
/dev/sda5 12204 14203 2048000 6 FAT16
Command (m for help): n
First cylinder (12202-46080, default 12202): 14204
Last cylinder, +cylinders or +size{K,M,G} (14204-46080, default 46080): +1G
Command (m for help): p
Disk /dev/sda: 48.3 GB, 48318382080 bytes
64 heads, 32 sectors/track, 46080 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005361c
Device Boot Start End Blocks Id System
/dev/sda1 * 2 201 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 202 10201 10240000 83 Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3 10202 12201 2048000 82 Linux swap / Solaris
Partition 3 does not end on cylinder boundary.
/dev/sda4 12202 46080 34692096 5 Extended
Partition 4 does not end on cylinder boundary.
/dev/sda5 12204 14203 2048000 6 FAT16
/dev/sda6 14204 15228 1049584 83 Linux
Command (m for help): n
First cylinder (12202-46080, default 12202): 15229
Last cylinder, +cylinders or +size{K,M,G} (15229-46080, default 46080): +1G
Command (m for help): t
Partition number (1-7): 6
Hex code (type L to list codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linux plaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext‘d (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 Hidden FAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaq diagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16 <3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
16 Hidden FAT16 64 Novell Netware af HFS / HFS+ fb VMware VMFS
17 Hidden HPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95 FAT1
Hex code (type L to list codes): fd
Changed system type of partition 6 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-7): 7
Hex code (type L to list codes): fd
Changed system type of partition 7 to fd (Linux raid autodetect)
Command (m for help): p
Disk /dev/sda: 48.3 GB, 48318382080 bytes
64 heads, 32 sectors/track, 46080 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0005361c
Device Boot Start End Blocks Id System
/dev/sda1 * 2 201 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 202 10201 10240000 83 Linux
Partition 2 does not end on cylinder boundary.
/dev/sda3 10202 12201 2048000 82 Linux swap / Solaris
Partition 3 does not end on cylinder boundary.
/dev/sda4 12202 46080 34692096 5 Extended
Partition 4 does not end on cylinder boundary.
/dev/sda5 12204 14203 2048000 6 FAT16
/dev/sda6 14204 15228 1049584 fd Linux raid autodetect
/dev/sda7 15229 16253 1049584 fd Linux raid autodetect
最后保存
[[email protected] ~]# mdadm -C mykk -n 2 -l 0 -a yes /dev/sda{6,7}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md/mykk started.
[[email protected] ~]# mke2fs -t ext4 /dev/md/mykk
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
131072 inodes, 524032 blocks
26201 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
正在写入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[[email protected] ~]# mount /dev/md
md/ md127
[[email protected] ~]# mount /dev/md/mykk /mnt
[[email protected] ~]# mdadm -D /dev/md/mykk
/dev/md/mykk:
Version : 1.2
Creation Time : Sun Dec 20 20:04:29 2015
Raid Level : raid0
Array Size : 2096128 (2047.34 MiB 2146.44 MB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Sun Dec 20 20:04:29 2015
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Chunk Size : 512K
Name : localhost.localdomain:mykk (local to host localhost.localdomain)
UUID : 1ea7f810:b952b2fa:bef2cb26:fd68c52e
Events : 0
Number Major Minor RaidDevice State
0 8 6 0 active sync /dev/sda6
1 8 7 1 active sync /dev/sda7
下面介绍:RAID 1
[[email protected] ~]# mdadm -C /dev/md1 -n 2 -l 1 -a yes /dev/sda{8,9}
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? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[[email protected] ~]# mke2fs -t ext4 /dev/md1
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262128 blocks
13106 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[[email protected] ~]# mount /dev/md1 /media/
[[email protected] ~]# mount
/dev/sda2 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
/dev/sda5 on /opt type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/md1 on /media type ext4 (rw)
模式当一个磁盘坏了的空余磁盘自动补上
[[email protected] ~]# mdadm /dev/md1 -a /dev/sda10
mdadm: added /dev/sda10
[[email protected] ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Sun Dec 20 20:21:48 2015
Raid Level : raid1
Array Size : 1048512 (1024.11 MiB 1073.68 MB)
Used Dev Size : 1048512 (1024.11 MiB 1073.68 MB)
Raid Devices : 2
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Sun Dec 20 20:33:38 2015
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1
Name : localhost.localdomain:1 (local to host localhost.localdomain)
UUID : 17689008:0600a878:a741e853:7629401a
Events : 18
Number Major Minor RaidDevice State
0 8 8 0 active sync /dev/sda8
1 8 9 1 active sync /dev/sda9
2 8 10 - spare /dev/sda10
[[email protected] ~]# mdadm /dev/md1 --fail /dev/sda9
mdadm: set /dev/sda9 faulty in /dev/md1
[[email protected] ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Sun Dec 20 20:21:48 2015
Raid Level : raid1
Array Size : 1048512 (1024.11 MiB 1073.68 MB)
Used Dev Size : 1048512 (1024.11 MiB 1073.68 MB)
Raid Devices : 2
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Sun Dec 20 20:38:55 2015
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 1
Spare Devices : 0
Name : localhost.localdomain:1 (local to host localhost.localdomain)
UUID : 17689008:0600a878:a741e853:7629401a
Events : 37
Number Major Minor RaidDevice State
0 8 8 0 active sync /dev/sda8
2 8 10 1 active sync /dev/sda10
1 8 9 - faulty /dev/sda9
移除坏掉的盘
[[email protected] ~]# mdadm -r /dev/md1 /dev/sda9
mdadm: hot removed /dev/sda9 from /dev/md1
[[email protected] ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Sun Dec 20 20:21:48 2015
Raid Level : raid1
Array Size : 1048512 (1024.11 MiB 1073.68 MB)
Used Dev Size : 1048512 (1024.11 MiB 1073.68 MB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Sun Dec 20 20:42:44 2015
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Name : localhost.localdomain:1 (local to host localhost.localdomain)
UUID : 17689008:0600a878:a741e853:7629401a
Events : 38
Number Major Minor RaidDevice State
0 8 8 0 active sync /dev/sda8
2 8 10 1 active sync /dev/sda10