RAID-1 :mirroring(镜像卷)需要磁盘两块以上
原理:是把一个磁盘的数据镜像到另一个磁盘上,也就是说数据在写入一块磁盘的同时,会在另一块闲置的磁盘上生成镜像文件,(同步)
特性:当一块硬盘失效时,系统会忽略该硬盘,转而使用剩余的镜像盘读写数据,具备很好的磁盘冗余能力。
磁盘利用率为50%,即2块100G的磁盘构成RAID1只能提供100G的可用空间。
fdisk /dev/sdd
[root@centos7-xinsz08 ~]# ll /dev/sdd*
brw-rw----. 1 root disk 8, 48 2月 27 16:22 /dev/sdd
brw-rw----. 1 root disk 8, 49 2月 27 16:22 /dev/sdd1
brw-rw----. 1 root disk 8, 50 2月 27 16:22 /dev/sdd2
brw-rw----. 1 root disk 8, 51 2月 27 16:22 /dev/sdd3
brw-rw----. 1 root disk 8, 52 2月 27 16:22 /dev/sdd4
`
[root@centos7-xinsz08 ~]# mdadm -C -v /dev/md2 -l 1 -n 2 -x 1 /dev/sdd1 /dev/sdd[2,3]
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: size set to 3140608K
mdadm: largest drive (/dev/sdd1) exceeds size (3140608K) by more than 1%
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md2 started.
[root@centos7-xinsz08 ~]# mdadm -Dsv > /etc/mdadm.conf
[root@centos7-xinsz08 ~]# mdadm -D /dev/md2
/dev/md2: //设备名
Version : 1.2
Creation Time : Thu Feb 27 16:24:39 2020 .//创建时间
Raid Level : raid1
Array Size : 3140608 (3.00 GiB 3.22 GB)
Used Dev Size : 3140608 (3.00 GiB 3.22 GB)
Raid Devices : 2
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Thu Feb 27 16:25:01 2020
State : clean
Active Devices : 2 //当前活动设备
Working Devices : 3 .//工作设备
Failed Devices : 0 // 失效设备
Spare Devices : 1 //热备盘的数量
Consistency Policy : resync
Name : centos7-xinsz08:2 (local to host centos7-xinsz08)
UUID : 5e197fe2:5c51970e:5e5288d5:e9066eb4
Events : 17
Number Major Minor RaidDevice State
0 8 49 0 active sync /dev/sdd1
1 8 50 1 active sync /dev/sdd2
2 8 51 - spare /dev/sdd3
[root@centos7-xinsz08 ~]# mkfs.xfs /dev/md2
meta-data=/dev/md2 isize=512 agcount=4, agsize=196288 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=785152, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@centos7-xinsz08 ~]# mkdir /raid1
[root@centos7-xinsz08 ~]# mount /dev/md2 /raid1/
[root@centos7-xinsz08 ~]# df -h | tail -1
/dev/md2 3.0G 33M 3.0G 2% /raid1
[root@centos7-xinsz08 raid1]# touch a.txt
[root@centos7-xinsz08 raid1]# echo "磁盘坏了,我也在" >a.txt
[root@centos7-xinsz08 raid1]# mdadm /dev/md2 -f /dev/sdd1
mdadm: set /dev/sdd1 faulty in /dev/md2
[root@centos7-xinsz08 raid1]# mdadm -D /dev/md2
/dev/md2:
Version : 1.2
Creation Time : Thu Feb 27 16:24:39 2020
Raid Level : raid1
Array Size : 3140608 (3.00 GiB 3.22 GB)
Used Dev Size : 3140608 (3.00 GiB 3.22 GB)
Raid Devices : 2
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Thu Feb 27 16:31:48 2020
State : clean, degraded, recovering
Active Devices : 1
Working Devices : 2
Failed Devices : 1
Spare Devices : 1
Consistency Policy : resync
Rebuild Status : 88% complete
Name : centos7-xinsz08:2 (local to host centos7-xinsz08)
UUID : 5e197fe2:5c51970e:5e5288d5:e9066eb4
Events : 35
Number Major Minor RaidDevice State
2 8 51 0 spare rebuilding /dev/sdd3
1 8 50 1 active sync /dev/sdd2
0 8 49 - faulty /dev/sdd1
测试移除之后文件是否还在
[root@centos7-xinsz08 raid1]# cat /raid1/a.txt
磁盘坏了,我也在
[root@centos7-xinsz08 raid1]# mdadm -r /dev/md2 /dev/sdd1
mdadm: hot removed /dev/sdd1 from /dev/md2
``
查看是否移除
```bash
[root@centos7-xinsz08 raid1]# mdadm -D /dev/md2
/dev/md2:
Version : 1.2
Creation Time : Thu Feb 27 16:24:39 2020
Raid Level : raid1
Array Size : 3140608 (3.00 GiB 3.22 GB)
Used Dev Size : 3140608 (3.00 GiB 3.22 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Feb 27 16:34:10 2020
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Consistency Policy : resync
Name : centos7-xinsz08:2 (local to host centos7-xinsz08)
UUID : 5e197fe2:5c51970e:5e5288d5:e9066eb4
Events : 39
Number Major Minor RaidDevice State
2 8 51 0 active sync /dev/sdd3
1 8 50 1 active sync /dev/sdd2
mdadm -a /dev/md2 /dev/sdb4