限定用户或组对磁盘空间的使用
[root@localhost ~]# rpm -qf `which quota` quota-4.01-11.el7.x86_64
[root@localhost ~]#mkfs.ext4 /dev/sdc3 [root@localhost ~]#mkdir /tmp/sdc3 [root@localhost ~]#mount /dev/sdc3 /tmp/sdc3/
[root@localhost ~]# mount -o remount,usrquota,grpquota /tmp/sdc3/ [root@localhost ~]# mount
/dev/sdc3 on /tmp/sdc3 type ext4 (rw,relatime,quota,usrquota,grpquota,data=ordered)
永久生效
/dev/sdc3 /tmp/sdc3 ext4 defaults,usrquota,grpquota 0 0 写在/tec/fstab
[root@localhost ~]# tail -n 1 /etc/fstab /dev/sdc3 /tmp/sdc3 ext4 defaults,usrquota,grpquota 0 0
#检测磁盘配额并生成配额的文件
[root@localhost ~]#quotacheck -cugv /tmp/sdc3/
[root@localhost ~]# ll -a /tmp/sdc3/ total 29 drwxr-xr-x 3 root root 1024 Dec 2 17:48 . drwxrwxrwt. 15 root root 4096 Dec 2 17:48 .. -rw------- 1 root root 6144 Dec 2 17:48 aquota.group -rw------- 1 root root 6144 Dec 2 17:48 aquota.user drwx------ 2 root root 12288 Dec 2 17:34 lost+found
确保关闭selinux 与selinux有关 [root@localhost ~]# getenforce #disabled关闭状态 Disabled
[root@localhost ~]# vim /etc/selinux/config #没关的时候打开文件 设置SELINUX=disabled
#用户和组的配额设置
[root@localhost ~]# useradd hcr [root@localhost ~]# id hcr uid=5007(hcr) gid=5007(hcr) groups=5007(hcr) [root@localhost ~]# edquota -g hcr #自动打开vim 设置 1 Disk quotas for group hcr (gid 5007): 2 Filesystem blocks soft hard inodes soft hard 3 /dev/sdc3 80 50 80 0 0 # 0
#激活磁盘配额
[root@localhost ~]# quotaon -ugv /tmp/sdc3/ /dev/sdc3 [/tmp/sdc3]: group quotas turned on /dev/sdc3 [/tmp/sdc3]: user quotas turned on
#测试
[root@localhost ~]# mkdir /tmp/sdc3/test #在sdc3下创建test目录 然后切换到hcr用户
[hcr@localhost test]$ dd if=/dev/zero of=hcr.txt bs=1k count=90 #block 1k 设置hard容量80k 所以超过80k报错error 大于50k会报警 sdc3: warning, group block quota exceeded. sdc3: write failed, group block limit reached. dd: error writing ‘hcr.txt’: Disk quota exceeded 81+0 records in 80+0 records out 81920 bytes (82 kB) copied, 0.000472524 s, 173 MB/s
[hcr@localhost test]$ ll -h total 80K -rw-rw-r-- 1 hcr hcr 80K Dec 2 18:13 hcr.txt #说明 [root@localhost ~]# tune2fs -l /dev/sdc3 | grep size #查看blocksize Filesystem features: has_journal ext_attr resize_inode dir_index filetype needs_recovery extent 64bit flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize Block size: 1024 Fragment size: 1024 Group descriptor size: 64 Flex block group size: 16 Inode size: 128
#说明磁盘配额中的blocks 一个block是1K