RAID:Redundant Arrays Indexpensive Disks
多个磁盘组合成一个阵列,来提供更好的性能、冗余
提高IO功能:
磁盘并行读写
提高耐用性:
磁盘冗余来实现
RAID级别:
多块磁盘组织在一起的工作方式有所不同
RAID实现方式:
外接式磁盘阵列:通过扩展卡提供适配能力
内接式RAID:主板集成RAID控制器
Software RAID:软件级别实现RAID
RAID-0:条带
读、写性能提升
可用空间:N*min(S1,S2,…)
无容错能力
最少磁盘数:2,2+
RAID-1:镜像
读性能提升、写性能略有下降:
可用空间:1*min(S1,S2,…)
有冗余能力
最少磁盘书:2,2+
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的实现:
结合内核中的md(multi devices)
mdadm:模式化的工具
命令的语法格式:mdadm [mode] <raiddevice> [options] <component-devices>
支持RAID级别:LINEAR,RAID0,RAID1,RAID4,RAID5,RAID6,RAID10
模式:
创建:-C
装配:-A
监控:-F
管理:-f,-r,-a
-C:创建模式:
-n #:使用#个块设备来创建次RAID
-l #:指明要创建的RAID的级别
-a {yes|no}:自动创建目标RAID设备的设备文件
-c CHUNK_SIZE:指明块chunk大小
-x #:指明空闲盘的个数
-D:显示raid的详细信息;
mdadm -D /dev/md#
管理模式:
-f:标记指定磁盘为损坏
-a:添加磁盘
-r:移除磁盘
观察md的状态:
cat /proc/mdstat
示例:
一.创建由三块硬盘组成的RAID5,一块备用硬盘,chunk大小128K,文件系统为ext4,开机可自动挂载至/backup
1.创建RAID5
[root@CentOS6 ~]# mdadm -C /dev/md0 -c 128K -a yes -l 5 -n 3 -x 1 /dev/sd{b,c,d,e} mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. [root@CentOS6 ~]# ll /dev/md0 brw-rw----. 1 root disk 9, 0 Sep 1 03:54 /dev/md0 [root@CentOS6 ~]# mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Thu Sep 1 03:54:09 2016 Raid Level : raid5 Array Size : 41910272 (39.97 GiB 42.92 GB) Used Dev Size : 20955136 (19.98 GiB 21.46 GB) Raid Devices : 3 Total Devices : 4 Persistence : Superblock is persistent Update Time : Thu Sep 1 03:55:55 2016 State : clean Active Devices : 3 Working Devices : 4 Failed Devices : 0 Spare Devices : 1 Layout : left-symmetric Chunk Size : 128K Name : CentOS6.localdomain:0 (local to host CentOS6.localdomain) UUID : fe4139e3:29157788:5dd26560:df142e56 Events : 18 Number Major Minor RaidDevice State 0 8 16 0 active sync /dev/sdb 1 8 32 1 active sync /dev/sdc 4 8 48 2 active sync /dev/sdd 3 8 64 - spare /dev/sde [root@CentOS6 ~]#
2.创建文件系统
[root@CentOS6 ~]# mke2fs -t ext4 -b 2048 -m 3 -L MYRAID /dev/md0 mke2fs 1.41.12 (17-May-2010) Filesystem label=MYRAID OS type: Linux Block size=2048 (log=1) Fragment size=2048 (log=1) Stride=64 blocks, Stripe width=128 blocks 2619392 inodes, 20955136 blocks 628654 blocks (3.00%) reserved for the super user First data block=0 Maximum filesystem blocks=557842432 1279 block groups 16384 blocks per group, 16384 fragments per group 2048 inodes per group Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 2048000, 3981312, 5619712, 10240000, 11943936 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@CentOS6 ~]# blkid /dev/md0 /dev/md0: LABEL="MYRAID" UUID="ed800d73-33c1-41d7-bfcf-dce18dc6aa72" TYPE="ext4" [root@CentOS6 ~]#
3.挂载文件系统
[root@CentOS6 raid]# cp /etc/* ./ &> /dev/null #复制文件到此目录 [root@CentOS6 raid]# cat fstab #数据可正常访问 # # /etc/fstab # Created by anaconda on Thu Jul 21 15:34:03 2016 # # 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 # UUID=f4d977bb-af76-4617-b07f-9c70ae42a056 / ext4 defaults 1 1 UUID=7907abdd-41cd-4609-8392-80e4a88c5b4c /boot ext4 defaults 1 2 UUID=50054489-14c8-4e49-a912-2ff368371653 /testdir ext4 defaults 1 2 UUID=d9f41da6-9df2-410f-8074-500425b26a3d 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 //10.1.250.60/share /root/mount cifs username=share,password=zhaizong 0 0 /dev/sr0 /media/cdrom iso9660 defaults 0 0 LABEL=MYRAID /mnt/raid ext4 defaults 0 0
二.模拟故障损坏
1.模拟/dev/sdb硬盘损坏
[root@CentOS6 ~]# mdadm /dev/md0 -f /dev/sdb #模拟故障/dev/sdb mdadm: set /dev/sdb faulty in /dev/md0 [root@CentOS6 ~]# mdadm -D /dev/md0 ... Number Major Minor RaidDevice State 3 8 64 0 spare rebuilding /dev/sde #备用设备/dev/sde接替/dev/sdb 1 8 32 1 active sync /dev/sdc 4 8 48 2 active sync /dev/sdd 0 8 16 - faulty /dev/sdb [root@CentOS6 ~]#
2.数据还可以正常访问
[root@CentOS6 raid]# cat fstab # # /etc/fstab # Created by anaconda on Thu Jul 21 15:34:03 2016 # # 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 # UUID=f4d977bb-af76-4617-b07f-9c70ae42a056 / ext4 defaults 1 1 UUID=7907abdd-41cd-4609-8392-80e4a88c5b4c /boot ext4 defaults 1 2 UUID=50054489-14c8-4e49-a912-2ff368371653 /testdir ext4 defaults 1 2 UUID=d9f41da6-9df2-410f-8074-500425b26a3d 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 //10.1.250.60/share /root/mount cifs username=share,password=zhaizong 0 0 /dev/sr0 /media/cdrom iso9660 defaults 0 0 LABEL=MYRAID /mnt/raid ext4 defaults 0 0 [root@CentOS6 raid]#
3.将/dev/sdb重新追加至RAID阵列
[root@CentOS6 ~]# mdadm /dev/md0 -a /dev/sdb mdadm: added /dev/sdb [root@CentOS6 ~]# mdadm -D /dev/md0 ... Number Major Minor RaidDevice State 3 8 64 0 active sync /dev/sde 1 8 32 1 active sync /dev/sdc 4 8 48 2 active sync /dev/sdd 5 8 16 - spare /dev/sdb #/dev/sdb处于备用状态 [root@CentOS6 ~]#
三.删除RAID
[root@CentOS6 ~]# umount /mnt/raid/ [root@CentOS6 ~]# mdadm -S /dev/md0 mdadm: stopped /dev/md0 [root@CentOS6 ~]# mdadm --zero-superblock /dev/sdb [root@CentOS6 ~]# mdadm --zero-superblock /dev/sdc [root@CentOS6 ~]# mdadm --zero-superblock /dev/sdd [root@CentOS6 ~]# mdadm --zero-superblock /dev/sde [root@CentOS6 ~]# blkid /dev/sda1: UUID="7907abdd-41cd-4609-8392-80e4a88c5b4c" TYPE="ext4" /dev/sda2: UUID="f4d977bb-af76-4617-b07f-9c70ae42a056" TYPE="ext4" /dev/sda3: UUID="50054489-14c8-4e49-a912-2ff368371653" TYPE="ext4" /dev/sda5: UUID="d9f41da6-9df2-410f-8074-500425b26a3d" TYPE="swap" [root@CentOS6 ~]#
原创文章,作者:zhai796898,如若转载,请注明出处:http://www.178linux.com/42694