Chinaunix首页 | 论坛 | 博客
  • 博客访问: 172444
  • 博文数量: 12
  • 博客积分: 333
  • 博客等级: 二等列兵
  • 技术积分: 208
  • 用 户 组: 普通用户
  • 注册时间: 2012-05-11 10:41
文章分类
文章存档

2012年(12)

分类: LINUX

2012-06-23 14:57:42

一、Raid的简介

     Raid(独立冗余磁盘阵列)是一种有多块廉价磁盘构成的冗余阵列,它可以充分发挥多块硬盘的优势,可以提升硬盘速度,增大容量,提供容错功能确保数据安全性,易于管理的优点,在任何一块硬盘出现问题的情况下都可以继续工作,不会受到损坏硬盘的影响。Raid的工作模式主要分为0-6个级别。现在常用的Raid级别是0,1,4,5,6和10(就是Raid1和Raid0的组合)。下面简单介绍几种Raid的创建方法。

二、Raid0的创建

     Raid0是将几块同样的硬盘用硬件的形式或者软件的形式串联起来,将数据依次写入到各磁盘中。其特点是:读写性能高,但无容错能力。以下是其在软件形式下将/dev/sda5和/dev/sda6创建为Raid0的过程:

1、将/dev/sda5和/dev/sda6的卷标改为fd:

  1. [root@localhost ~]# fdisk /dev/sda  
  2. The number of cylinders for this disk is set to 15665.  
  3. There is nothing wrong with that, but this is larger than 1024,  
  4. and could in certain setups cause problems with:  
  5. 1) software that runs at boot time (e.g., old versions of LILO)  
  6. 2) booting and partitioning software from other OSs  
  7.    (e.g., DOS FDISK, OS/2 FDISK)  
  8. Command (m for help): t  
  9. Partition number (1-8): 5  
  10. Hex code (type L to list codes): fd   
  11. Command (m for help): t  
  12. Partition number (1-8): 6  
  13. Hex code (type L to list codes): fd  
  14. Command (m for help): p  
  15. Disk /dev/sda: 128.8 GB, 128849018880 bytes  
  16. 255 heads, 63 sectors/track, 15665 cylinders  
  17. Units = cylinders of 16065 * 512 = 8225280 bytes  
  18.    Device Boot      Start         End      Blocks   Id  System  
  19. /dev/sda1   *           1          13      104391   83  Linux  
  20. /dev/sda2              14        5235    41945715   8e  Linux LVM  
  21. /dev/sda3            5236        5366     1052257+  82  Linux swap / Solaris  
  22. /dev/sda4            5367       15665    82726717+   5  Extended  
  23. /dev/sda5            5367        5732     2939863+  fd  Linux raid autodetect  
  24. /dev/sda6            5733        6098     2939863+  fd  Linux raid autodetect  
  25. /dev/sda7            6099        6464     2939863+  fd  Linux raid autodetect  
  26. /dev/sda8            6465        6830     2939863+  fd  Linux raid autodetect  
  27. Command (m for help): w 

2、将/dev/sda5和/dev/sda6制作成Raid0

  1. [root@localhost ~]# mdadm -C /dev/md0 -l 0 -n 2 /dev/sda{5,6}  
  2. mdadm: /dev/sda5 appears to contain an ext2fs file system  
  3.     size=8819328K  mtime=Sat Jun 23 10:56:53 2012  
  4. mdadm: /dev/sda5 appears to be part of a raid array:  
  5.     level=raid0 devices=2 ctime=Sat Jun 23 14:11:40 2012  
  6. mdadm: /dev/sda6 appears to be part of a raid array:  
  7.     level=raid0 devices=2 ctime=Sat Jun 23 14:11:40 2012  
  8. Continue creating array? y  
  9. mdadm: array /dev/md0 started.  
  10. [root@localhost ~]# cat /proc/mdstat   
  11. Personalities : [raid1] [raid10] [raid6] [raid5] [raid4] [raid0]   
  12. md0 : active raid0 sda6[1] sda5[0]  
  13.       5879552 blocks 64k chunks  
  14.         
  15. unused devices: <none> 
  16. [root@localhost ~]#  

