LVM

An overview of the

define

  • Logical Volume Manager (LVM) manages Logical volumes

It is a mechanism for managing disk partitions in Linux. Implemented by Heinz Mauelshagen in the Linux 2.4 kernel, it can dynamically adjust disk capacity while keeping the existing data unchanged, thus improving the flexibility of disk management

The /boot partition is used to store boot files and cannot be created based on LVM

2. Basic concepts of LVM mechanism

2.1 Physical Storage Media

  • Physical storage devices: Disks, such as /dev/hda and /dev/sda, are the lowest level storage units of a storage system.

2.2 Physical Volume (PV)

  • A physical volume is the basic storage device of the LVM mechanism. It usually corresponds to a common partition or the entire hard disk. When a physical volume is created, a reserved block is created in the head of the partition or hard disk to record the attributes of the LVM and divide the storage space into basic units (pes) with a default size of 4MB

2.3 Volume Group (VG)

  • A volume group consists of one or more physical volumes. You can dynamically add or remove physical volumes from a volume group

1.3 Logical Volumes (LV)

  • A space separated from a volume group to form a logical volume. Use tools such as MKFS to create a file system on a logical volume

LVM management commands

function pv vg lv
Scan to scan pvscan vgscan lvscan
Create establishes pvcreate vgcreate lvcreate
The display shows pvdisplay vgdisplay lvdisplay
Remove delete pvremove vgremove lvremove
The extend extension vgextend lvextend
Reduce to reduce vgreduce lvreduce
Pvcreate Device name 1 [device name 2... // Create a physical volume vgcreate Volume group name Physical volume name 1 Physical volume name 2 // Assign a physical volume to a volume group lvcreate -l Capacity size -n Logical volume name Volume group name // Create a logical volume from a volume group lvextend -l + size /dev/volume group name/Logical volume name // Logical volume space expansionCopy the code

LVM application instance

Procedure: PV→VG→LV→ format, mount the file system

1. Shut down the host, add two new disks, restart the host, or refresh the disk status

echo "- - -" > /sys/class/scsi_host/host0/scan 
echo "- - -" > /sys/class/scsi_host/host1/scan 
echo "- - -" > /sys/class/scsi_host/host2/scan
Copy the code

2. Disk partition (remember wq to save)

  • 2.1 Creating a Disk

  • 2.2 Modifying Disk Attributes To change the DISK ID to 8E

– The same for the other disk (remember to save after wq partition)

  • To complete the partition

3. Create a physical volume.

pvcreate /dev/sdb1 /dev/sdc1
Copy the code

View physical volume information

pvdisplay
Copy the code

4. Create a volume group

vgcreate vgname1 /dev/sdb1 /dev/sdc1
Copy the code

5. Create a logical volume with the capacity of 30 GB

  • Create a logical volume named my from the vgname1 volume group
lvcreate -L 30G -n my vgname1
Copy the code

To view

6. Format the logical volume, create an XFS file system, and mount it to the /data directory

mkfs.xfs /dev/vgname1/my

mount /dev/vgname1/my /data
Copy the code
  • 6.1 the formatting

  • 6.2 mount

7,

And just like in the previous step, Add a hard disk to create a partition (SDD) pvcreate /dev/sdd1 // Create a physical volume vgextend vgname1 /dev/sdd1 // Create a volume group lvextend -l +20G /dev/vgname1/my // Create a logical volume. Capacity 20 gb xfs_growfs /data // Refreshes the capacity of an XFS file systemCopy the code

7.1 Adding a Hard Disk and Creating partitions

7.2 Creating a Physical Volume (PV)

7.3 Creating A Volume Group

7.4 Creating a Logical Volume (LV)

7.5 No Change Is Found After the Vm Is Added

7.6 XFS File System Capacity Needs to Be Refreshed (Refreshing mount Points)

7.7 Look again, the capacity is ready

Disk quota

An overview of the

1. Conditions for achieving disk quotas

Linux kernel support is required

Install xFSProgs and Quota software packages

 

2. Linux disk quota features

Scope: For the specified file system (partition)

Restricted objects: User accounts and group accounts

Limit type: Disk capacity and file quantity

Limit method: soft limit, hard limit

  • Hard limit: An absolute limit on resource nodes and data blocks. Users are not allowed to exceed this limit under any circumstances

  • Soft limit: A user can apply for resources within the hard limit after the soft limit is exceeded (the default time is one week and is set in /usr/include/sys/fs/ufs_quota. H). At the same time, the system displays a warning message and the remaining time for the user to apply for resources. If the hard disk usage still exceeds the soft limit, the system does not allow the user to apply for hard disk resources

Common commands and options

Steps for disk quotas

When the disk space of the Linux root partition is used up, the Linux operating system cannot create new files, and service programs may crash or the system may fail to start.

To avoid to appear similar to the problem of insufficient disk space in the server, you can enable disk quotas function, to the user in the specified file system (partition) used in the disk space, to limit the number of files, to prevent individual users malicious or inadvertently take up a lot of disk space, so as to maintain the stability of the system storage space and continuous availability.

In CentOS, different file systems use different disk quota configuration and management tools. For example, XFS file systems are managed using the xfs_quota tool. Ext3/4 file systems are managed using the Quota tool.

Disk Quota Management

Enable disk quota support

  1. Check whether the XFSProgs and Xfs_Quota software packages have been installed
rpm -q xfsprogs quota
Copy the code

  1. Use mount to enable quota support for a file system
  • Temporary mount
Umount /data // Unmount mount -o usrquota /dev/vgname1/my /data // Add mounting parameters mount // Check whether the mount is successfulCopy the code

  • Manually mount
[root@localhost ~]# vim /etc/fstab / Enable disk quotas support/dev/vg1 / my/data XFS defaults, usrquota, grpquota 0 0 / root @ localhost ~ # mount - a / / to mountCopy the code

2. Edit the quota Settings for user and group accounts

Edit quota Settings using the xfs_quota command:

Xfs_quota-x -c "limit -u bsoft=N bhard=N isoft=N ihard=N user name "Mount pointCopy the code

Common options:

  • -x: enables the expert mode. In the current mode, all management commands that modify the quota system can be used.
  • -c: directly invokes management commands.
  • -u: specifies the user account object.
  • -g: specifies the group account object.

Restricted field:

  • Bsoft: Sets the soft limit of the disk capacity (default unit: KB).
  • Bhard: Sets the hard limit of the disk capacity (default unit: KB).
  • Isoft: Sets the soft limit for the number of disk files.
  • Ihard: sets the hard limit for the number of files on the disk.

Example:

Xfs_quota-x -c "limit -u bsoft=100M bhard=150M hope" /data # Xfs_quote-x -c "limit -u isoft=5 ihard=10 hope" /dataCopy the code

2. Check the disk quota usage

The xfs_quota command displays the Settings and usage of disk quotas.

Xfs_quota -x -c "Report Options" mount pointCopy the code

Report common options:

  • -u: Views the user
  • -g: Views groups
  • -a: Displays the quota usage report of all AVAILABILITY zones
  • -b: Check the disk capacity
  • -i: Displays the number of files
  • -h: User-friendly display
Xfs_quote-x -c "report -ubih" /data // Query /data User quota on /data (/dev/mapper/vgname1-my) Blocks Inodes User ID Used Soft Hard Warn/Grace Used Soft Hard Warn/Grace ---------- --------------------------------- --------------------------------- root 0 0 0 00 [------] 3 0 0 00 [------] hope 0 100M 150M 00 [------] 0 5 10 00 / -- -- -- -- -- -Copy the code

3. Verify the disk quota function

  • Switch to the partition with the quota (mount directory)
  • Create a specified number of files: use the touch command, or the cp command
  • Create a file of specified size: use dd command, or cp command

[root@localhost ~]# chmod 777 /data // set all users to have read/write execution permission on /data directory [root@localhost ~]# su hope // Switch to hope user [hope@localhost Root]$CD /data/ / Switch to /data directory [hope@localhost data]$dd if=/dev/zero of=/data/123.txt bs=100M count=3 // copy 300M Dd: write "/data/123.txt" to /data/123.txt 2+0 read record 1+0 write 157286400 bytes (157 MB) copied, 0.523713 seconds 300 MB/ SEC [hope@localhost data]$exit // Exit user exit [root@localhost ~]# xfs_quota -x -c "report -ubih" /data // Check that the user has used 150 MB capacity. Create a file User quota on /data (/dev/mapper/vgname1-my) Blocks Inodes User ID Used Soft Hard Warn/Grace Used Soft Hard Warn/Grace ---------- --------------------------------- --------------------------------- root 0 0 0 00 [------] 3 0 0 00 [------] hope 150M 100M 150M 00 [7 days] 1 5 10 00 [------]Copy the code

4. Cancel the disk quota

Command format:

Xfs_quota-x -c "disable-up" mount point # Temporarily removes limits on quotas, but the system is still calculating them, just not controlling them. Xfs_quota-x -c "enable-up" mount point # Restore to the normal control state. Disable and fs_quota-x are disabled. Xfs_quota-x -c "off-up" mount point # Disable all limits on quota. After using this state, quota cannot be started again until it is unmounted and remounted. (Does not remove limits on quota, just turns them off.) Xfs_quota -x -c "remove -p" mount point # This command must be executed in the off state to remove limits on a quota. (Note: "remove-p" will remove restrictions on all items)Copy the code

Example: “off-up” turns off quota limits and then tests whether the HOPE user can create files

[root@localhost ~]# xfs_quota-x -c "off-up" /data // Completely disable quota limits [root@localhost ~]# su hope // Switch to user Hope [hope@localhost root]$CD /data/ / To the data directory [hope@localhost data]$dd if=/dev/zero of=/data/321. TXT bs=200M count=1 // Write the file 209715200 bytes (210 MB) have been copied, 0.60735 SEC, 345 MB/ SEC [hope@localhost data]$ls // view write 123.txt 321.txtCopy the code