标签:raid
RAID是英文Redundant Array of Independent Disks的缩写,中文简称为独立冗余磁盘阵列。简单的说,RAID是一种把多块独立的硬盘(物理硬盘)按不同的方式组合起来形成一个硬盘组(逻辑硬盘),从而提供比单个硬盘更高的存储性能和提供数据备份技术。
Raid的级别:仅代表磁盘组织方式不同,没有上下之分;
0: 条带
性能提升: 读,写
冗余能力(容错能力): 无
空间利用率:nS
至少2块盘
1: 镜像
性能表现:写性能下降,读性能提升
冗余能力:有
空间利用率:1/2
至少2块盘
5:
性能表现:读,写提升
冗余能力:有
空间利用率:(n-1)/n
至少需要3块
10:
性能表现:读、写提升
冗余能力:有
空间利用率:1/2
至少需要4块
01:
性能表现:读、写提升
冗余能力:有
空间利用率:1/2
至少需要4块
50:
性能表现:读、写提升
冗余能力:有
空间利用率:(n-2)/n
至少需要6块
jbod:
性能表现:无提升
冗余能力:无
空间利用率:100%
至少需要2块
用fdisk 分出来两个分区模拟两块硬盘,
[root@localhost ~]# fdisk -l
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 25 200781 83 Linux
/dev/sda2 26 152 1020127+ 82 Linux swap / Solaris
/dev/sda3 153 1044 7164990 83 Linux
Disk /dev/sdb: 1073 MB, 1073741824 bytes (/dev/sdb创建)
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
root@localhost ~]# fdisk /dev/sdb
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-130, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-130, default 130): +300M
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 37 297171 83 Linux
这样一个分区就创建好了,但要做raid要把磁盘的ID改成为raid的(Linux raid auto),
Command (m for help): l
0 Empty 1e Hidden W95 FAT1 80 Old Minix bf Solaris
1 FAT12 24 NEC DOS 81 Minix / old Lin c1 DRDOS/sec (FAT-
2 XENIX root 39 Plan 9 82 Linux swap / So c4 DRDOS/sec (FAT-
3 XENIX usr 3c PartitionMagic 83 Linux c6 DRDOS/sec (FAT-
4 FAT16 <32M 40 Venix 80286 84 OS/2 hidden C: c7 Syrinx
5 Extended 41 PPC PReP Boot 85 Linux extended da Non-FS data
6 FAT16 42 SFS 86 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4d QNX4.x 87 NTFS volume set de Dell Utility
8 AIX 4e QNX4.x 2nd part 88 Linux plaintext df BootIt
9 AIX bootable 4f QNX4.x 3rd part 8e Linux LVM e1 DOS access
a OS/2 Boot Manag 50 OnTrack DM 93 Amoeba e3 DOS R/O
b W95 FAT32 51 OnTrack DM6 Aux 94 Amoeba BBT e4 SpeedStor
c W95 FAT32 (LBA) 52 CP/M 9f BSD/OS eb BeOS fs
e W95 FAT16 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi ee EFI GPT
f W95 Ext‘d (LBA) 54 OnTrackDM6 a5 FreeBSD ef EFI (FAT-12/16/
10 OPUS 55 EZ-Drive a6 OpenBSD f0 Linux/PA-RISC b
11 Hidden FAT12 56 Golden Bow a7 NeXTSTEP f1 SpeedStor
12 Compaq diagnost 5c Priam Edisk a8 Darwin UFS f4 SpeedStor
14 Hidden FAT16 <3 61 SpeedStor a9 NetBSD f2 DOS secondary
16 Hidden FAT16 63 GNU HURD or Sys ab Darwin boot fb VMware VMFS
17 Hidden HPFS/NTF 64 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 AST SmartSleep 65 Novell Netware b8 BSDI swap fd Linux raid auto
1b Hidden W95 FAT3 70 DiskSecure Mult bb Boot Wizard hid fe LANstep
1c Hidden W95 FAT3 75 PC/IX be Solaris boot ff BBT
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd (改成fd)
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 37 297171 fd Linux raid autodetect
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (38-130, default 38):
Using default value 38
Last cylinder or +size or +sizeM or +sizeK (38-130, default 130): +300M
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)
Command (m for help): p
Disk /dev/sdb: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 37 297171 fd Linux raid autodetect
/dev/sdb2 38 74 297202+ fd 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 ~]# partprobe /dev/sdb (重新读取分区表)
[root@localhost ~]# cat /proc/partitions
major minor #blocks name
8 0 8388608 sda
8 1 200781 sda1
8 2 1020127 sda2
8 3 7164990 sda3
8 16 1048576 sdb
8 17 297171 sdb1
8 18 297202 sdb2
创建Raid 0
[root@localhost ~]# mdadm -C /dev/md0 -a yes -l 0 -n 2 /dev/sdb{1,2}
mdadm: array /dev/md0 started.
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid0]
md0 : active raid0 sdb2[1] sdb1[0]
594176 blocks 64k chunks
unused devices: <none>
[root@localhost ~]# mke2fs -j /dev/md0 格式化
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
74400 inodes, 148544 blocks
7427 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=155189248
5 block groups
32768 blocks per group, 32768 fragments per group
14880 inodes per group
Superblock backups stored on blocks:
32768, 98304
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mount /dev/md0 /mnt/ 挂载到/mnt下
别的级别的raid创建方法相同。
mdadm: 将任何块设备做成RAID
模式化的命令:
创建模式
-C
专用选项:
-l: 级别
-n #: 设备个数(#为数字)
-a {yes|no}: 是否自动为其创建设备文件
-c: CHUNK大小, 2^n,默认为64K
-x #: 指定空闲盘个数
管理模式
--add, --remove, --fail
mdadm /dev/md# --fail /dev/sda7
监控模式
-F
增长模式
-G
装配模式
-A
查看RAID阵列的详细信息
mdadm -D /dev/md#
--detail
停止阵列:
mdadm -S /dev/md#
--stop
显示Raid的详细信息:
mdadm -D /dev/md0(raid设备)
模拟磁盘损坏:
mdadm /dev/md0 --fail /dev/sdb2 (raid /dev/md0上的磁盘/dev/sdb2损坏。)
删除损坏的磁盘:
mdadm /dev/md0 -r /dev/sdb2
加一块新的盘到raid里(新加的盘要和之前的盘大小一定要一致)
mdadm /dev/sdb2 -a /dev/sdb3
Raid阵列不想用了(停止):
mdadm -S /dev/md0
Raid阵列重新启用(启动):
mdadm -A /dev/md0 /dev/sdb1 /dev/sdb2
指定空闲盘,当raid中有磁盘坏掉时,它自己替换它:
mdadm -C /dev/md0 -a yes -l 1 -n 2 -x 1 /dev/sdb1/dev/sdb2 /dev/sdb3
如果已经创建好了,再加空闲盘操作:
mdadm /dev/sdb2 -a /dev/sdb3
将当前RAID信息保存至配置文件,以便以后进行装配:
mdadm -D --scan >/etc/mdadm.conf
下面的链接写的更清楚:
http://lyp0909.blog.51cto.com/508999/503575
标签:raid
原文地址:http://hans925.blog.51cto.com/542170/1625864