quota 磁盘配额 测试环境配置流程

  • 参考:

云栖社区:xfs分区设置空间配额

IBM:管理磁盘配额

鸟哥私房菜:磁盘配额

  • 注:磁盘类型为 xfs

fstab文件配置分区,使其可被quota控制

1.打开fstab文件

$ sudo vim  /etc/fstab

2.配置分区。预对挂载于home目录下的分区进行空间配额,故在/home对应的行添加,usrquota,grpquota,使quota可控制/home下挂载的分区

#
# /etc/fstab
# Created by anaconda on Thu Jul  4 10:41:38 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=cde78703-f6af-48f8-bb01-900439c3b29a /                       xfs     defaults        0 0
UUID=a9a1f244-644c-495c-a784-1c65c5404847 /boot                   xfs     defaults        0 0
UUID=0716eaaa-8008-460f-911a-19e027c7a675 /home                   xfs     defaults,usrquota,grpquota        0 0
UUID=e173a278-7af7-4e3b-891f-8ecab7d7bf47 swap                    swap    defaults        0 0

3.完成上述步骤后,重启服务器,使配置生效

4.用mount查看配置是否生效.如下,显示/home中包含(usrquota,grpquota)两配置

$ mount | grep '/home'
/dev/sda2 on /home type xfs (rw,relatime,seclabel,attr2,inode64,usrquota,grpquota)

xfs_quota命令限制用户空间

1.限制用户空间。用户目录在/home目录下,故对挂载/home的分区进行配额。设置软阈值1Gbsoft=1G,硬阈值为2Gbhard=2G, 限制的用户为yhuang

$ sudo xfs_quota -x -c "limit bsoft=1G bhard=2G yhuang" /home

2.硬阈值不可超出。超过软阈值,会受到警告,默认7天,超过时限,软阈值会变为硬阈值

3.普通用户查看阈值限制报告

$ xfs_quota -c 'quota -uvh [user name]' /home
Filesystem              Blocks      Quota      Limit  Warn/Time      Mounted on
/dev/sda2              2097132    1048576    2097152   00  [6 days] /home

4.超级用户查看阈值报告

$ sudo xfs_quota -x -c "report -ubh" /home
User quota on /home (/dev/sda2)
                        Blocks              
User ID      Used   Soft   Hard Warn/Grace   
---------- --------------------------------- 
root            0      0      0  00 [------]
yhuang       1.3G   500M     1G  00 [-none-]
usr1       695.8M      0      0  00 [------]
usr2          12K      0      0  00 [------]

你可能感兴趣的:(quota 磁盘配额 测试环境配置流程)