tile 发表于 2013-7-10 09:19:35

软件磁盘阵列(Software RAID)

RAID可以透过一个技术(软件或硬件),将多个较小的磁盘整合成为一个较大的磁盘装置;而这个较大的磁盘功能不只是存储,还具有数据保护的功能。RAID选择的level不同,使得整合后的磁盘具有不同的功能。

常见的level:         RAID-0(等量模式):性能最佳         RAID-1(映像模式):完整备份         RAID 0+1
         RAID 5:性能与数据备份的均衡考虑         Spare Disk:预备磁盘的功能
磁盘阵列的优点:            当磁盘损毁时,数据能够安全的恢复            RAID 0可以加强读写性能            可以让多个磁盘组合起来,单一的文件系统可以有相当大的容量
软件磁盘阵列的设定:
             设定很简单,只要使用mdadm这个指令即可。             
   我实验的环境都是在vmware下进行的,所以添加一块10G的硬盘(这个应该很简单)做测试



# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006bd09
   Device Boot      Start         End      Blocks   IdSystem
/dev/sda1   *         1      2481    19921920   83Linux
/dev/sda2            2481      2611   1046529    5Extended
/dev/sda5            2481      2611   1046528   82Linux swap / Solaris
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb8b17d21
   Device Boot      Start         End      Blocks   IdSystem我希望做成的RAID 5环境:         利用4个partition组成RAID 5         每个partition约为1G,需确定每个partition一样大         利用1个partition设定为spare disk         这个spare disk的大小与其他RAID所需partition一样大         将此RAID 5装置挂载到/mnt/raid目录下
建立所需的磁盘装置:      需要5个1G的分区
# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-1305, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-1305, default 1305): +1G
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (133-1305, default 133):
Using default value 133
Last cylinder, +cylinders or +size{K,M,G} (133-1305, default 1305): +1G
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (265-1305, default 265):
Using default value 265
Last cylinder, +cylinders or +size{K,M,G} (265-1305, default 1305): +1G
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
e
Selected partition 4
First cylinder (397-1305, default 397):
Using default value 397
Last cylinder, +cylinders or +size{K,M,G} (397-1305, default 1305):
Using default value 1305
Command (m for help): n
First cylinder (397-1305, default 397):
Using default value 397
Last cylinder, +cylinders or +size{K,M,G} (397-1305, default 1305): +1G
Command (m for help): n
First cylinder (529-1305, default 529):
Using default value 529
Last cylinder, +cylinders or +size{K,M,G} (529-1305, default 1305): +1G
Command (m for help): p
Disk /dev/sdb: 10.7 GB, 10737418240 bytes
255 heads, 63 sectors/track, 1305 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xb8b17d21
   Device Boot      Start         End      Blocks   IdSystem
/dev/sdb1               1         132   1060258+83Linux
/dev/sdb2             133         264   1060290   83Linux
/dev/sdb3             265         396   1060290   83Linux
/dev/sdb4             397      1305   7301542+   5Extended
/dev/sdb5             397         528   1060258+83Linux
/dev/sdb6             529         660   1060258+83Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.


1
# partprobe


用mdadm建立RAID:

    通过mdadm建立磁盘阵列
# mdadm --create --auto=yes /dev/md0 --level=5 \
> --raid-devices=4 --spare-devices=1 /dev/sdb{1,2,3,5,6}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

    查看阵列信息
# mdadm --detail /dev/md0
/dev/md0:
      Version : 1.2
Creation Time : Tue Jul9 16:51:39 2013
   Raid Level : raid5
   Array Size : 3176448 (3.03 GiB 3.25 GB)
Used Dev Size : 1058816 (1034.17 MiB 1084.23 MB)
   Raid Devices : 4
Total Devices : 5
    Persistence : Superblock is persistent
    Update Time : Tue Jul9 16:51:59 2013
          State : clean
Active Devices : 4
Working Devices : 5
Failed Devices : 0
Spare Devices : 1
         Layout : left-symmetric
   Chunk Size : 512K
         Name : minilinux:0(local to host minilinux)
         UUID : 79a8d5ba:b04180ca:a72133ce:358877a4
         Events : 18
    Number   Major   Minor   RaidDevice State
       0       8       17      0      active sync   /dev/sdb1
       1       8       18      1      active sync   /dev/sdb2
       2       8       19      2      active sync   /dev/sdb3
       5       8       21      3      active sync   /dev/sdb5
       4       8       22      -      spare   /dev/sdb6
    注:RaidDevice指的就是在此RAID内的磁盘顺序

   也可以通过/proc/mdstat查看磁盘阵列信息
# cat /proc/mdstat
Personalities :
md0 : active raid5 sdb5 sdb6(S) sdb3 sdb2 sdb1
      3176448 blocks super 1.2 level 5, 512k chunk, algorithm 2
   
总共有3行,主要解释后两行。
第二行:指出md0为raid5 使用了sdb1 sdb2 sdb3 sdb5 sdb6 5个磁盘分区。每个分区后面中括号[]内的数字为此磁盘在RAID中的顺序(RaidDevice),sdb6后面的代表spare.

第三行:此磁盘阵列有3176448个block(每个block单位为1K),使用RAID 5,写入磁盘的小区块(chunk)大小为512K,使用algorithm 2磁盘阵列算法。代表此磁盘阵列需要m个分区,且n个分区正常工作。此md0需要4个分区且4个分区都正常工作。后面的代表4个所需的分区的启动情况,U代表正常工作,若为_则代表不正常。


格式化与挂载使用RAID:
   格式化/dev/md0
# mkfs -t ext4 /dev/md0
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=128 blocks, Stripe width=384 blocks
198800 inodes, 794112 blocks
39705 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=813694976
25 block groups
32768 blocks per group, 32768 fragments per group
7952 inodes per group
Superblock backups stored on blocks:
      32768, 98304, 163840, 229376, 294912
Writing inode tables: done                        
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first.Use tune2fs -c or -i to override.

挂载/dev/md0
# mkdir /mnt/raid
# mount /dev/md0 /mnt/raid
# df
Filesystem         1K-blocks      Used Available Use% Mounted on
/dev/sda1             19609276   134088017272300   8% /
tmpfs                   118188         0    118188   0% /dev/shm
/dev/md0               3126500   70192   2897488   3% /mnt/raid
发现多个一个/dev/md0的装置


所谓覅破解 发表于 2013-7-10 10:06:56

流氓不可怕,就怕流氓有文化。

qq78707 发表于 2013-7-10 17:47:41

要是我灌水,就骂我“三个代表”没学好吧。

della0887 发表于 2013-7-11 09:34:40

美女未抱身先走,常使色狼泪满襟。。。。。。

ddsdjn 发表于 2013-7-11 13:13:49

如果恐龙是人,那人是什么?

bobbai 发表于 2013-7-11 20:01:45

我是来刷分的,嘿嘿

刘伟 发表于 2013-7-11 21:42:52

饭在锅里,我在床上*^_^*
页: [1]
查看完整版本: 软件磁盘阵列(Software RAID)