文件系统配额
- 要想做文件系统配额必须是独立的分区才能做
- 我们针对/home做配额限制,因为之前home并不是单独的分区,所以要把home迁移一个单独的分区上,在之前的实验过程中已经迁移完了。
- 由于做配额限制要启用usrquota对用户,对组做配额要启用grpquota ,我们直接在fstab文件中加上
UUID=155cc08a-a66c-4389-8986-92129b20b26c /home ext4 defaults,usrquota,grpquota 0 0
- 然后重新挂载一下
mount -o remount /dev/sda6 /home
- 用mount 查看一下挂载里是否添加上
[root@centos6 home]# mount
/dev/sda6 on /home type ext4 (rw,usrquota,grpquota)
- 我们进入要限制的目录里运行quotacheck 会创建两个文件,这条命令是 初始化数据库,运行这个命令一定确定selinu关闭 /etc/selinux/config 的文件,不然会执行不成功
[root@centos6 /]# quotacheck -cug /home
[root@centos6 /]# cd /home
[root@centos6 home]# ls
aquota.group aquota.user guo lost+found mnt2 xiaoming
- 会创建aquota.group 和 aquota.user 这两个文件
- 现在针对guo用户做配额
- 首先开启用quotaon -p /home
bash
[root@centos6 ~]# quotaon -p /home
group quota on /home (/dev/sda6) is on
user quota on /home (/dev/sda6) is on
- 指定用户的空间限制
bash
[root@centos6 ~]# edquota guo 此命令是编辑guo用户空间限制
Disk quotas for user guo (uid 500):
Filesystem blocks(占用) soft (软限制) hard (硬限制) inodes(inode编号) soft hard
/dev/sda6 2376 0 0 365 0 0
是以k为单位的
Disk quotas for user guo (uid 500):
Filesystem blocks(占用) soft (软限制) hard (硬限制) inodes(inode编号) soft hard
/dev/sda6 2376 800000 1000000 365 0 0
[root@centos6 ~]# quota guo
Disk quotas for user guo (uid 500):
Filesystem blocks quota limit grace files quota limit grace
/dev/sda6 2376 800000 1000000 365 365 0
- 首先开启用quotaon -p /home
- 现在测试
[guo@centos6 ~]$ dd if=/dev/zero of=f1 bs=1M count=2048
sda6: warning, user block quota exceeded.
sda6: write failed, user block limit reached.
dd: writing `f1': Disk quota exceeded
975+0 records in
974+0 records out
1021562880 bytes (1.0 GB) copied, 10.1314 s, 101 MB/s
[guo@centos6 ~]$ du -sh /home/guo/
977M /home/guo/
[guo@centos6 ~]$ quota guo
Disk quotas for user guo (uid 500):
Filesystem blocks quota limit grace files quota limit grace
/dev/sda6 1000000* 800000 1000000 6days 366* 365 0 6days(在这7天只能可以达到硬限制,过了7天则只能达到软限制)
[guo@centos6 ~]$
- 如何对组添加配额
- 如何用户和组都有配额限制,则是那个限制最低会生效。
- 我们现在把刚刚的用户配额不限制,0就是不限制
Disk quotas for user guo (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/sda6 0 0 0 366 365 0
- edquota -g GROUPNAME 这个是设置组的,其它和设定用户一样。
其它查询命令
- 用户调查 : quota -u usernam
- 组调查 :quota -g grepname
查看配额概述 : repquota /dir
如何删除配额限制
- 用命令先禁用配额
- quotaoff /dir
然后删除目录里的生成的文件
[root@centos6 home]# quotaoff -p /home group quota on /home (/dev/sda6) is off user quota on /home (/dev/sda6) is off [root@centos6 home]# rm aquota.* rm: remove regular file `aquota.group'? yes rm: remove regular file `aquota.user'? yes [root@centos6 home]# ls guo lost+found mnt2 xiaoming [root@centos6 home]#
把/etc/fstab 中的文件把usrquota,和gprquota去掉
- 然后重新挂载就好了