3、将/dev/md0格式化,并将其挂载,这样Raid0就建立了。

  1. [root@localhost ~]# mke2fs -j /dev/md0  
  2. mke2fs 1.39 (29-May-2006)  
  3. Filesystem label=  
  4. OS type: Linux  
  5. Block size=4096 (log=2)  
  6. Fragment size=4096 (log=2)  
  7. 735840 inodes, 1469888 blocks  
  8. 73494 blocks (5.00%) reserved for the super user  
  9. First data block=0 
  10. Maximum filesystem blocks=1505755136 
  11. 45 block groups  
  12. 32768 blocks per group, 32768 fragments per group  
  13. 16352 inodes per group  
  14. Superblock backups stored on blocks:   
  15.     32768, 98304, 163840, 229376, 294912, 819200, 884736  
  16. Writing inode tables: done                              
  17. Creating journal (32768 blocks): done  
  18. Writing superblocks and filesystem accounting information: done  
  19. This filesystem will be automatically checked every 34 mounts or  
  20. 180 days, whichever comes first.  Use tune2fs -c or -i to override.  
  21. [root@localhost ~]# mount /dev/md0 /data  
  22. [root@localhost ~]# ls /data  
  23. lost+found 

二、Raid1的特点及创建

     Raid1又称磁盘镜像,是把一个磁盘上的数据镜像到另一个磁盘上,这样Raid1具有很强的容错功能,但是写入性能较低,磁盘的利用率低,至少需要两块磁盘。其创建过程和Raid0 的创建过程基本相同,只是将mdadm命令中的参数改为:

mdadm -C /dev/md1 -l 1 -n 2 /dev/sda{5,6};其余的步骤和Raid0的创建过程相同,在此不做赘述。

三、Raid4的特点

      Raid4增添了校验功能,其校验码(前两块磁盘异或之后得到的)放在第三块磁盘中,这样可以保证当一块磁盘坏掉后,仍能保持数据的完整性。至少需要三块硬盘,每次数据更新时有四次数据请求,所以访问数据的效率不高。

四、Raid5的特点及创建过程以及管理

      Raid5和Raid4基本相同,只是它将校验码分散的存储在磁盘上,这样可以平均磁盘的负载,读写性能高。下面介绍具有空闲磁盘的Raid5的创建过程。

 1、将/dev/sd{5,6,7,8}创建成具有空闲磁盘的Raid5。如下所示:

  1. [root@localhost ~]# mdadm -C /dev/md1 -l 5 -n 3 -x 1 /dev/sda{5,6,7,8}  
  2. mdadm: /dev/sda5 appears to contain an ext2fs file system  
  3.     size=5879552K  mtime=Sat Jun 23 14:15:52 2012  
  4. mdadm: /dev/sda5 appears to be part of a raid array:  
  5.     level=raid0 devices=2 ctime=Sat Jun 23 14:12:50 2012  
  6. mdadm: /dev/sda6 appears to be part of a raid array:  
  7.     level=raid0 devices=2 ctime=Sat Jun 23 14:12:50 2012  
  8. mdadm: /dev/sda7 appears to be part of a raid array:  
  9.     level=raid5 devices=4 ctime=Sat Jun 23 10:38:54 2012  
  10. mdadm: /dev/sda8 appears to contain an ext2fs file system  
  11.     size=8819328K  mtime=Sat Jun 23 10:56:53 2012  
  12. mdadm: /dev/sda8 appears to be part of a raid array:  
  13.     level=raid5 devices=4 ctime=Sat Jun 23 10:38:54 2012  
  14. Continue creating array? y  
  15. mdadm: array /dev/md1 started.  
  16. [root@localhost ~]# cat /proc/mdstat   
  17. Personalities : [raid1] [raid10] [raid6] [raid5] [raid4] [raid0]   
  18. md1 : active raid5 sda7[4] sda8[3](S) sda6[1] sda5[0]  
  19.       5879552 blocks level 5, 64k chunk, algorithm 2 [3/2] [UU_]  
  20.       [==>..................]  recovery = 14.7% (434172/2939776) finish=2.7min speed=14971K/sec  
  21.         
  22. unused devices: <none> 
  23. [root@localhost ~]# mdadm -D /dev/md1  
  24. /dev/md1:  
  25.         Version : 0.90  
  26.   Creation Time : Sat Jun 23 14:39:31 2012  
  27.      Raid Level : raid5  
  28.      Array Size : 5879552 (5.61 GiB 6.02 GB)  
  29.   Used Dev Size : 2939776 (2.80 GiB 3.01 GB)  
  30.    Raid Devices : 3  
  31.   Total Devices : 4  
  32. Preferred Minor : 1  
  33.     Persistence : Superblock is persistent  
  34.     Update Time : Sat Jun 23 14:39:31 2012  
  35.           State : clean, degraded, recovering  
  36.  Active Devices : 2  
  37. Working Devices : 4  
  38.  Failed Devices : 0  
  39.   Spare Devices : 2  
  40.          Layout : left-symmetric  
  41.      Chunk Size : 64K  
  42.  Rebuild Status : 30% complete  
  43.            UUID : 2f398377:8996228f:5da4c195:b9923acd  
  44.          Events : 0.1  
  45.     Number   Major   Minor   RaidDevice State  
  46.        0       8        5        0      active sync   /dev/sda5  
  47.        1       8        6        1      active sync   /dev/sda6  
  48.        4       8        7        2      spare rebuilding   /dev/sda7  
  49.        3       8        8        -      spare   /dev/sda8 

