1.在确认有一块物理硬盘设备出现损坏而不能继续正常使用后,应该使用mdadm 命令将其移除,然后查看RAID 磁盘阵列的状态,可以发现状态已经改变。  

[root@Centos ~]# mdadm /dev/md0 -f /dev/sdb
mdadm: set /dev/sdb faulty in /dev/md0
[root@linuxprobe ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri May 8 08:11:00 2017
Raid Level : raid10
Array Size : 41909248 (39.97 GiB 42.92 GB)
Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Fri May 8 08:27:18 2017
State : clean, degraded
Active Devices : 3
Working Devices : 3
Failed Devices : 1
Spare Devices : 0
Layout : near=2
Chunk Size : 512K
Name : linuxprobe.com:0 (local to host linuxprobe.com)
UUID : f2993bbd:99c1eb63:bd61d4d4:3f06c3b0
Events : 21
Number Major Minor RaidDevice State
0 0 0 0 removed
1 8 32 1 active sync /dev/sdc
2 8 48 2 active sync /dev/sdd
3 8 64 3 active sync /dev/sde
0 8 16 – faulty /dev/sdb

  在 RAID 10 级别的磁盘阵列中,当RAID 1 磁盘阵列中存在一个故障盘时并不影响RAID10 磁盘阵列的使用。当购买了新的硬盘设备后再使用mdadm 命令来予以替换即可,在此期间我们可以在/RAID 目录中正常地创建或删除文件。  

[root@Centoslinuxprobe ~]# umount /RAID
[root@Centos ~]# mdadm /dev/md0 -a /dev/sdb
[root@Centos ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Mon Jan 30 00:08:56 2017
Raid Level : raid10
Array Size : 41909248 (39.97 GiB 42.92 GB)
Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
Raid Devices : 4
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Mon Jan 30 00:19:53 2017
State : clean
Active Devices : 4
Working Devices : 4
Failed Devices : 0
Spare Devices : 0
Layout : near=2
Chunk Size : 512K
Name : localhost.localdomain:0 (local to host localhost.localdomain)
UUID : d3491c05:cfc81ca0:32489f04:716a2cf0
Events : 56
Number Major Minor RaidDevice State
4 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
2 8 48 2 active sync /dev/sdd
3 8 64 3 active sync /dev/sde
[root@Centos ~]# mount –a

2.磁盘阵列+备份盘

  RAID 10 磁盘阵列中最多允许50%的硬盘设备发生故障,但是存在这样一种极端情况,即同一RAID 1 磁盘阵列中的硬盘设备若全部损坏,也会导致数据丢失。

  换句话说,在RAID10 磁盘阵列中,如果RAID 1 中的某一块硬盘出现了故障,而我们正在前往修复的路上,恰巧该RAID1 磁盘阵列中的另一块硬盘设备也出现故障,那么数据就被彻底丢失了。

  解决办法:使用RAID 备份盘技术来预防这类事故。该技术的核心理念就是准备一块足够大的硬盘,这块硬盘平时处于闲置状态,一旦RAID磁盘阵列中有硬盘出现故障后则会马上自动顶替上去。

  1)创建一个RAID 5 磁盘阵列+备份盘。  

[root@Centos ~]#mdadm -Cv /dev/md0 -n 3 -l 5 -x 1 /dev/sdb /dev/sdc /dev/
sdd /dev/sde
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 20954624K
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
[root@Centos ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri May 8 09:20:35 2017
Raid Level : raid5
Array Size : 41909248 (39.97 GiB 42.92 GB)
Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Fri May 8 09:22:22 2017
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Name : linuxprobe.com:0 (local to host linuxprobe.com)
UUID : 44b1a152:3f1809d3:1d234916:4ac70481
Events : 18
Number Major Minor RaidDevice State
0 8 16 0 active sync /dev/sdb
1 8 32 1 active sync /dev/sdc
4 8 48 2 active sync /dev/sdd
3 8 64 - spare /dev/sde

  参数-n 3 代表创建这个RAID 5 磁盘阵列所需的硬盘数,参数-l 5 代表RAID 的级别,而参数-x 1 则代表有一块备份盘。当查看/dev/md0(即RAID 5 磁盘阵列的名称)磁盘阵列的时候就能看到有一块备份盘在等待中了。

  将部署好的RAID 5 磁盘阵列格式化为ext4 文件格式,然后挂载到目录上,之后就可以使用了。  

[root@Centos ~]# 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=128 blocks, Stripe width=256 blocks
2621440 inodes, 10477312 blocks
523865 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2157969408
320 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, 7962624
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[root@Centos ~]# echo "/dev/md0 /RAID ext4 defaults 0 0" >> /etc/fstab
[root@Centos ~]# mkdir /RAID
[root@Centos ~]# mount -a

  再次把硬盘设备/dev/sdb 移出磁盘阵列,然后迅速查看/dev/md0 磁盘阵列的状态,就会发现备份盘已经被自动顶替上去并开始了数据同步。RAID 中的这种备份盘技术非常实用,可以在保证RAID 磁盘阵列数据安全性的基础上进一步提高数据可靠性,

  所以,如果公司不差钱的话还是再买上一块备份盘以防万一。  

[root@Centos ~]# mdadm /dev/md0 -f /dev/sdb
mdadm: set /dev/sdb faulty in /dev/md0
[root@Centos ~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Fri May 8 09:20:35 2017
Raid Level : raid5
Array Size : 41909248 (39.97 GiB 42.92 GB)
Used Dev Size : 20954624 (19.98 GiB 21.46 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Fri May 8 09:23:51 2017
State : active, degraded, recovering
Active Devices : 2
Working Devices : 3
Failed Devices : 1
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Rebuild Status : 0% complete
Name : linuxprobe.com:0 (local to host linuxprobe.com)
UUID : 44b1a152:3f1809d3:1d234916:4ac70481
Events : 21
Number Major Minor RaidDevice State
3 8 64 0 spare rebuilding /dev/sde
1 8 32 1 active sync /dev/sdc
4 8 48 2 active sync /dev/sdd
0 8 16 - faulty /dev/sdb

 

posted on 2020-08-19 17:03  星痕1216  阅读(962)  评论(0编辑  收藏  举报