【Operating System】Disk Management Advanced

RAID disk array

Redundant Array of Independent Disks - 独立冗余磁盘阵列

What is RAID?

把多个磁盘设备组合成一个容量更大、更安全的磁盘阵列

把数据切割成多个区段,分别存放在不同的物理硬盘设备上,然后利用 分散读写技术 来提升磁盘阵列整体的性能;

同时把多个重要数据的 副本 同步到不同的物理硬盘设备上,从而起到非常好的 数据冗余备份 效果

advantage

  1. redundant backup
  2. Increased hard disk throughput and improved read and write speeds
  3. Negative: Cost increase

RAID disk array scheme:

At least a dozen kinds, four kinds in detail

  • RAID 0
  • RAID 1
  • RAID 5
  • RAID 10

RAID 0

数据条带化
数量:2块及以上的硬盘,性能和容量随硬盘数递增

Advantages: The fastest of all RAID levels; (concurrent read and write)
Disadvantages: No redundancy or error repair capability, hard disk damage can not be tolerated.

RAID 1

数据镜像(一模一样的备份)
数量:2块及以上的硬盘(偶数)

Advantages: There is one copy of data in each group of disks, and the read performance is good. If a group of disks is damaged, data access will not be affected;
Disadvantages: The write performance decreases because double copies of data need to be written;

RAID 5

奇偶校验
数量:3块及以上的硬盘

并发存放

Advantages: can tolerate any broken disk, parity recovery is close to the data reading speed of RAID-0, has a certain disaster tolerance capability, and the writing speed is slower than RAID-1

RAID 10

奇偶校验
数量:至少4块

Advantages: better performance, better reliability
Disadvantages: high cost, small capacity

1.RAID-0:无容灾,很少单独使用
2.RAID-1:操作系统-日志文件;
3.RAID-5:数据文件、备份文件
4.RAID-10:所有类型都使用,成本影响较大;

Disk Array Management

Need to use the mdadm tool

rpm -qa mdadm

Using the mdadm Tool

RAID creation steps

1. 确认mdama工具已安装;
2. 添加磁盘(至少2块);
3. 进行 分区 和 格式化 (fdisk  ,  mkfs)
4. 使用 mdada 命令创建管理 RAID  【见下文】
5. 模拟磁盘坏道的情况
6. 数据的恢复

Create and manage RAID

# 1. 创立RAID
mdadm -Cv /dev/md1 -l1 -n2 /dev/sdb1 /dev/sdc1	#RAID1 卷
mdadm -Cv /dev/md5 -l5 -n3 /dev/sdb2 /dev/sdc2 /dev/sdd2	#RAID5 卷
# 2. 查看RAID
mdadm -D /dev/md1
# 3. 创建配置文件
mdadm -D -s >> /etc/mdadm.conf
# 4. 停止RAID
mdadm -s /dev/md1
# 5. 激活RAID
mdadm -A /dev/md1

access:


mkdir /mnt/md1	#创建一个挂载点
mount /dev/md1 /mnt/md1	#挂载RAID

# 开机自动挂载
#将下述信息加入到 /etc/fstab中
# /dev/md1	/mnt/md1 auto defaults 0 0
# /dev/md5  /mnt/md5 auto defaults 0 0

example

To create a RAID5 disk array, the required capacity is 8G, the file system is ext4, and it can be automatically mounted to the /raid5 directory when booting



LVM disk management

Function: dynamically adjust the disk capacity. If the hardware supports it, you can add a hard disk to a running volume group, thereby increasing the flexibility of disk management.

Physical Volume - PV

1. 物理卷 是 LVM 的最基本的 物理 组成部分,可以是整个硬盘也可以是硬盘中的某个分区;
2. 怎么生成pv:利用 fdisk 命令把实际的分区转化成为 8e 的系统格式,然后利用 pvcreate 把分区变成能够利用的物理卷

physical volume

Volume Group - VG

VG(Volumn Group,卷组):一个或多个物理卷组合而成的整体。[逻辑上,非物理上]
PE:是LVM最小的存储单位,一般大小为 4MB ,是构成 VG 的基本单位

insert image description here

Logical Volume - LV

1. 逻辑卷:从 卷组[VG] 中分割出一块空间,用于建立文件系统

insert image description here

Deploying LVM requires configuring physical volumes, volume groups, and logical volumes one by one

Function Physical volume pv management Volume group VG management logical volume lv management
scan - scan pvscan vgscan lvscan
create - create pvcreate vgcreate lvcreate
display - display pvdisplay vgdiaplay lvdislay
remove - remove pvremove vgremove lvremove
extend - extend vgextend lvextend
reduce - reduce vgreduce lvreduce

Create LVM from the command line

# 命令行创建 LVM
#1. 创建 物理卷,卷组,逻辑卷,,,首先创建LVM
#2. 挂载 逻辑卷LV
# 常用命令
pvcreate 物理磁盘/物理磁盘的分区   #创建物理卷
vgcreate 卷组名 物理卷1 物理卷2  #合并物理卷为 卷组
lvcreate -L 容量大小 -n 逻辑卷名 卷组名  # 创建逻辑卷方式一
# 或者: lvcreate -l PE个数 -n 逻辑卷名 卷组名   #创建逻辑卷方式二
lvextend -L +容量大小 逻辑卷的绝对路径   #合并逻辑卷
lvextend -L 容量大小 逻辑卷的绝对路径   #指定逻辑卷,扩展至指定大小

Create Logical Volume Steps

1.让物理磁盘支持 LVM 技术:pvcreate 
2.把pv增加到卷组VG中:vgcreate
3.创建逻辑卷lv:lvcreate

Resizing LVM

expand

As long as there are enough resources in the volume group, you can always expand the logical volume.
Remember: before expanding, be sure to unmount the associated umount of the device and the mount point

# 1.扩展
lvextend -L 300M /dev/myvg/mylv
# 2.检查硬盘完整性,并重置硬盘容量
e2fsck -f /dev/myvg/mylv
	#检查inode、块和大小;检查目录结构;检查目录连接性;检查引用计数;检查组概要信息
# 3.重新挂载
mount 

zoom out

#1.调整文件系统的大小
resize2fs 位置 大小
#2.调整lv大小
lvreduce -L 大小 位置
#3.重新设置文件系统
#4.重新挂载

delete logical volume

#删除逻辑卷
lvremove lv_name
#删除卷组,可以删除,可以不删除,自己选择
#vgremove vg_name

Guess you like

Origin blog.csdn.net/Sanayeah/article/details/126903689