选项简写
准备:可以多准备几块磁盘
raid0
raid0的创建
1.首先查看分区
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 1G 0 part
│ └─md0 9:0 0 3G 0 raid0
└─sdb2 8:18 0 2G 0 part
└─md0 9:0 0 3G 0 raid0
sr0 11:0 1 4.2G 0 rom
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 1.6G 16G 9% /
/dev/sda1 1014M 138M 877M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
2.用fdisk命令进行分区sdb1,sdb2
# fdisk /dev/sdb
3.使用mdadm命令进行raid创建
mdadm -Cv /dev/md0 -l 0 -n 2 /dev/sdb1 /dev/sdb2
查看
mdadm -Ds
4. 进行格式化
mkds.xfs /dev/md0
5.进行挂载
mdkir /raid0
mount -t xfs /dev/md0 /raid0
6.进行查看
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 1.6G 16G 9% /
/dev/sda1 1014M 138M 877M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/md0 3.0G 33M 3.0G 2% /raid0
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 1G 0 part
│ └─md0 9:0 0 3G 0 raid0 /raid0
└─sdb2 8:18 0 2G 0 part
└─md0 9:0 0 3G 0 raid0 /raid0
sr0 11:0 1 4.2G 0 rom
查看RAID 0详细信息
mdadm -D /dev/md0
raid0的删除
1、查看RAID磁盘阵列信息,确认一下要关闭哪个
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid0]
md0 : active raid0 sdb2[1] sdb1[0]
3141632 blocks super 1.2 512k chunks
unused devices: <none>
2.先解挂
[root@localhost ~]# umount /dev/md0
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 1G 0 part
│ └─md0 9:0 0 3G 0 raid0
└─sdb2 8:18 0 2G 0 part
└─md0 9:0 0 3G 0 raid0
sr0 11:0 1 4.2G 0 rom
或者[root@localhost ~]# umount /raid0/
[root@localhost ~]# mdadm -Ds /dev/md0
mdadm: cannot open /dev/md0: No such file or directory
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 1G 0 part
└─sdb2 8:18 0 2G 0 part
sr0 11:0 1 4.2G 0 rom
3、停止md0阵列设备
[root@localhost ~]# mdadm -S /dev/md0
mdadm: stopped /dev/md0
4、清除每个磁盘当中阵列的超级块信息,这一步很重要!
mdadm --zero-superblock /dev/sdb
注:如果在/etc/fstab里写了永久挂载信息需要删除
vim /etc/fstab
删除或注释/etc/mdadm.conf对应的RAID信息
vim /etc/mdadm.conf
raid1
raid1的创建
[root@localhost ~]# mdadm -Cv /dev/md1 -l1 -n2 /dev/sdb1 /dev/sdb2
mdadm: /dev/sdb1 appears to be part of a raid array:
level=raid0 devices=2 ctime=Tue Jan 23 16:40:12 2024
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/sdb2 appears to be part of a raid array:
level=raid0 devices=2 ctime=Tue Jan 23 16:40:12 2024
mdadm: size set to 1046528K
mdadm: largest drive (/dev/sdb2) exceeds size (1046528K) by more than 1%
Continue creating array?
Continue creating array? (y/n) y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.
[root@localhost ~]# mdadm -D /dev/md1
/dev/md1:
Version : 1.2
Creation Time : Thu Jan 25 09:52:42 2024
Raid Level : raid1
Array Size : 1046528 (1022.00 MiB 1071.64 MB)
Used Dev Size : 1046528 (1022.00 MiB 1071.64 MB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Jan 25 09:52:48 2024
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Consistency Policy : resync
Name : localhost.localdomain:1 (local to host localhost.localdomain)
UUID : 64a3d36b:869025fe:414d2e2b:5c968bef
Events : 17
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 18 1 active sync /dev/sdb2
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 1G 0 part
│ └─md1 9:1 0 1022M 0 raid1
└─sdb2 8:18 0 2G 0 part
└─md1 9:1 0 1022M 0 raid1
sr0 11:0 1 4.2G 0 rom
[root@localhost ~]# mkdir /raid1
[root@localhost ~]# mkfs.xfs -f /dev/md1
meta-data=/dev/md1 isize=512 agcount=4, agsize=65408 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=261632, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=855, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@localhost ~]# mount -t xfs /dev/md1 /raid1
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 1.6G 16G 9% /
/dev/sda1 1014M 138M 877M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/md1 1019M 33M 987M 4% /raid1
删除raid1
raid5
创建raid5
根据 RAID5 的要求,至少需要 3 个以上的设备。也就是说,一个有效的 RAID5 数组应该至少包含 3 个或更多的磁盘
[root@localhost ~]# mdadm -Cv /dev/md5 -l5 -n3 /dev/sdc[1-3]
mdadm: layout defaults to left-symmetric
mdadm: layout defaults to left-symmetric
mdadm: chunk size defaults to 512K
mdadm: size set to 1046528K
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 : Fri Jan 26 11:27:17 2024
Raid Level : raid5
Array Size : 2093056 (2044.00 MiB 2143.29 MB)
Used Dev Size : 1046528 (1022.00 MiB 1071.64 MB)
Raid Devices : 3
Total Devices : 3
Persistence : Superblock is persistent
Update Time : Fri Jan 26 11:27:23 2024
State : clean
Active Devices : 3
Working Devices : 3
Failed Devices : 0
Spare Devices : 0
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : localhost.localdomain:5 (local to host localhost.localdomain)
UUID : b911d507:2e3a6272:05000db3:1b60dff7
Events : 18
Number Major Minor RaidDevice State
0 8 33 0 active sync /dev/sdc1
1 8 34 1 active sync /dev/sdc2
3 8 35 2 active sync /dev/sdc3
[root@localhost ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 20G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 20G 0 disk
├─sdb1 8:17 0 1G 0 part
│ └─md1 9:1 0 1022M 0 raid1
├─sdb2 8:18 0 2G 0 part
│ └─md1 9:1 0 1022M 0 raid1
├─sdb3 8:19 0 2G 0 part
└─sdb4 8:20 0 2G 0 part
sdc 8:32 0 20G 0 disk
├─sdc1 8:33 0 1G 0 part
│ └─md5 9:5 0 2G 0 raid5
├─sdc2 8:34 0 1G 0 part
│ └─md5 9:5 0 2G 0 raid5
└─sdc3 8:35 0 1G 0 part
└─md5 9:5 0 2G 0 raid5
sr0 11:0 1 4.2G 0 rom
[root@localhost ~]# mkfs.xfs /dev/md5
meta-data=/dev/md5 isize=512 agcount=8, agsize=65408 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=523264, imaxpct=25
= sunit=128 swidth=256 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, 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/
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 1.6G 16G 9% /
/dev/sda1 1014M 138M 877M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/md5 2.0G 33M 2.0G 2% /raid5
删除raid5
[root@localhost ~]# cat /proc/mdstat
Personalities : [raid1] [raid6] [raid5] [raid4]
md5 : active raid5 sdc3[3] sdc2[1] sdc1[0]
2093056 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
md1 : active raid1 sdb2[1] sdb1[0]
1046528 blocks super 1.2 [2/2] [UU]
unused devices: <none>
[root@localhost ~]# umount /dev/md5
[root@localhost ~]# mdadm -S /dev/md5
mdadm: stopped /dev/md5
[root@localhost ~]# mdadm --zero-superblock /dev/sdc1 /dev/sdc2 /dev/sdc3
如果在/etc/fstab里写了永久挂载信息需要删除
删除或注释/etc/mdadm.conf对应的RAID信息
vim /etc/mdadm.conf ##进入配置进行修改
如果没有/etc/mdadm.conf跳过即可,有就将对应的RAID文件删除