XFS磁盘配额介绍以及配置

为了避免服务器中出现类似的磁盘空间不足的问题,可以启用磁盘配额功能,
对用户指定的磁盘空间,文件数量进行限制,
防止个别用户恶意或无意占用大量的磁盘空间

系统中的xfs文件系统配置管理磁盘配额的工具由xfsprogs软件包含的xfs_quota配置管理程序提供

查看是否安装配置工具,查看xfs_quota工具所在位置

[root@localhost ~]# rpm -q xfsprogs  查看是否安装配置工具
xfsprogs-4.5.0-15.el7.x86_64
[root@localhost ~]# rpm -ql xfsprogs | grep xfs_quota
/usr/sbin/xfs_quota
/usr/share/man/man8/xfs_quota.8.gz

磁盘配额概念

xfs_quota设置的磁盘配额,只在指定的文件系统内有效,用户使用未配额的文件系统时,将不受限制
磁盘容量:限制用户能够使用的磁盘数据块大小,默认单位kb
文件数量:限制用户可以创建的文件个数 quota限制i

软限制:指定一个软性的配额数据值,用户超过这个数据时,系统给出警告信息,可以打破数据值
硬限制:指定一个硬性的配额值,禁止用户超过这个限制

支持磁盘配额的三个条件:

内核
xfs_quota工具外,
前提条件即指定的分区必须已经挂载且支持磁盘配额功能

usrquota:支持对用户的磁盘配额
grpquota:支持对组的磁盘配额
就是挂载的时候使用:-o usrquota grpquota “mount挂载

实验前提已经使用fdisk分好区了,童鞋们可以查看以前的文章https://blog.csdn.net/aaaa_xiebiao/article/details/104520329

实例①如何挂载

首先创建一个文件夹,挂载

[root@localhost ~]# mkdir /tmp/a
[root@localhost ~]# mount -o usrquota,grpquota /dev/sdb1  /tmp/a 
[root@localhost ~]# mount | grep "/dev/sdb1"查看挂载的
/dev/sdb1 on /root/a type xfs (rw,relatime,seclabel,attr2,inode
64,usrquota,grpquota)

赋予其他用户读写权限
[root@localhost ~]# chmod 777  /tmp/a

第二种方法:
若要开机自动挂载,修改/etc/fstab
[root@localhost ~]# vim /etc/fstab
    /dev/sdb1	  /tmp/a			xfs	 defaults	0 0
[root@localhost ~]# mount -a

新建一个用户,alinux

创建一个新用户  alinux
[root@localhost ~]# useradd alinux
[root@localhost ~]# echo "123456" |passwd --stdin alinux 
更改用户 alinux 的密码 。
passwd:所有的身份验证令牌已经成功更新。

对用户alinux 设置磁盘配额,磁盘容量软限制为80M,硬限制为100M,文件软限制为80个,硬限制为100个

限制文件以及磁盘
[root@localhost ~]# xfs_quota -x -c 'limit -u bsoft=80M bhard=100M isof=80  ihard=100 alinux ' /tmp/a

仅限制磁盘容量时:
[root@localhost ~]# xfs_quota -x -c 'limit -u bsoft=80M bhard=100M alinux ' /tmp/a

仅限制文件数量时:
[root@localhost ~]# xfs_quota -x -c 'limit -u isoft=80 ihard=100 alinux ' /tmp/a

查看文件磁盘容量是否受限制:

查看磁盘容量对于用户是否受限制
[root@localhost ~]# xfs_quota -c 'quota -uv alinux '  /tmp/a
Disk quotas for User alinux (1001)
Filesystem              Blocks      Quota      Limit  Warn/Time      Mount
ed on/dev/sdb1                    0      81920     102400   00 [--------] /root

查看文件数量是否受限制:
/a[root@localhost ~]# xfs_quota -c 'quota -i -uv alinux ' a
Disk quotas for User alinux (1001)
Filesystem               Files      Quota      Limit  Warn/Time      Mounted on
/dev/sdb1                    0         80        100   00 [--------] /root/a

切换用户alinux ,实验是否配置成功


[alinux@localhost ~]$ dd if=/dev/zero of=/tmp/a/aa bs=1M count=81
记录了81+0 的读入
记录了81+0 的写出
84934656字节(85 MB)已复制,0.289575 秒,293 MB/[alinux@localhost ~]$ dd if=/dev/zero of=/tmp/a/aa bs=1M count=100
记录了100+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,0.139826 秒,750 MB/[alinux@localhost ~]$ dd if=/dev/zero of=/tmp/a/aa bs=1M count=101
dd: 写入"/tmp/a/aa" 出错: 超出磁盘限额
记录了101+0 的读入
记录了100+0 的写出
104857600字节(105 MB)已复制,0.0855834 秒,1.2 GB/

查看占用的文件数量:


[alinux@localhost a]$ touch {1..100}.txt
[alinux@localhost a]$ ls
100.txt  18.txt  26.txt  34.txt  42.txt  50.txt  59.txt  67.txt  75.txt  83.txt  91.txt  9.txt
10.txt   19.txt  27.txt  35.txt  43.txt  51.txt  5.txt   68.txt  76.txt  84.txt  92.txt
11.txt   1.txt   28.txt  36.txt  44.txt  52.txt  60.txt  69.txt  77.txt  85.txt  93.txt
12.txt   20.txt  29.txt  37.txt  45.txt  53.txt  61.txt  6.txt   78.txt  86.txt  94.txt
13.txt   21.txt  2.txt   38.txt  46.txt  54.txt  62.txt  70.txt  79.txt  87.txt  95.txt
14.txt   22.txt  30.txt  39.txt  47.txt  55.txt  63.txt  71.txt  7.txt   88.txt  96.txt
15.txt   23.txt  31.txt  3.txt   48.txt  56.txt  64.txt  72.txt  80.txt  89.txt  97.txt
16.txt   24.txt  32.txt  40.txt  49.txt  57.txt  65.txt  73.txt  81.txt  8.txt   98.txt
17.txt   25.txt  33.txt  41.txt  4.txt   58.txt  66.txt  74.txt  82.txt  90.txt  99.txt
[alinux@localhost a]$ touch {1..101}.txt
touch: 无法创建"101.txt": 超出磁盘限额

总结,对于用户alinux来说建立文件和占用磁盘有限制,说明对于用户建立磁盘配额成功,不需要建立的时候,可以直接umount /dev/sdb1取消挂载即可

发布了39 篇原创文章 · 获赞 19 · 访问量 2243

猜你喜欢

转载自blog.csdn.net/aaaa_xiebiao/article/details/104538709