Linux Dry Goods – LVM and Disk Quotas
1. LVM (Logical Volume Manager) logical volume management
It is a mechanism for managing disk partitions in the Linux environment;
(1) It can dynamically adjust the disk capacity without keeping the existing data unchanged, thereby improving the flexibility of disk management.
(2) The /boot partition is used to store bow | guide files and cannot be created based on LVM
Advantages: maintain existing data, dynamically adjust, high availability and flexibility;
2. Implementation process
● Designate the device as a physical volume
● use one or more physical volumes to create a volume group,
The physical volume is defined by a fixed-size physical area (PE) (easy to call, high utilization, default 1PE=4M)
●The logical volume created on the physical volume is composed of physical area (PE)
● File systems can be created and mounted on logical volumes
3. The basic concept of LVM mechanism:
(1) PV (physical volume): A physical volume is the basic storage device of the LVM mechanism, which usually corresponds to a common partition or an entire hard disk. When creating a physical volume, a reserved block is created at the head of the partition or hard disk to record the properties of LVM, 1PE=4MB;
(2) VG (Volume Group): It is composed of one or more physical volumes as a whole, which is called a volume group, and physical volumes can be dynamically added or removed in the volume group;
(3) LV (logical volume): The logical volume is built on the volume group and has no direct relationship with the physical volume.
For logical volumes, each volume group is a whole, and a small space is "cut out" from this whole, which is used as the basis for users to create a file system. This small space is called a logical volume.
(4) PE (physical block): PE is the basic division unit of the physical volume PV, and the PE with a unique number is the smallest unit that can be addressed by LVM. The size of the PE is configurable and defaults to 4MB. So the physical volume (PV) consists of basic units PE of equal size;
Main command:
Function | Physical Volume Management | Volume group management | Logical volume management |
---|---|---|---|
Scan scan | pvscan | vgscan | lvscan |
create build | pvcerate | vgcreate | lvcreate |
display display | pvdisplay | vgdisplay | lvdisplay |
remove delete | pvremove | vgremove | lvremove |
extend | ---- | vgextend | lvtend |
reduce reduce | ---- | vgreduce | lvreduce |
4. LVM experimental operation:
(1) Shut down the host, add two new hard disks, and restart the host;
(2) Use fdisk -l or lsblk to view the hard disk partition;
[External link image transfer failed, the source site may have an anti-leech mechanism, it is recommended to save the image and upload it directly (img-HKZIxE9w-1631176495928)(D:\learning files\Linux\KY15 course\7, LVM and disk quota\screenshots \20.png)]
(3) Partition the hard disk sdb, and change the ID number of the partition type to "8e"
fdisk /dev/sdb //Start partition
[External link image transfer failed, the source site may have anti-leech mechanism, it is recommended to save the image and upload it directly (img-MYUDcxfO-1631176495930)(D:\learning files\Linux\KY15 course\7, LVM and disk quota\screenshot \21.png)]
(4) Create a physical volume: (The device when creating a physical volume can be a partition or a hard disk. If it is a partition, its type ID should be 8e)
[root@localhost ~]# pvcreate /dev/sdb1 /dev/sdc //Create a physical volume [root@localhost ~]# pvdisplay //View the physical volume
[External link image transfer failed, the source site may have anti-leech mechanism, it is recommended to save the image and upload it directly (img-HZmxJwHh-1631176495932)(D:\learning files\Linux\KY15 course\7, LVM and disk quota\screenshot \22.png)]
(5) Group multiple or one physical volumes into a volume group:
[root@localhost ~]# vgcreate ky15 /dev/sdc /dev/sdb1 command word volume group name physical volume(s) [root@localhost ~]# vgdisplay //View volume group
[External link image transfer failed, the source site may have an anti-leech mechanism, it is recommended to save the image and upload it directly (img-b8gvKKdr-1631176495933)(D:\learning files\Linux\KY15 course\7, LVM and disk quota\screenshots \23.png)]
(6) Create a logical volume:
[root@localhost ~]# lvcreate -L 20G -n ky1501 ky15 Command word size 20 G -n Logical volume name Volume group name [root@localhost ~]# lvdisplay //View the logical volume
[External link image transfer failed, the source site may have an anti-leech mechanism, it is recommended to save the image and upload it directly (img-IVU59FwA-1631176495936)(D:\Learning Files\Linux\KY15 Course\7, LVM and Disk Quota\Screenshot \24.png)]
(7) Format the logical volume, create an XFS file system, and mount it to the /data directory
[root@localhost ~]# mkfs.xfs /dev/ky15/ky1501 //Format the logical volume and create an xfs system [root@localhost ~]# mkdir /data //create data folder [root@localhost ~]# mount /dev/ky15/ky1501 /data //Mount to /data directory [root@localhost ~]# df -hT //View file mount status
[External link image transfer failed, the source site may have an anti-leech mechanism, it is recommended to save the image and upload it directly (img-crB66Yh0-1631176495937)(D:\learning files\Linux\KY15 course\7, LVM and disk quota\screenshots \25.png)]
(8) Expand volume groups and logical volumes:
[External link image transfer failed, the source site may have anti-leech mechanism, it is recommended to save the image and upload it directly (img-yjOBrhXn-1631176495938)(D:\learning files\Linux\KY15 course\7, LVM and disk quota\screenshot \26.png)]
First add partitions to physical volumes, and then expand volume groups and logical volumes;
[root@localhost ~]# pvcreate /dev/sdb2 //Add partition sdb2 to physical volume [root@localhost ~]# pvdisplay //View physical volumes
[External link image transfer failed, the source site may have an anti-leech mechanism, it is recommended to save the image and upload it directly (img-9ZrzX62g-1631176495938)(D:\learning files\Linux\KY15 course\7, LVM and disk quota\screenshots \27.png)]
vgextend ky15 /dev/sdb2 Command word Name of volume group to be expanded Physical volume (physical volume not used) lvextend -L +10G /dev/ky15/ky1501 command word specify friendly size 10 G lv Logical volume location xfs_growfs /dev/ky15/ky1501 //Refresh the xfs filesystem Flush file system command Logical volume name
[External link image transfer failed, the source site may have anti-leech mechanism, it is recommended to save the image and upload it directly (img-rYaX820A-1631176495939)(D:\learning files\Linux\KY15 course\7, LVM and disk quota\screenshots \28.png)]
Experiment: Setting Disk Quotas in CentOS7:
When the disk space of the Linux root partition is exhausted, the Linux operating system will no longer be able to create new files, and at the same time, failures such as service program crash and system failure may occur.
In Centos system, different file systems use different disk quota configuration management tools. For example, XFS file systems are managed by the xfs_quota tool; EXT3/4 file systems are managed by the quota tool.
(1) Check whether the xfsprogs and quota packages have been installed;
[root@localhost ~]# rpm -q xfsprogs quota xfsprogs-4.5.0-12.el7.x86_64 quota-4.01-14.el7.x86_64 Use if not installed yum Install: [root@localhost ~]# yum install -y xfsprogs quota
(2) Mount the file system in a way that supports the quota function;
[root@localhost ~]# umount /data [root@localhost ~]# mount -o usrquota,grpquota /dev/ky15/ky1501 /data #Add mount parameters "usrquota, grpquota" to add support for user and group quota function
(3) Edit quota settings for user and group accounts;
[root@localhost ~]# useradd lisi [root@localhost ~]# passwd lisi xfs_quota -x -c 'limit -u bsoft=80M bhard=100M isoft=6 ihard=10 lisi' /data/ Command word Expert mode Call command limit limit -u Named User Soft and Hard Limits Users that need to be restricted Mount points -x:Indicates that the expert mode is activated, and all administrative commands that allow modification of the quota system are available in the current mode -c: Indicates direct invocation of management commands -u: Specifies the user account object -g: Specify the group account object bsoft: Set the soft limit value for disk capacity(The default unit is KB) bhard:Set hard limit value for disk capacity(The default unit is KB) isoft:Set the soft limit value for the number of disk files ihard:Set the hard limit value for the number of disk files View disk capacity quota usage for available partitions:xfs_quota -x -c 'report -abih' report Common options: -u: View to users -g: View the group -a: View quota usage for all available partitions -b: View disk capacity -i: View the number of files
[External link image transfer failed, the source site may have an anti-leech mechanism, it is recommended to save the image and upload it directly (img-3xZRA2Qv-1631176495940)(D:\learning files\Linux\KY15 course\7, LVM and disk quota\screenshots \29.png)]
(4) Verify the disk quota function:
chmod 777 /data su lisi cd /data [lili@localhost data]$ dd if=/dev/zero of=/data/tp.txt bs=100M count=2
[External link image transfer failed, the source site may have an anti-leech mechanism, it is recommended to save the image and upload it directly (img-6BQtXf57-1631176495940)(D:\learning files\Linux\KY15 course\7, LVM and disk quota\screenshots \30.png)]
Summarize:
1. LVM is logical volume management, which can save existing data and dynamically adjust disk capacity;
2. One or more physical volumes form a volume group, and physical volumes can be disk partitions or disks;
3. 1PE=4MB in the physical volume;
4. The logical volume is built on the volume group and has no direct relationship with the physical volume;
xt bs=100M count=2
[External link pictures are being transferred...(img-6BQtXf57-1631176495940)] Summarize: 1,LVM It is a logical volume management, which can save the existing data and dynamically adjust the disk capacity; 2,One or more physical volumes form a volume group, and physical volumes can be disk partitions or disks; 3,Physical Volume 1 PE=4MB; 4,Logical volumes are built on volume groups and have no direct relationship with physical volumes;