一、磁盘配额

Linux是一个多用户的操作系统,系统有很多用户,就必须限制每个用户的保存空间,配额就是来管理用户空间的,配额只是针对与设备而言。

1.新建一个分区

lvs full nat模式怎么配置需要个什么模块_lvm

2.格式化分区为xfs文件系统

lvs full nat模式怎么配置需要个什么模块_配置文件_02

3.将其以配额的方式挂载

lvs full nat模式怎么配置需要个什么模块_逻辑卷_03

用mount命令可以查看到其挂载方式为配额

lvs full nat模式怎么配置需要个什么模块_配置文件_04

4.给 /mnt满权限

lvs full nat模式怎么配置需要个什么模块_文件系统_05

5.开始给用户配额

打开配置文件

lvs full nat模式怎么配置需要个什么模块_逻辑卷_06

给用户配额,最大额度为20480k即20M

lvs full nat模式怎么配置需要个什么模块_lvm_07

上述方式为暂时性配额,开启开机自动配额可编辑以下文件

配置文件:vim /etc/fstab

lvs full nat模式怎么配置需要个什么模块_逻辑卷_08

6.切换student用户进行测试

20M未超过磁盘额度,分割结果正常

lvs full nat模式怎么配置需要个什么模块_lvm_09

21M已经超过额度,不能进行分割

lvs full nat模式怎么配置需要个什么模块_lvm_10

二、lvm逻辑卷管理

1.相关定义

PV(Physica lVolume)物理卷

VG(Volume Group)物理卷组

PE(Physical Extend)物理扩展,LVM最小的存储块

LV(Logical Volume)逻辑卷

2.相关图解(注:本图来源鸟哥私房菜)

lvs full nat模式怎么配置需要个什么模块_文件系统_11

3.建立LVM逻辑卷

(1)新建3个1G分区并修改分区标签为lvm

lvs full nat模式怎么配置需要个什么模块_逻辑卷_12

(2)创建物理卷

lvs full nat模式怎么配置需要个什么模块_配置文件_13

(3)创建物理卷组

lvs full nat模式怎么配置需要个什么模块_配置文件_14

(4)创建逻辑卷

大小300M 名字lv0  在vg0下建立

lvs full nat模式怎么配置需要个什么模块_文件系统_15

(5)格式化,给逻辑卷加xfs文件系统

lvs full nat模式怎么配置需要个什么模块_lvm_16

(6)将设备挂载

lvs full nat模式怎么配置需要个什么模块_lvm_17

监控命令:watch -n 1 'pvs;vgs;lvs;df -h /mnt'

lvs full nat模式怎么配置需要个什么模块_文件系统_18

mapper 指的是虚拟设备

4.LVM的拉伸

pvcreate /dev/vdb2 ##再创建一个物理卷

lvs full nat模式怎么配置需要个什么模块_配置文件_19

vgextend vg0 /dev/vdb2 ##增加物理卷组

lvs full nat模式怎么配置需要个什么模块_lvm_20

lvextend -L 1500M /dev/vg0/lv0 ##拉伸逻辑卷

lvs full nat模式怎么配置需要个什么模块_逻辑卷_21

xfs_growfs  /dev/vg0/lv0 ##将文件系统扩容

lvs full nat模式怎么配置需要个什么模块_lvm_22

由监控命令可以观察到已经拉伸成功:

lvs full nat模式怎么配置需要个什么模块_lvm_23

5.以ext4文件系统拉伸

mkfs.ext4  /dev/vg0/lv0  ##格式化为ext4文件系统

lvs full nat模式怎么配置需要个什么模块_配置文件_24

mount  /dev/vg0/lv0  /mnt    ##重新挂载

lvextend -L 1800M /dev/vg0/lv0  ##拉伸设备

lvs full nat模式怎么配置需要个什么模块_配置文件_25

resize2fs /dev/vg0/lv0   ##拉伸文件系统

lvs full nat模式怎么配置需要个什么模块_lvm_26

由监控命令可以观察到已经拉伸成功:

lvs full nat模式怎么配置需要个什么模块_lvm_27

ext4格式不仅可以拉伸还可以缩减,而xfs只可以拉伸

6.ext4格式下的缩减

e2fsck -f  /dev/vg0/lv0  ##设备的扫描

lvs full nat模式怎么配置需要个什么模块_文件系统_28

resize2fs  /dev/vg0/lv0   1000M  ##对文件系统的缩减

lvs full nat模式怎么配置需要个什么模块_逻辑卷_29

mount /dev/vg0/lv0  /mnt/  ##重新挂载

lvreduce  -L 1000M /dev/vg0/lv0 ##缩减设备

lvs full nat模式怎么配置需要个什么模块_文件系统_30

由监控命令可以观察到已经缩减成功:

lvs full nat模式怎么配置需要个什么模块_配置文件_31

7.物理卷的缩减

pvmove /dev/vdb1  /dev/vdb2  ##将1中的数据放入2中

lvs full nat模式怎么配置需要个什么模块_逻辑卷_32

vgreduce  vg0 /dev/vdb1 ##将vdb1从vg0中取出

pvremove  /dev/vdb1 ##移除vdb1

lvs full nat模式怎么配置需要个什么模块_配置文件_33

8.lvm的快照

在/dev/vg0/lv0挂载的情况下touch /mnt/file{1..3}

lvs full nat模式怎么配置需要个什么模块_逻辑卷_34

1.lvcreate -L 100M -n lv0backup -s  /dev/vg0/lv0 ##创建快照

lvs full nat模式怎么配置需要个什么模块_逻辑卷_35

2.mount /dev/vg0/lv0backup   /mnt/    ##将快照进行挂载

lvs full nat模式怎么配置需要个什么模块_逻辑卷_36

3.rm -rf /mnt/file{1..3}

4.umount /mnt/

5.lvremove /dev/vg0/lv0backup ##将快照移除

lvs full nat模式怎么配置需要个什么模块_逻辑卷_37

6.lvcreate  -L 100M -n lv0backuo -s /dev/vg0/lvo ##重新创建快照

lvs full nat模式怎么配置需要个什么模块_逻辑卷_35

7.mount /dev/vg0/lv0backup  /mnt/

8.ls /mnt/  ##文件重新回来

lvs full nat模式怎么配置需要个什么模块_lvm_39

9.删除lvm 

umount /mnt/

lvremove /dev/vg0/lv0backup ##移除快照

lvs full nat模式怎么配置需要个什么模块_逻辑卷_37

lvremove /dev/vg0/lv0 ##移除逻辑卷

lvs full nat模式怎么配置需要个什么模块_配置文件_41

vgremove vg0 ##移除物理卷组

lvs full nat模式怎么配置需要个什么模块_lvm_42

pvremove /dev/vdb{1..2} ##移除物理卷

lvs full nat模式怎么配置需要个什么模块_配置文件_43

删除和新建为逆过程

删除之前的监控内容:

lvs full nat模式怎么配置需要个什么模块_lvm_44

删除之后:

lvs full nat模式怎么配置需要个什么模块_逻辑卷_45