题目要求:
· 在虚拟机上添加 4 个 1G 的硬盘;
· 创建 raid5,其中一个作为热备盘, 设备名为md0;
· 将 md0 设置为 LVM,设备为/dev/vg01/lv01;
· 格式化为 ext4 文件系统;
· 开机自动挂载到/data 目录。
题目实施:
RAID5配置
添加4个1g的虚拟磁盘,查看:
//未添加之前
[root@server01 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 49G 0 part
├─centos-root 253:0 0 47G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sr0 11:0 1 4.4G 0 rom
//添加之后
[root@server01 ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 50G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 49G 0 part
├─centos-root 253:0 0 47G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
sdb 8:16 0 1G 0 disk
sdc 8:32 0 1G 0 disk
sdd 8:48 0 1G 0 disk
sde 8:64 0 1G 0 disk
sr0 11:0 1 4.4G 0 rom
安装软件包:
[root@server01 ~]# yum install mdadm -y
创建RAID5:
#-C 创建 raid
#-v 显示过程
#-n 指定设备数量
#-x 指定热备盘数量
#-l 指定 RAID 等级
[root@server01 ~]# mdadm -Cv /dev/md0 -n 3 -x 1 -l 5 /dev/sd[b-e]
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/md0 started.
[root@server01 ~]#
查看创建:
[root@server01 ~]# mdadm -D /dev/md0 /dev/
/dev/md0:
Version : 1.2
Creation Time : Mon Dec 12 20:20:27 2022
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 : 4
Persistence : Superblock is persistent
Update Time : Mon Dec 12 20:20:33 2022
State : clean
Active Devices : 3
Working Devices : 4
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 512K
Consistency Policy : resync
Name : server01:0 (local to host server01)
UUID : 88e7da96:de40f7c5:38b5dd25:e2ffc3ab
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
mdadm: /dev/ does not appear to be an md device
[root@server01 ~]#
LVM配置
创建LVM:
#创建物理卷
[root@server01 ~]# pvcreate /dev/md0
Physical volume "/dev/md0" successfully created.
#创建卷组
[root@server01 ~]# vgcreate vg01 /dev/md0
Volume group "vg01" successfully created
#创建逻辑卷,-n:名称 -L:以G为单位 -l:以4M为单位
[root@server01 ~]# lvcreate -n lv01 -L 1g vg01
Logical volume "lv01" created.
查看逻辑卷:
[root@server01 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg01/lv01 #这里是我们创建的
LV Name lv01
VG Name vg01
LV UUID W2K82H-1q51-oOf8-pIFP-nzCr-4Nnh-Z3WoQY
LV Write Access read/write
LV Creation host, time server01, 2022-12-12 20:24:45 +0800
LV Status available
# open 0
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
--- Logical volume ---
LV Path /dev/centos/swap
LV Name swap
VG Name centos
LV UUID rqCGRJ-Ej2D-pdR0-km7h-g1MB-3tsW-0nI19H
LV Write Access read/write
LV Creation host, time localhost, 2022-06-07 03:04:09 +0800
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:1
--- Logical volume ---
LV Path /dev/centos/root
LV Name root
VG Name centos
LV UUID WoQUmg-BuZp-dVJP-hpru-Lsu0-zPkG-Ughp6i
LV Write Access read/write
LV Creation host, time localhost, 2022-06-07 03:04:10 +0800
LV Status available
# open 1
LV Size 46.99 GiB
Current LE 12030
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
[root@server01 ~]#
格式化RAID:
[root@server01 ~]# mkfs.ext4 /dev/vg01/lv01
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=128 blocks, Stripe width=256 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Allocating group tables: 完成
正在写入inode表: 完成
Creating journal (8192 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@server01 ~]#
进行配置永久挂载:
创建挂载目录/data:
[root@server01 ~]# mkdir /data
永久挂载:
[root@server01 ~]# echo '/dev/vg01/lv01 /data ext4 defaults 0 0' >>/etc/fstab
[root@server01 ~]# mount -a
查看挂载文件(重启测试):
[root@server01 ~]# 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 47G 1.4G 46G 3% /
/dev/sda1 1014M 138M 877M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/vg01-lv01 976M 2.6M 907M 1% /data
[root@server01 ~]#
配置完成