2、模拟当/dev/sda5坏掉时,/dev/sda8可以填补/sda5d的空缺。

  1. [root@localhost ~]# mdadm -f /dev/md1 /dev/sda5  
  2. mdadm: set /dev/sda5 faulty in /dev/md1  
  3. [root@localhost ~]# mdadm -D /dev/md1  
  4. /dev/md1:  
  5.         Version : 0.90  
  6.   Creation Time : Sat Jun 23 14:39:31 2012  
  7.      Raid Level : raid5  
  8.      Array Size : 5879552 (5.61 GiB 6.02 GB)  
  9.   Used Dev Size : 2939776 (2.80 GiB 3.01 GB)  
  10.    Raid Devices : 3  
  11.   Total Devices : 4  
  12. Preferred Minor : 1  
  13.     Persistence : Superblock is persistent  
  14.     Update Time : Sat Jun 23 14:45:38 2012  
  15.           State : clean, degraded, recovering  
  16.  Active Devices : 2  
  17. Working Devices : 3  
  18.  Failed Devices : 1  
  19.   Spare Devices : 1  
  20.          Layout : left-symmetric  
  21.      Chunk Size : 64K  
  22.  Rebuild Status : 10% complete  
  23.            UUID : 2f398377:8996228f:5da4c195:b9923acd  
  24.          Events : 0.6  
  25.     Number   Major   Minor   RaidDevice State  
  26.        3       8        8        0      spare rebuilding   /dev/sda8  
  27.        1       8        6        1      active sync   /dev/sda6  
  28.        2       8        7        2      active sync   /dev/sda7  
  29.        4       8        5        -      faulty spare   /dev/sda5  
  30. [root@localhost ~]#  

     这样就可以将sda5卸掉,换一块好的硬盘。注意:如果你只是做Raid测试的话,那么一定要关闭Raid,因为如果你不关闭时重新分区时,会出现一些莫名的错误。其关闭步骤如下:

  1. [root@localhost ~]# mdadm -S /dev/md1  
  2. mdadm: stopped /dev/md1  
  3. [root@localhost ~]# cat /proc/mdstat   
  4. Personalities : [raid1] [raid10] [raid6] [raid5] [raid4] [raid0]   
  5. unused devices: <none> 
阅读(3896) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~