做这个实验我们需要新添加两块30G的硬盘
[[email protected] ~]# uname -a
Linux ZZSRV1.localdomain 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
我们可以不用重启就能显示出磁盘
[[email protected] ~]# echo "- - -" > /sys/class/scsi_host/host0/scan
[[email protected] ~]# echo "- - -" > /sys/class/scsi_host/host1/scan
[[email protected] ~]# echo "- - -" > /sys/class/scsi_host/host2/scan
查看磁盘
[[email protected] ~]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0003747c
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 83886079 41430016 8e Linux LVM
Disk /dev/sdb: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sdc: 32.2 GB, 32212254720 bytes, 62914560 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
安装mdadm
[[email protected] ~]# mount /dev/cdrom /mnt/cdrom/
[[email protected] ~]# cd /mnt/cdrom/Packages/
[[email protected] Packages]# ls mdadm*
mdadm-3.2.6-31.el7.x86_64.rpm
[[email protected] Packages]# rpm -ivh mdadm-3.2.6-31.el7.x86_64.rpm
warning: mdadm-3.2.6-31.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [100%]
package mdadm-3.2.6-31.el7.x86_64 is already installed
给磁盘分区
[[email protected] Packages]# fdisk /dev/sdb
[[email protected] Packages]# fdisk /dev/sdc
创建RAID1卷
[[email protected] ~]# mdadm -Cv /dev/md0 -l1 -n2 /dev/sdc1 /dev/sdb1
mdadm: /dev/sdc1 appears to contain an ext2fs file system
size=31456256K mtime=Thu Jan 1 08:00:00 1970
mdadm: Note: this array has metadata at the start and
may not be suitable as a boot device. If you plan to
store ‘/boot‘ on this device please ensure that
your boot-loader understands md/v1.x metadata, or use
--metadata=0.90
mdadm: /dev/sdb1 appears to contain an ext2fs file system
size=31456256K mtime=Thu Jan 1 08:00:00 1970
mdadm: size set to 31439744K
Continue creating array? (y/n) y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[[email protected] ~]# cd /
[[email protected] /]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[1] sdc1[0]
31439744 blocks super 1.2 [2/2] [UU]
[========>............] resync = 41.6% (13101184/31439744) finish=1.5min speed=199772K/sec
unused devices: <none>
格式化RAID卷
[[email protected] Packages]# mkfs.ext4 /dev/md0
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5238496 blocks
261924 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2153775104
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[[email protected] Packages]# mkdir /data
[[email protected] Packages]# mount /dev/md0 /data
[[email protected] Packages]# ll /data/
total 16
drwx------ 2 root root 16384 Aug 15 00:31 lost+found
[[email protected] Packages]# mdadm -Ds
ARRAY /dev/md0 metadata=1.2 name=ZZSRV1.localdomain:0 UUID=c2fe6a35:461511e9:7e9bf672:9baeb95c
[[email protected] Packages]# mdadm -Ds >> /etc/mdadm.conf
[[email protected] Packages]# vi /etc/fstab
在最后添加
/dev/md0 /data ext4 defaults 0 0
[[email protected] Packages]# mdadm -Ds
ARRAY /dev/md0 metadata=1.2 name=ZZSRV1.localdomain:0 UUID=c2fe6a35:461511e9:7e9bf672:9baeb95c
[[email protected] Packages]# mdadm -Ds >> /etc/mdadm.conf
[[email protected] Packages]# reboot
[[email protected] ~]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/md0 on /data type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
[[email protected] ~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[0] sdc1[1]
31438720 blocks super 1.2 [2/2] [UU]
unused devices: <none>
我们可以模拟故障
将一块30G的硬盘删除
查看日志会出现 需要等一会
sd 2:0:1:0: [sdb] Unhandled error code
sd 2:0:1:0: [sdb] Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK
sd 2:0:1:0: [sdb] CDB: Write(10): 2a 00 00 00 00 47 00 00 01 00
md: super_written gets error=-5, uptodate=0
md/raid1:md0: Disk failure on sdb1, disabling device.
md/raid1:md0: Operation continuing on 1 devices.
RAID1 conf printout:
--- wd:1 rd:2
disk 0, wo:1, o:0, dev:sdb1
disk 1, wo:0, o:1, dev:sdc1
RAID1 conf printout:
--- wd:1 rd:2
disk 1, wo:0, o:1, dev:sdc1
sd 2:0:1:0: [sdb] Unhandled error code
sd 2:0:1:0: [sdb] Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK
sd 2:0:1:0: [sdb] CDB: Write(10): 2a 00 00 00 00 47 00 00 01 00
md: super_written gets error=-5, uptodate=0
md/raid1:md0: Disk failure on sdb1, disabling device.
md/raid1:md0: Operation continuing on 1 devices.
[[email protected] ~]# 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
模拟恢复,添加一块新的30G硬盘
[[email protected] ~]# fdisk -l /dev/sdb
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 / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9b6ff607
Device Boot Start End Blocks Id System
/dev/sdb1 2048 62914559 31456256 83 Linux
在线加入新组成单元
[[email protected] ~]# mdadm /dev/md0 -a /dev/sdb1
mdadm: added /dev/sdb1
[[email protected] ~]# 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>
在日志中我们可以看到重建过程
md: bind<sdb1>
md: recovery 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 recovery.
md: using 128k window, over a total of 31438720k.
md: md0: recovery done.
两块30G硬盘做RAID1