Linux-LVM and Disk Quota

LVM overview

1. Meaning

  • LVM (Logical Volume Manager), logical volume management
  1. Ability to dynamically adjust the disk capacity while keeping the existing data unchanged, thereby improving the flexibility of disk management
  2. The /boot partition is used to store boot files and cannot be created based on LVM.

2. Composition

  • Basic concepts of LVM mechanism
  1. LV (Physical volume, physical volume)
    Physical volume is the basic storage device of the LVM mechanism, and usually corresponds to an ordinary 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 attributes of the LVM, and the storage space is divided into basic units (PE) with a default size of 4MB to form the physical volume.
  2. VG (volume group, volume group) is
    composed of one or more physical volumes as a whole, which is called a volume group, in which physical volumes can be dynamically added or removed.
  3. LV (Logical volume)
    is a piece of space divided from a volume group to form a logical volume. Use tools such as mkfs to create file systems on logical volumes.

3. LVM management commands

  • Main command
Features Physical volume management Volume group management Logical volume management
Scan pvscan vgscan lvscan
Create pvcreate vgcreate lvcreate
Display pvdisplay vgdisplay lvdisplay
Remove pvremove vgremove lvremove
Extend vgextend lvextend
Reduce vgreduce lvreduce

Two, instance: LVM

  • Main command steps of LVM operation

1. Add two new hard disks to the virtual machine and restart the virtual machine

Insert picture description here

2. View the hard disk and create hard disk partitions

First check whether the hard disk is created using the fdisk tool to divide the disk devices /dev/sdb and /dev/sdc into primary partitions sdb1 and sdc1, and change the ID mark number of the partition type to "8e"
fdisk -l
fdisk /dev/sdb
fdisk /dev/sdc
Insert picture description here
Insert picture description here

3. Create a physical volume

pvcreate /dev/sdb1 /dev/sdc1
Insert picture description here

4. Create a volume group named vg1

vgcreate vgname1 /dev/sdb1 /dev/sdc1
Insert picture description here

5. Create a logical volume named lv1

The logical volume name is lv1, the capacity is 20GB, and the generated file path is /dev/vg1/lv1
lvcreate -L 20G -n lv1 vg1
Insert picture description here

6. Format and mount

Format the logical volume, create an XFS file system, and mount it to the /data directory
mkfs.xfs /dev/vg1/lv1
mount /dev/vg1/ lv1 /data
df -hT
Insert picture description here
Insert picture description here

7. Expand again

vgextend vgname1 /dev/sdc2
lvextend -L +10G /dev/vg1/lv1
resize2fs /dev/vg1/lv1###Refresh ext4 file system capacity
xfs_growfs /dev/vg1/lv1###Refresh xfs file system capacity
Insert picture description here
Insert picture description here

3. Overview of Disk Quota

1. Conditions

  • Conditions for achieving disk quota

1. Need Linux kernel support
2. Install xfsprogs and quota software packages

2. Features

  • Features of Linux Disk Quota

1. Scope: for the specified file system (partition)
2. Restriction object: user account, group account
3. Restriction type: disk capacity, number of files
4. Restriction method: soft limit, hard limit

3. Steps

  • step
  1. Long load the file system in a way that supports the quota function
  2. Edit quota settings for user and group accounts
  3. Verify disk quota function
  4. View disk quota usage

4. Settings

  • Set disk quota
  1. When the disk space of the Linux root partition is exhausted, the Linux operating system will no longer be able to create new files. At the same time, failures such as service program crashes and system failures may occur.
  2. In order to avoid problems such as insufficient disk space in the server, the disk quota function can be enabled to limit the disk space and the number of files used by users in the specified file system (partition) to prevent individual users from maliciously or unintentionally occupying a large number of disks. Space to maintain the stability and continuous availability of system storage space.
  3. In the CentOS system, different file systems use different disk quota configuration management tools. For example, the XFS file system is managed by the xfs_quota tool; the EXT3/4 file system is managed by the quota tool.

Four, example: disk quota management

  • Steps to set disk quota in Centos7

1. Check whether the xfsprogs and xfs_quota software packages have been installed

rpm -q xfsprogs quota
yum install -y xfsprogs quota
Insert picture description here

2. Mount the file system in a way that supports the quota function

umount /dev/vg1/lv1
1. Manually mount
mount -o usrquota,grpquota /dev/vg1/lv1 /data###Add mounting parameters "usrquota, grpquota" to increase support for user and group quota functions or
2. Automatically mount
vim /etc/fstab
/dev/vg1/lv1——/data——xfs——defaults, usrquota, grpquota——0——0
mount -a### -a option, set /etc/fstab Reload everything
Insert picture description here
Insert picture description here

3. Edit the quota settings of user and group accounts

useradd zhangsan
passwd zhangsan
xfs_quota -x -c'limit -u bsoft=80M bhard=100M isoft=4 ihard=5 zhangsan' /data
-x: means to start expert mode, all management of the quota system is allowed to be modified in the current mode The command is available.
-c: Indicates that the management command is directly invoked.
-u: Specify the user account object
-g: Specify the group account object
bsoft: Set the soft limit value of the disk capacity (the default unit is KB).
bhard: Set the hard limit value of the disk capacity ((default unit is KB).
isoft: Set the soft limit value of the number of disk files.
ihard: Set the hard limit value of the number of disk files . #Limit
only the disk capacity
xfs_quota -x -c ' limit -u bsoft=80M bhard=100M zhangsan' /data #Limit
only the number of files
xfs_quota -x -c'limit -u isoft=4 ihard=5 zhangsan' /data #View
zhangsan disk capacity limit
xfs_quota -c'quota -uv zhangsan' /data #View
zhangsan file limit
xfs_quota -c 'quota -i -uv zhangsan' /data
Insert picture description here

4. Verify the disk: quota function

chmod 777 /data
su zhangsan
cd /data #Verify
that the disk capacity exceeds the limit
dd if=/dev/zero of=/data/1.txt bs=10M count=12 #Verify
that the number of disk files exceeds the limit
touch {aa, bb,cc ,dd, ee,ff}.txt
dd command is a device conversion and continuous copy command
"if=" specifies the input device (or file)
"of=" specifies the output device (or file)
"bs=" specifies the read data block The size of
"count=" specifies the number of data blocks read
/dev/zero "zero" device file, can provide unlimited null characters. Often used to generate a specific size
Insert picture description here
Insert picture description here

5. Check the quota usage

  1. View the disk capacity quota usage of all available partitions
    xfs_quota -x -c'report -a'
    Insert picture description here
  2. View the report of disk capacity and number of files
    xfs_quota -x -c'report -abih'
    Insert picture description here

Guess you like

Origin blog.csdn.net/s15212790607/article/details/113359535