LVM and Disk Quota in LINUX

LVM and Disk Quota in LINUX

One, LVM overview

1. LVM logical volume management

(1) The disk capacity can be dynamically adjusted 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. The basic concept of LVM mechanism

PV (Physical Volume)
VG (Volume Group)
LV (Logical Volume)
Insert picture description here

Insert picture description here
The so-called logical volume is a part divided from the volume group, and the volume group is a whole composed of multiple physical volumes. Logical volumes do not have to use up the entire volume group, but a part of it can be used.

3. LVM concept

PV (Physical volume, physical volume)
physical volume is the basic storage device of the LVM mechanism, usually corresponding to an ordinary partition or the 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 LVM, and the storage space is divided into basic units (PE) with a default size of 4MB to form a physical volume.
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.
IV (Logical volume)
A piece of space divided from a volume group to form a logical volume. Use tools such as mkfs to create a file system on a logical volume.

Two, LVM management commands

1. Main commands

Features Physical volume management Volume group management Logical volume management
Scan pvscan vgscan lvscan
Create pvcreate vgcreate lvcreate
Display pvdisplay vgdisplay Ivdisplay
Remove pvremove vgremove lvremove
Extend —— vgextend Ivextend
Reduce —— vgreduce Ivreduce
pvcreate 设备名1   [设备名2 .....]  
vgcreate  卷组名 物理卷名1  物理卷名2
lvcreate  -L 容量大小 -n 逻辑卷名 卷组名
lvextend -L +大小 /dev/卷组/各逻辑卷名
1234

When you want to extend the size of a logical volume, use the "lvextend" command to extend. Note that the logical volume cannot be in the logical volume before expansion. The logical volume can be edited without unmounting, or it can be edited after unmounting, and there must be a "+" before the extended space, otherwise the original space will be changed For 20G, not expansion. Here, the logical volume is expanded by 20G.
Insert picture description here

Use the lvdisplay command to view the size of the expanded logical volume.
Insert picture description here

3. Overview of Disk Quota

1. Conditions for realizing the disk quota

(1) Need Linux kernel support
(2) Install xfsprogs and quota software packages (check whether these two software packages are installed in the system, you can use "rpm -qa | grep xfsprogs" to filter and filter.)
Use rpm -q quota xfsprogs to query Whether the two software have been installed, it is found that they have been installed. Because these two software are installed by default in Linux 7 system. If you find that it is not installed, you can install it with "yum install -y …".
Insert picture description here

2. The characteristics 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 (node ​​number)
(4) Restriction method: soft limit, hard limit
Insert picture description here

3. Set disk quota

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.
In order to avoid problems like 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 the user 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.
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.

4. Steps to set disk quota in centos7

(1) Check whether the xfsprogs and xfsquota software packages have been installed
rpm   -q   xfsprogs   quota (检查是否已经安装)
yum  install  -y  xfsprogs   quota  (没有安装的话使用该命令安装)
12
(2) Mount the file system in a way that supports the quota function
umount   /dev/vgname1/lvname1
mount   -o  usrquota, grpquota    /dev/vgname1/ lvname1   /opt(手动挂载)
添加挂载参数"usrquota, grpquota"用于增加对用户、组配额功能的支持
或者
vim    /etc/fstab
/dev/vgname1/lvname1        /opt        xfs        defaults,usrquota,grpquota     0    0(自动挂载)

umount    /dev/vgname1/lvname1
mount    -a                   ###-a选项,将/etc/fstab的所有内容重新加载
123456789
(3) Edit the quota settings of user and group accounts
useradd     zhangsan    (创建一个新用户)
passwd      zhangsan      (设置密码用来激活该新用户)
12
xfs_quota     -x     -c    'limit   -u    bsoft=80M   bhard=100M    isoft=40     ihard=50    zhangsan'      /opt/
1

-x: Indicates that the expert mode is activated, and all management commands that allow modification of the quota system are available in the current mode.
-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 (the default unit is KB)
isoft: Set the number of disk files The value of the soft limit.
ihard: Set the hard limit value for the number of disk files.

Only limit disk capacity:

xfs_quota    -x    -c    'limit    -u    bsoft=80M     bhard=100M    zhangsan'        /opt/
1

Only limit the number of files

xfs_quota    -x   -c    'limit    -u    isoft=40    ihard=50    zhangsan'     /opt/
1

View zhangsan disk capacity limit

xfs_quota    -c    'quota    -uv    zhangsan'    /opt/
1
(4) Verify the disk quota function
chmod    777  /opt
su    zhangsan
cd    /opt
123

Verify that the disk capacity exceeds the limit:

dd    if=/dev/zero    of=/opt/ddtest.txt    bs=10M    count=12 (意思是:每次给10M,连续给12次)
1

Verify that the number of disk files exceeds the limit

touch  {1..101}.txt
1

The dd command is a device conversion and continuous copy command
" if= "Specify the input device (or file)
" of= "Specify the output device (or file)
" bs= "Specify the size of the read data block
" count= "Specify the read The number of data blocks
/dev/zero The "zero" device file can provide unlimited null characters. It is often used to generate a file of a specific size.

(5) View quota usage

View the disk capacity quota usage of all available partitions

xfs_quota    -x    -c    'report    -a'
1

View report of disk capacity and file count

xfs_quota   -x   -c 'report   -abih'
1

First check whether the package is installed, and then use the automount command.
Insert picture description here

Write the automatically mounted program to save and exit.
Insert picture description here

Use the "mount -a" command to mount, with the "-a" option, you can reload all the contents of /etc/fstab, so that it can be automatically mounted.
Insert picture description here

Create a new user where you need to mount, here is the zhangsan user. After creating the new user, you need to set a password to activate the new user before it can be used.
Insert picture description here

After creating a new user, use the following command to edit the user's quota limit. Among them, "-x": Indicates that the expert mode is activated, and all management commands that allow modification of the quota system are available in the current mode. "-C": Indicates that the management command is directly invoked. "-U": Specify the user account object. "Bsoft": set the soft limit value of the disk capacity to 80M, "bhard": set the hard limit value of the disk capacity to 100M, "isoft": set the soft limit value of the number of disk files to 40, "ihard": set the disk The hard limit value for the number of files is 50.
Insert picture description here

Use the following command to view the zhangsan disk capacity limit. Found that the quota has been set successfully.
Insert picture description here

Then set the user authority, you need to give 777 the highest authority, otherwise the user cannot execute the commands in it. Then use the command to verify that the disk capacity exceeds the limit:
dd if=/dev/zero of=/abc01/test.txt bs=10M count=12 (meaning: give 10M each time, give 12 times in a row) where test. txt is a file created by myself.

Insert picture description here

When the stored capacity is too much, it will prompt that the disk quota has been exceeded.
Insert picture description here

The command to limit the number of files is: xfs_quota -x -c'limit -u isoft=4 ihard=5 zhangsan' /opt/, the maximum hard limit is 5 files, by creating 6 files under this partition, it is found that the limit is exceeded Disk quota.
Insert picture description hereInsert picture description here

Guess you like

Origin blog.csdn.net/tefuiryy/article/details/110532111