Rhel5 軟raid5的實驗

RAID5:至少需要3塊磁盤,是raid0raid1的折中方案,採用奇偶校驗的方式將數據拆分存儲在不同的磁盤中,並且其數據和對應的校驗信息存儲在不同的磁盤上,最多允許有一塊磁盤故障,在更換了故障的磁盤後可以使用校驗信息來恢復丟失的數據。

本實驗中將使用4塊磁盤創建軟RAID5,其中一塊磁盤做備份磁盤。軟RAID,即操作系統級的RAID

1、         創建以來建立RAID54個分區。

[root@vm ~]# fdisk /dev/sdb    //創建4個磁盤分區

 

The number of cylinders for this disk is set to 2610.

There is nothing wrong with that, but this is larger than 1024,

and could in certain setups cause problems with:

1) software that runs at boot time (e.g., old versions of LILO)

2) booting and partitioning software from other OSs

   (e.g., DOS FDISK, OS/2 FDISK)

 

Command (m for help): n   //創建分區

Command action

   e   extended

   p   primary partition (1-4)

p                       //選擇主分區

Partition number (1-4): 1      //分區ID 1

First cylinder (1-2610, default 1):

Using default value 1

Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): 100

 

......

 

Command (m for help): t              //更改分區類型爲 Linux raid autodetect

Partition number (1-4): 1

Hex code (type L to list codes): fd

Changed system type of partition 1 to fd (Linux raid autodetect)

 

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): t

Partition number (1-4): 3

Hex code (type L to list codes): fd

Changed system type of partition 3 to fd (Linux raid autodetect)

 

Command (m for help): t

Partition number (1-4): 4

Hex code (type L to list codes): fd

Changed system type of partition 4 to fd (Linux raid autodetect)

 

Command (m for help): p           //查看分區結構

 

Disk /dev/sdb: 21.4 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

 

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1               1         100      803218+  fd  Linux raid autodetect

/dev/sdb2             101         200      803250   fd  Linux raid autodetect

/dev/sdb3             201         300      803250   fd  Linux raid autodetect

/dev/sdb4             301         400      803250   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@vm ~]#

 

2、         創建軟RAID5陣列。

[root@vm ~]# mdadm -C /dev/md0 -l 5 –n 3 -x 1 -c 128  /dev/sdb{1,2,3,4}

-C 創建 後面接創建的RAID塊設備名稱

-l 5  創建raid 5

-n 3 用於創建raid5磁盤的數量,即活動磁盤的數量,RAID5最少爲3

-x 5 備用磁盤的數量

-c 128 設置塊大小爲128K ,默認爲64K

 

3、         格式化創建的RAID陣列並掛載。

[root@vm /]# mkfs.ext3 /dev/md0   //格式化文件系統爲ext3

[root@vm /]# mount /dev/md0  /mnt/    //掛載文件系統

[root@vm /]# mdadm --detail /dev/md0     //查看詳細信息

/dev/md0:

        Version : 0.90

  Creation Time : Fri Jul 30 15:14:09 2010

     Raid Level : raid5

     Array Size : 1606144 (1568.76 MiB 1644.69 MB)

  Used Dev Size : 803072 (784.38 MiB 822.35 MB)

   Raid Devices : 3

  Total Devices : 4

Preferred Minor : 0

    Persistence : Superblock is persistent

 

    Update Time : Fri Jul 30 15:19:14 2010

          State : clean

 Active Devices : 3

Working Devices : 4

 Failed Devices : 0

  Spare Devices : 1

 

         Layout : left-symmetric

     Chunk Size : 128K

 

           UUID : 7035b6e4:31c6f22f:cb44717b:a34273bf

         Events : 0.2

 

    Number   Major   Minor   RaidDevice State

       0       8       17        0      active sync   /dev/sdb1 //注意狀態”active”

       1       8       18        1      active sync   /dev/sdb2

       2       8       19        2      active sync   /dev/sdb3

 

       3       8       20        -      spare   /dev/sdb4     //備用分區

[root@vm /]#

 

4、         模擬陣列中的某個分區失效。

[root@vm /]# mdadm /dev/md0 -f /dev/sdb3 //模擬組成rdia5sdb3磁盤失效

mdadm: set /dev/sdb3 faulty in /dev/md0

[root@vm /]#

[root@vm /]# mdadm --detail /dev/md0   //再次查看raid5 信息

