一,RAID 的认识
多快同时存储,速度快,但没有备份,不安全
只有一个在正在存数据,一个备份,速度慢,安全
数据随机在一个盘中建立检验。允许一个盘坏掉
数据随机在两个盘中建立检验,容许两个坏掉
二、配置RAID的大致步骤:
1、建立对应磁盘阵列
mdadm -C -v /dev/md0 -l 0 -n 2 /dev/sdb /dev/sdc #-C创建,跟raid名称与路径;-l 后跟RAID的类型 ;-n阵列化的磁盘数 ;最后是被列阵化的具体磁盘
2、生成配置文件
配置文件在 /etc/ mdadm.conf,若没有先touch建立
mdadm -Dsv /dev/md0 > /etc/ mdadm.conf
3、格式化
mkfs.xfs /dev/md0
4、挂载磁盘
mount /dev/md0 /raid0 #挂载/raid0,临时
或者是
vim /etc/fstab
/dev/vd0 /raid0 xfs defaults 0 0 #输入,永久保存
或者[
root@localhost ~]# blkid /dev/md0
/dev/md0: UUID="41918eb2-4385-4644-9629-dc4297ce2624" TYPE="xfs"
[root@localhost ~]# echo "UUID=41918eb2-4385-4644-9629-dc4297ce2624 /md0 xfs defaults 0 0" >> /etc/fstab
#移除一块硬盘之后,硬盘设备的名称也随之而改变了,所以最好用UUID挂载硬盘
三、
1、配置RAID0
如图,有b~g六个空磁盘
lsblk #查看磁盘
生成raid0的
生成配置文件
格式化和挂载
2、卸载RAID 0
[root@localhost etc]# umount /dev/md0 #卸载挂载
[root@localhost etc]# mdadm -S /dev/md0 停止md0
[root@localhost etc]# mdadm --zero-superblock /dev/sd0 #移除数据
[root@localhost etc]# cat /dev/null > /etc/mdadm.conf #目前mdadm中只有md0的,可以清空配置
3.1、配置RAID1
mdadm -C -v /dev/md11 -l 1 -n 2 /dev/sda /dev/sdb #创建raid1,-C创建,跟raid名称与路径;-l 后跟RAID的类型 ;-n阵列化的磁盘数 ;最后是被列阵化的具体磁盘
[root@localhost etc]# mdadm -C -v /dev/md11 -l 1 -n 2 /dev/sdc /dev/sdb # 创建一个raid1,名为md11
mdadm: /dev/sdc appears to be part of a raid array:
level=raid0 devices=2 ctime=Mon May 10 14:42:39 2021
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/sdb appears to be part of a raid array:
level=raid0 devices=2 ctime=Mon May 10 14:42:39 2021
mdadm: size set to 20954112K
Continue creating array? y #y确认
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md11 started.
[root@localhost etc]# mdadm -Dsv /dev/ /md11 > /etc/mdadm.conf # 配置文件
[root@localhost etc]# mkfs.xfs /dev/md11 #格式化md11
meta-data=/dev/md11 isize=512 agcount=4, agsize=1309632 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=5238528, 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@localhost etc]# mkdir /raid11
[root@localhost etc]# mount /dev/md11 /raid11 # 挂载
3.2、RAID1 的热备份
[root@localhost etc]# mdadm -a /dev/md11 /dev/sdd #增加区
mdadm: /dev/ /md11 is an invalid name for an md device - ignored.
mdadm: added /dev/sdd
[root@localhost etc]# lsblk #此时看到sdd出现在md11
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 190G 0 part /boot
└─sda2 8:2 0 10G 0 part
├─centos-root 253:0 0 7G 0 lvm /
└─centos-swap 253:1 0 3G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
└─md11 9:11 0 20G 0 raid1 /raid11
sdc 8:32 0 20G 0 disk
└─md11 9:11 0 20G 0 raid1 /raid11
sdd 8:48 0 20G 0 disk
└─md11 9:11 0 20G 0 raid1 /raid11
sde 8:64 0 20G 0 disk
sdf 8:80 0 20G 0 disk
sdg 8:96 0 20G 0 disk
sr0 11:0 1 4.3G 0 rom /run/media/root/CentOS 7 x86_64
[root@localhost etc]# mdadm -r /dev/md11 /dev/sdd #移除盘,注意慎用,当有数据数据时不能移除
mdadm: /dev/ /md11 is an invalid name for an md device - ignored.
mdadm: hot removed /dev/sdd from /dev/md11
[root@localhost etc]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 200G 0 disk
├─sda1 8:1 0 190G 0 part /boot
└─sda2 8:2 0 10G 0 part
├─centos-root 253:0 0 7G 0 lvm /
└─centos-swap 253:1 0 3G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
└─md11 9:11 0 20G 0 raid1 /raid11
sdc 8:32 0 20G 0 disk
└─md11 9:11 0 20G 0 raid1 /raid11
sdd 8:48 0 20G 0 disk
sde 8:64 0 20G 0 disk
sdf 8:80 0 20G 0 disk
4、设置热备份的盘
先把之前的raid去掉
[root@localhost etc]# umount /dev/md11
[root@localhost etc]# mdadm -S /dev/md11
[root@localhost etc]# cat /dev/null > /etc/mdadm.conf
重新创建,-x指定热备份的数量
mdadm -C -v /dev/md11 -l 1 -n 2 -x 1 /dev/sd[b-d] #组内工作的2个盘,热备一个
这时候如再加一个盘到md11时,依旧为热备份盘,不能正常使用。raid1是两个磁盘,也无法单独加一个盘,拓展磁盘时可以和lvm结合,达到单独加一个盘的需要。
5、配置RAID5
[root@localhost ~]# mdadm -C -v /dev/md5 -l5 -n3 -x1 /dev/sd[b,c,d,e] //3块盘做raid5,1块盘做热备
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: /dev/sdb appears to be part of a raid array:
level=raid5 devices=4 ctime=Mon May 10 02:27:56 2021
mdadm: /dev/sdc appears to be part of a raid array:
level=raid5 devices=4 ctime=Mon May 10 02:27:56 2021
mdadm: /dev/sdd appears to be part of a raid array:
level=raid5 devices=4 ctime=Mon May 10 02:27:56 2021
mdadm: /dev/sde appears to be part of a raid array:
level=raid5 devices=4 ctime=Mon May 10 02:27:56 2021
mdadm: size set to 20954112K
Continue creating array? y <----这里输入y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.
[root@localhost ~]# mdadm -D /dev/md5 //查看状态
/dev/md5:
Version : 1.2
Creation Time : Mon May 10 02:34:28 2021
Raid Level : raid5
Array Size : 41908224 (39.97 GiB 42.91 GB)
Used Dev Size : 20954112 (19.98 GiB 21.46 GB)
Raid Devices : 3
Total Devices : 4
Persistence : Superblock is persistent
Update Time : Mon May 10 02:35:11 2021
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : localhost.localdomain:5 (local to host localhost.localdomain)
UUID : 19141953:15e712a3:70fc1faa:220b06c7
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 //热备盘
[root@localhost ~]# mdadm -Dvs > /etc/mdadm.conf //写入配置
[root@localhost ~]# mkfs.xfs /dev/md5
meta-data=/dev/md5 isize=512 agcount=16, agsize=654720 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=10475520, imaxpct=25
= sunit=128 swidth=256 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=5120, version=2
= sectsz=512 sunit=8 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# mkdir /raid5
[root@localhost ~]# mount /dev/md5 /raid5/
6,创建RAID 10
创建raid10(用4块硬盘)
两种方法
1、可以先做raid1再做raid0
2、mdadm -C -v /dev/md10 -l 10 -n 4 /dev/sd[k,l,m,n]