linux_disk quota

1. Overview of Disk Quota

Conditions for realizing disk quotas
●Linux kernel support required
●Install xfsprogs and quota software packages

The characteristics of Linux disk quotasScope
: for the specified file system (partition)
Restriction objects: user accounts, group accountsRestriction
types: disk capacity, number of
filesRestriction methods: soft limit, hard limit

2. 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 number of files used by the user in the specified file system (partition) to prevent individual users from malicious or unintentional occupation A large amount of disk 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.

3. Steps to set disk quota

1. Check whether the xfsprogs and xfs_ quota software packages have been installed
rpm -q xfsprogs quota
yum install -y xfsprogs quota

2. Mount the file system in a way that supports the quota function
umount /dev/vgname1/lvname1
mount -o usrquota, grpqucta /dev/ vgname1/ lvname1 /opt #Add the
mount parameter "usrquota, grpquota" for adding users and groups Quota function support

Or
vim /etc/ fstab
/dev/ vgname1/ lvname1 /opt xfs de faul ts, usrquota, grpquota 0 0

umount /dev/ vgname1/ lvname 1
mount -a #-a option, reload all contents of /etc/fstab

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=40 ihard=50 zhangsan’ /opt/

-X: means to start expert mode, all management commands that allow modification of the quota system are available in the current mode.

-c: means to directly call management commands.

-u: Specify the user account object

-g: Specify the user 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 soft limit value for the number of disk files.
ihard: Set the hard limit value for the number of disk files.

4. Verify the disk quota function
chmod 777 /opt
su zhangsan
cd /opt #Verify
that the disk capacity exceeds the limit
dd if=/dev/zero of=/opt/ddtest. txt bs=10M count=12

#Verify that the number of disk files exceeds the limit
touch {aa,bb,cc,dd,ee, ff} .txt

5. View quota usage:
####View disk capacity quota usage of all available partitions:

[root@localhost ~]# xfs_quota -x -c ‘report -a’

4. Disk quota experiment steps

1. Check if the xfsprogs and xfs_ quota packages have been installed
rpm -q xfsprogs quota
yum install -y xfsprogs quota ####Installation command

Insert picture description here

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

临时挂载
[root@localhost ~]# umount /dev/vgname1/lvname1
[root@localhost ~]# mount -o usrquota,grpquota /dev/vgname1/lvname1 /opt


或者自动挂载
vim /etc/ fstab
/dev/ vgname1/ lvname1      /opt     xfs     de faul ts, usrquota, grpquota   0 0

  • ① df- h view mount:

Insert picture description here

  • ②Unmounting:

  • Insert picture description here

  • ③: There are two ways to mount, here we use automatic mount:

Insert picture description hereInsert picture description here

3. Edit the quota settings of user and group accounts

useradd zhangsan

passwd zhangsan

  • Create account and set password
    Insert picture description here

  • Quota settings:
    Insert picture description here

  • View command:

 [root@localhost ~]# xfs_quota -c 'quota -uv zhangsan' /opt

Insert picture description here
Insert picture description here

4. Verify the disk quota function

chmod 777 /opt
su zhangsan
cd /opt

Insert picture description here


#Verify that the disk capacity exceeds the limit dd if=/dev/zero of=/opt/ddtext.txt bs=10M count=9

Insert picture description here

5. View quota usage

####View the disk capacity quota usage of all available partitions:

[root@localhost ~]# xfs_quota -x -c ‘report -a’
Insert picture description here

Verify that the disk capacity and the number of files exceed the limit:

Create a file:
Insert picture description here

View the report of disk capacity and number of files;
[root@localhost opt]# xfs_quota -x -c'report -abih'

Insert picture description here
Insert picture description here
Insert picture description here

Guess you like

Origin blog.csdn.net/Wsxyi/article/details/113646130