首页 > 代码库 > Linux 红帽 磁盘管理~~~~RAID5+LVM
Linux 红帽 磁盘管理~~~~RAID5+LVM
Linux 红帽 磁盘管理~~~~RAID5+LVM
实验环境:
在Linux 操作系统的PC机上添加3块20G大小的磁盘
实验步骤:
一. 创建RAID5:
1. 准备工作:
[root@112 ~]# uname -a //查看基本信息 |
[root@112 ~]# cat /etc/redhat-release //查看红帽的发行版本 |
为添加好的三个磁盘进行分区, 分区的类型:FD(全称:)
为了节省时间 就以 一个整磁盘一个分区进行演示
[root@112 ~]# fdisk /dev/sdb //对sdb进行分区 |
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x3b436575.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won‘t be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It‘s strongly recommended to
switch off the mode (command ‘c‘) and change display units to
sectors (command ‘u‘).
Command (m for help): n |
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-2610, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): (可以这设定分区的大小, 格式:+**M 。*表示数字)
Using default value 2610
Command (m for help): t
Selected partition 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): p (进行查看上面的操作是否成功)
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x3b436575
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ fd Linux raid autodetect
Command (m for help): w (保存并退出)
The partition table has been altered!
Calling ioctl() to re-read partition table.
按照以上的步骤对余下的两个盘进行分区:
[root@112 ~]# fdisk /dev/sdc |
[root@112 ~]# fdisk /dev/sdd |
2. 创建RAID5:
[root@112 ~]# mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1 |
[root@112 ~]# mkfs.ext4 /dev/md0 //对RAID5进行格式化 |
[root@112 ~]# mdadm --detail --scan //查看卷的信息 |
[root@112 ~]# mdadm --detail --scan >> /etc/mdadm.conf //写入配置文件 |
二. 在RAID5中部署LVM:
[root@112 ~]# pvcreate /dev/md0 //把分区变成 物理卷(PV) |
Physical volume "/dev/md0" successfully created
[root@112 ~]# vgcreate vg0 /dev/md0 //把物理卷(PV)加入到卷组(VG)中 |
Volume group "vg0" successfully created
[root@112 ~]# lvcreate -L 20G -n lv0 vg0 //在卷组(VG)中取出一部分做成逻辑卷(LV) |
[root@112 ~]# mkfs.ext4 /dev/vg0/lv0 //对逻辑卷 进行格式化 |
[root@112 ~]# mkdir /data //创建目录data |
[root@112 ~]# mount /dev/vg0/lv0 /data/ //把逻辑卷挂载到目的data下 |
[root@112 ~]# df -k //查看信息 |
[root@112 ~]# vi /etc/fstab //建立自动挂载 添加以下 /dev/vg0/lv0 /data ext4 defaults 0 0 |
[root@112 ~]# mount //进行查看 |
在目录data中创建四个文件
[root@112 ~]# cd /data [root@112 data]# touch a1 [root@112 data]# touch a2 [root@112 data]# touch a3 [root@112 data]# touch a4 |
三.模拟磁盘损坏
手工取出一块磁盘 这里 我选择sdb1
[root@112 data]# mdadm /dev/md0 --fail /dev/sdb1 //标记sdb1 在RAID5中失效 |
mdadm: set /dev/sdb1 faulty in /dev/md0
[root@112 data]# mdadm /dev/md0 --remove /dev/sdb1 //移除损坏的磁盘 |
mdadm: hot removed /dev/sdb1 from /dev/md0
[root@112 data]# ll //查看文件 |
total 16
-rw-r--r-- 1 root root 0 Aug 16 11:39 a1
-rw-r--r-- 1 root root 0 Aug 16 11:39 a2
-rw-r--r-- 1 root root 0 Aug 16 11:39 a3
-rw-r--r-- 1 root root 0 Aug 16 11:39 a4
drwx------ 2 root root 16384 Aug 16 11:11 lost+found
查看结果 所创建的文件都存在
[root@112 data]# touch a5 //创建新的文件 [root@112 data]# ll |
-rw-r--r-- 1 root root 0 Aug 16 11:39 a1
-rw-r--r-- 1 root root 0 Aug 16 11:39 a2
-rw-r--r-- 1 root root 0 Aug 16 11:39 a3
-rw-r--r-- 1 root root 0 Aug 16 11:39 a4
-rw-r--r-- 1 root root 0 Aug 16 12:10 a5
drwx------ 2 root root 16384 Aug 16 11:11 lost+found
查看结果,能新建
[root@112 data]# reboot //重启 |
添加一块新的磁盘 并给新加的磁盘 进行配置
[root@112 ~]# fdisk -l //进行查看 新加的磁盘 |
[root@112 ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c8420
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
Disk /dev/sdb: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x14b322cb
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ fd Linux raid autodetect
Disk /dev/sdc: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xea3e17bd
Device Boot Start End Blocks Id System
/dev/sdc1 1 2610 20964793+ fd Linux raid autodetect
Disk /dev/sdd: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
在这里我新加的磁盘自动变成了 sdd
一下对sdd 进行 FD式分区 , 进行 格式化
[root@112 ~]# mdadm /dev/md0 --add /dev/sdd1 //把新加的磁盘 添加到RAID卷中 |
mdadm: added /dev/sdd1
[root@112 ~]# cat /proc/mdstat 进行查看 |
Personalities : [raid6] [raid5] [raid4]
md0 : active raid5 sdd1[4] sdc1[3] sdb1[1]
41895936 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [_UU]
[==============>......] recovery = 70.5% (14781696/20947968) finish=1.1min speed=88939K/sec
unused devices: <none>
[root@112 data]# mount /dev/vg0/lv0/ /data |
mount: /dev/mapper/vg0-lv0 already mounted or /data busy
mount: according to mtab, /dev/mapper/vg0-lv0 is already mounted on /data
提示已经挂载过
[root@112 data]# ll //进行查看文件是否丢失 |
total 16
-rw-r--r-- 1 root root 0 Aug 16 11:39 a1
-rw-r--r-- 1 root root 0 Aug 16 11:39 a2
-rw-r--r-- 1 root root 0 Aug 16 11:39 a3
-rw-r--r-- 1 root root 0 Aug 16 11:39 a4
-rw-r--r-- 1 root root 0 Aug 16 12:10 a5
drwx------ 2 root root 16384 Aug 16 11:11 lost+found
得出结果,文件没有丢失
本期:《Linux 红帽 磁盘管理~~~~RAID5+LVM》到此结束
如果觉得可以,请关注本博客
谢谢您的光临,我们下期再会...
本文出自 “李-鹏辉~~~IT鸿蒙博门客” 博客,转载请与作者联系!