raid 5基本创建过程

我的机器硬盘分区情况
[root@centos ~]# fdisk -l

Disk /dev/sda: 79.9 GB, 79949722112 bytes
255 heads, 63 sectors/track, 9720 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2563    20482875   83  Linux
/dev/sda3            2564        3838    10241437+  83  Linux
/dev/sda4            3839        9720    47247165    5  Extended
/dev/sda5            3839        5113    10241406   83  Linux
/dev/sda6            5114        5750     5116671   83  Linux
/dev/sda7            5751        5877     1020096   82  Linux swap / Solaris
/dev/sda8            5878        5890      104391   83  Linux
/dev/sda9            5891        5903      104391   83  Linux
/dev/sda10           5904        5916      104391   83  Linux
/dev/sda11           5917        5929      104391   83  Linux


用sda8、9、10、11四个分区做raid 5,其中一个为sparedisk
[root@centos ~]# mdadm --create --auto=yes /dev/md0 --level=5 \
> --raid-devices=3 --spare-devices=1 /dev/sda{8,9,10,11}

mdadm: array /dev/md0 started.

[root@centos ~]# mdadm --detail /dev/md0 
/dev/md0:
        Version : 0.90
  Creation Time : Fri Sep  2 00:31:52 2011
     Raid Level : raid5
     Array Size : 208640 (203.78 MiB 213.65 MB)         --raid总容量
  Used Dev Size : 104320 (101.89 MiB 106.82 MB)         --每个设备容量
   Raid Devices : 3         --作为raid的设备数
  Total Devices : 4
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Fri Sep  2 00:32:03 2011
          State : clean
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1

         Layout : left-symmetric
     Chunk Size : 64K

           UUID : 9f8f1b13:aa5672df:5bdf3333:2b166b17
         Events : 0.2

    Number   Major   Minor   RaidDevice State
       0       8        8        0      active sync   /dev/sda8
       1       8        9        1      active sync   /dev/sda9
       2       8       10        2      active sync   /dev/sda10

       3       8       11        -      spare   /dev/sda11
  
  
格式化

[root@centos ~]# mkfs -t ext3 /dev/md0 
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
52208 inodes, 208640 blocks
10432 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
26 block groups
8192 blocks per group, 8192 fragments per group
2008 inodes per group
Superblock backups stored on blocks: 
        8193, 24577, 40961, 57345, 73729, 204801

Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.


把raid挂载到/mnt/raid
[root@centos ~]# mkdir /mnt/raid
[root@centos ~]# mount /dev/md0 /mnt/raid/
[root@centos ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda5              9920592   5487808   3920716  59% /
/dev/sda6              4956284   1511328   3189124  33% /opt
/dev/sda3              9920624    557688   8850868   6% /var
/dev/sda2             19840924  14392460   4424324  77% /home
/dev/sda1               101086     16954     78913  18% /boot
tmpfs                   516808         0    516808   0% /dev/shm
/dev/md0                202047      5920    185695   4% /mnt/raid
  

[root@centos ~]# cd /mnt/raid/
[root@centos raid]# ls
lost+found
[root@centos raid]# touch test
[root@centos raid]# vi test 

hello world!
~
~
"test" 1L, 13C written


把sda8变成错误状态
[root@centos raid]# mdadm --manage /dev/md0 --fail /dev/sda8 
mdadm: set /dev/sda8 faulty in /dev/md0

[root@centos raid]# mdadm --detail /dev/md0 
/dev/md0:
        Version : 0.90
  Creation Time : Fri Sep  2 00:31:52 2011
     Raid Level : raid5
     Array Size : 208640 (203.78 MiB 213.65 MB)
  Used Dev Size : 104320 (101.89 MiB 106.82 MB)
   Raid Devices : 3
  Total Devices : 4
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Fri Sep  2 00:46:54 2011
          State : clean
 Active Devices : 3
Working Devices : 3
 Failed Devices : 1
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 64K

           UUID : 9f8f1b13:aa5672df:5bdf3333:2b166b17
         Events : 0.6

    Number   Major   Minor   RaidDevice State
       0       8       11        0      active sync   /dev/sda11       --已经自动重建了
       1       8        9        1      active sync   /dev/sda9             
       2       8       10        2      active sync   /dev/sda10

       3       8        8        -      faulty spare   /dev/sda8
  
[root@centos raid]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4] 
md0 : active raid5 sda10[2] sda11[0] sda9[1] sda8[3](F)
      208640 blocks level 5, 64k chunk, algorithm 2 [3/3] [UUU]
      
unused devices:


[root@centos raid]# cat test 
hello world!               --数据还在



[root@centos raid]# fdisk /dev/sda

The number of cylinders for this disk is set to 9720.
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
First cylinder (5930-9720, default 5930): 
Using default value 5930
Last cylinder or +size or +sizeM or +sizeK (5930-9720, default 9720): +100M

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.
    
[root@centos raid]# partprobe 


[root@centos raid]# fdisk -l

Disk /dev/sda: 79.9 GB, 79949722112 bytes
255 heads, 63 sectors/track, 9720 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2563    20482875   83  Linux
/dev/sda3            2564        3838    10241437+  83  Linux
/dev/sda4            3839        9720    47247165    5  Extended
/dev/sda5            3839        5113    10241406   83  Linux
/dev/sda6            5114        5750     5116671   83  Linux
/dev/sda7            5751        5877     1020096   82  Linux swap / Solaris
/dev/sda8            5878        5890      104391   83  Linux
/dev/sda9            5891        5903      104391   83  Linux
/dev/sda10           5904        5916      104391   83  Linux
/dev/sda11           5917        5929      104391   83  Linux
/dev/sda12           5930        5942      104391   83  Linux

Disk /dev/md0: 213 MB, 213647360 bytes
2 heads, 4 sectors/track, 52160 cylinders
Units = cylinders of 8 * 512 = 4096 bytes

Disk /dev/md0 doesn't contain a valid partition table


用sda12替换sda8
[root@centos raid]# mdadm --manage /dev/md0 --add /dev/sda12 --remove /dev/sda8
mdadm: added /dev/sda12
mdadm: hot removed /dev/sda8

[root@centos raid]# mdadm --detail /dev/md0 
/dev/md0:
        Version : 0.90
  Creation Time : Fri Sep  2 00:31:52 2011
     Raid Level : raid5
     Array Size : 208640 (203.78 MiB 213.65 MB)
  Used Dev Size : 104320 (101.89 MiB 106.82 MB)
   Raid Devices : 3
  Total Devices : 4
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Fri Sep  2 01:03:12 2011
          State : clean
 Active Devices : 3
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 1

         Layout : left-symmetric
     Chunk Size : 64K

           UUID : 9f8f1b13:aa5672df:5bdf3333:2b166b17
         Events : 0.8

    Number   Major   Minor   RaidDevice State
       0       8       11        0      active sync   /dev/sda11
       1       8        9        1      active sync   /dev/sda9
       2       8       10        2      active sync   /dev/sda10

       3       8       12        -      spare   /dev/sda12           --恢复了
  
关闭raid

[root@centos ~]# umount /mnt/raid/
[root@centos ~]# mdadm --stop /dev/md0 
mdadm: stopped /dev/md0
[root@centos ~]# cat /proc/mdstat 
Personalities : [raid6] [raid5] [raid4]   --没有设备了
unused devices:

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25361369/viewspace-706514/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/25361369/viewspace-706514/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值