首页 > 代码库 > RAID

RAID

 

 

 

操作

分区

# fdisk -l

......

Disk/dev/sdb: 32.2 GB, 32212254720 bytes

255 heads, 63 sectors/track, 3916 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

 

 

Disk/dev/sdc: 32.2 GB, 32212254720 bytes

255 heads, 63 sectors/track, 3916 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

......

 

[root@localhost ~]# fdisk /dev/sdb

 

wKiom1Pss4-y6xqNAAG8-mw4TfI470.jpgwKioL1PstLzxHFrrAAGDsavKoOA731.jpg

 

 

 

 

建立RAID1

 

 

[root@localhost ~]# mdadm -C /dev/md0 -l 1-n 2 /dev/sd[bc][1]

mdadm: Note: this array has metadata at the startand

    may notbe suitable as a boot device.  If youplan to

    store‘/boot‘ on this device please ensure that

    yourboot-loader understands md/v1.x metadata, or use

   --metadata=http://www.mamicode.com/0.90

Continue creating array? y

mdadm: Defaulting to version 1.2 metadata

mdadm: array /dev/md0 started.

 

 

wKioL1PstNzAN-4_AAEJ9wlz4X4160.jpg

 

 

dmesg中会看到如下信息

md: bind<sdb1>

md: bind<sdc1>

md: raid1 personality registered for  level 1

bio: create slab <bio-1> at 1

md/raid1:md0: not clean -- starting background  reconstruction

md/raid1:md0: active with 2 out of 2  mirrors

md0: detected capacity change from 0 to  32193249280

 md0:

md: resync of RAID array md0

md: minimum _guaranteed_  speed: 1000 KB/sec/disk.

md: using maximum available idle IO  bandwidth (but not more than 200000 KB/sec) for resync.

md: using 128k window, over a total of  31438720k.

 unknown partition table

 

 

创建文件系统

格式化该磁盘阵列 

[root@localhost ~]# mkfs.ext4 /dev/md0

 

[root@localhost ~]# mkdir /data

[root@localhost ~]# mount /dev/md0 /data

[root@localhost ~]# ll /data/

total 16

drwx------ 2 root root 16384 Aug 14 15:21lost+found

 

[root@localhost ~]# vi /etc/fstab

最后添加

/dev/md0         /data         ext4   defaults        0 0

 

[root@localhost ~]# mdadm -Ds >> /etc/mdadm.conf

 

 

模拟故障

30GBA.VMDK删除,只保留RAID1中另外一个成员。

 wKioL1Pstinz7QvyAAIJ5gvLZ9M982.jpg

 

 

 

[root@localhost ~]# cat /proc/mdstat

Personalities : [raid1]

md0 : active raid1 sdb1[0](F) sdc1[1]

     31438720 blocks super 1.2 [2/1] [_U]

 

unused devices: <none>

RAID1重建

模拟恢复,还是30GB的硬盘,添加新的磁盘文件将30GBC.VMDK

wKioL1Pstjux69nVAAIjhOgp3X4041.jpg

 

[root@localhost ~]# fdisk -l /dev/sdb

 

Disk /dev/sdb: 32.2 GB, 32212254720 bytes

255 heads, 63 sectors/track, 3916 cylinders

Units = cylinders of 16065 * 512 = 8225280bytes

Sector size (logical/physical): 512 bytes /512 bytes

I/O size (minimum/optimal): 512 bytes / 512bytes

Disk identifier: 0x9b6ff607

 

  Device Boot      Start         End      Blocks  Id  System

/dev/sdb1      1      3916    31455238+  fd Linux raid autodetect

 

 

[root@localhost ~]# mdadm /dev/md0 -a /dev/sdb1

mdadm: added /dev/sdb1

 

[root@localhost ~]# cat /proc/mdstat

Personalities : [raid1]

md0 : active raid1 sdb1[2] sdc1[1]

     31438720 blocks super 1.2 [2/1] [_U]

     [=>...................] recovery =  7.0%(2201920/31438720) finish=2.4min speed=200174K/sec

 

unused devices: <none>

完成.