/dev/md0:

        Version : 0.90

  Creation Time : Fri Jul 30 15:14:09 2010

     Raid Level : raid5

     Array Size : 1606144 (1568.76 MiB 1644.69 MB)

  Used Dev Size : 803072 (784.38 MiB 822.35 MB)

   Raid Devices : 3

  Total Devices : 4

Preferred Minor : 0

    Persistence : Superblock is persistent

 

    Update Time : Fri Jul 30 15:27:50 2010

          State : clean

 Active Devices : 3

Working Devices : 3

 Failed Devices : 1

  Spare Devices : 0

 

         Layout : left-symmetric

     Chunk Size : 128K

 

           UUID : 7035b6e4:31c6f22f:cb44717b:a34273bf

         Events : 0.6

 

    Number   Major   Minor   RaidDevice State

       0       8       17        0      active sync   /dev/sdb1

       1       8       18        1      active sync   /dev/sdb2

       2       8       20        2      active sync   /dev/sdb4

 

       3       8       19        -      faulty spare   /dev/sdb3

 

//此時備用磁盤sdb4自動轉爲activesdb3faulty狀態。

 

5、         移除失效的分區。

[root@vm /]# mdadm /dev/md0 --remove /dev/sdb3  //移除sdb3

mdadm: hot removed /dev/sdb3

[root@vm /]#

[root@vm /]# mdadm --detail /dev/md0

/dev/md0:

        Version : 0.90

  Creation Time : Fri Jul 30 15:14:09 2010

     Raid Level : raid5

     Array Size : 1606144 (1568.76 MiB 1644.69 MB)

  Used Dev Size : 803072 (784.38 MiB 822.35 MB)

   Raid Devices : 3

  Total Devices : 3

Preferred Minor : 0

    Persistence : Superblock is persistent

 

    Update Time : Fri Jul 30 15:30:44 2010

          State : clean

 Active Devices : 3

Working Devices : 3

 Failed Devices : 0

  Spare Devices : 0

 

         Layout : left-symmetric

     Chunk Size : 128K

 

           UUID : 7035b6e4:31c6f22f:cb44717b:a34273bf

         Events : 0.8

 

    Number   Major   Minor   RaidDevice State

       0       8       17        0      active sync   /dev/sdb1

       1       8       18        1      active sync   /dev/sdb2

       2       8       20        2      active sync   /dev/sdb4

[root@vm /]#

//此時sdb3已經移除了。

 

6、         重新添加分區。

[root@vm /]# mdadm /dev/md0 -a /dev/sdb3  //-a”參數添加sdb3

mdadm: added /dev/sdb3

[root@vm /]#

[root@vm /]#

[root@vm /]#

[root@vm /]# mdadm --detail /dev/md0

/dev/md0:

        Version : 0.90

  Creation Time : Fri Jul 30 15:14:09 2010

     Raid Level : raid5

     Array Size : 1606144 (1568.76 MiB 1644.69 MB)

  Used Dev Size : 803072 (784.38 MiB 822.35 MB)

   Raid Devices : 3

  Total Devices : 4

Preferred Minor : 0

    Persistence : Superblock is persistent

 

    Update Time : Fri Jul 30 15:30:44 2010

          State : clean

 Active Devices : 3

Working Devices : 4

 Failed Devices : 0

  Spare Devices : 1

 

         Layout : left-symmetric

     Chunk Size : 128K

 

           UUID : 7035b6e4:31c6f22f:cb44717b:a34273bf

         Events : 0.8

 

    Number   Major   Minor   RaidDevice State

       0       8       17        0      active sync   /dev/sdb1

       1       8       18        1      active sync   /dev/sdb2

       2       8       20        2      active sync   /dev/sdb4

 

       3       8       19        -      spare   /dev/sdb3

[root@vm /]#

 

7、         7、建立RAID配置文件。

如果沒有配置文件,在停止raid後就無法再激活
[root@mylab ~]# echo DEVICE /dev/sdb{1,2,3,4} > /etc/mdadm.conf
[root@mylab ~]# mdadm -Ds >> /etc/mdadm.conf
[root@mylab ~]# mdadm -D /dev/md0 >> /etc/mdadm.conf

 

8、         停用,啓用或移除RAID.

執行此操作之前需要完成第7步的操作。

首先卸載陣列,然後停止RAID。命令如下:

[root@vm ~]# umount /dev/md0

[root@vm ~]# mdadm --stop /dev/md0

啓用RAID,命令如下:

[root@vm ~]# mdadm --assemble --scan /dev/md0

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章