磁盘配额
quota -av #开启所有的配额,重新配置配额信息后,需要开启配额,否则不生效
quotaon -vug /mnt/tom 启用配额
quotaoff -vug /mnt/tom #关闭配额(注意不可以对根分区和root用户进行限制)
#fstab下的记录
/dev/sda5 /mnt/test ext4 defaults,usrquota,grpquota 0 0
mount -a #fstab使生效
usrquota,grpquota #开启用户、用户组的限额
mount -o remount,usrquota /home #临时设置
/etc/fstab #不临时
检查磁盘配额
quotachack -cugv /mnt/tom 建立配额数据
ls -l /mnt/tom
edquota -u user
-g 对用户组
-t 使用宽限时间设置
edquota tom 设置某个用户的配额
edquota -p root tom 设置tom用户配额以root用户为模板
repquota test/ 查看配额信息
repquota -a 查看所有配额信息
blocks(kb) 空间大小以kb为单位
Filesystem blocks soft hard inodes soft hard
/dev/sda5 0 0 0 0 0 0
运行 repquota 时,只显示 root 用户
[root@ton test]#repquota -a
*** Report for user quotas on device /dev/sda5
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 20 10000 10000 2 3 0
但是用户tom设置可生效如下
[root@ton test]#quota -v tom
Disk quotas for user tom (uid 500):
Filesystem blocks quota limit grace files quota limit grace
/dev/sda5 0 1024 15360 0 3 4
[root@ton test]#
这里使用-av
选项则显示正常,可能是软件bug吧
[tom1@paly ~]$sudo repquota -av
*** Report for user quotas on device /dev/sda5
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root +- 51220 10000 10000 none 3 3 0
tom ++ 15360 1024 15360 none 4 3 4 none
tom1 ++ 20000 1024 35360 6days 4 3 4 6days
tom2 -- 0 1024 15360 0 3 4
Statistics:
Total blocks: 8
Data blocks: 1
Entries: 4
Used average: 4.000000
[tom1@paly ~]$sudo repquota -avg #查看组配额
*** Report for group quotas on device /dev/sda5
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
Group used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 51220 0 0 3 0 0
tom -- 15360 0 0 4 0 0
tang -- 20000 20000 20000 4 7 8
Statistics:
Total blocks: 8
Data blocks: 1
Entries: 3
Used average: 3.000000
配额测试
[tom@ton ~]$su - tom
Password:
[tom@ton ~]$who am i
tom pts/0 2022-03-11 01:37 (192.168.31.163)
[tom@ton ~]$cd /mnt/test/
[tom@ton test]$touch file1 file2 file3
[tom@ton test]$ls
aquota.group aquota.user file1 file2 file3 lost+found
[tom@ton test]$touch file4
sda5: warning, user file quota exceeded.
[tom@ton test]$ls
aquota.group aquota.user file1 file2 file3 file4 lost+found
[tom@ton test]$touch file5
sda5: write failed, user file limit reached.
touch: cannot touch `file5': Disk quota exceeded
[tom@ton test]$dd if=/dev/zero of=file4 bs=1M count=20
sda5: warning, user block quota exceeded.
sda5: write failed, user block limit reached.
dd: writing `file4': Disk quota exceeded
16+0 records in
15+0 records out
15728640 bytes (16 MB) copied, 0.0193494 s, 813 MB/s
[tom@ton test]$ls -lah
total 16M
drwxrwxr-x 3 root root 4.0K Mar 11 01:46 .
drwxr-xr-x. 7 root root 4.0K Jul 30 2020 ..
-rw-rwx--- 1 root root 7.0K Mar 11 01:46 aquota.group
-rw-rwx--- 1 root root 7.0K Mar 11 01:25 aquota.user
-rw-rw-r-- 1 tom tom 0 Mar 11 01:46 file1
-rw-rw-r-- 1 tom tom 0 Mar 11 01:46 file2
-rw-rw-r-- 1 tom tom 0 Mar 11 01:46 file3
-rw-rw-r-- 1 tom tom 15M Mar 11 01:47 file4
drwxrwx--- 2 root root 16K Mar 10 19:28 lost+found
[tom@ton test]$
用户tom显示两个++
,表示软硬限制均用超,宽限期还有6天。
[root@ton ~]#repquota -av
*** Report for user quotas on device /dev/sda5
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 20 10000 10000 2 3 0
tom ++ 15360 1024 15360 6days 4 3 4 6days
Statistics:
Total blocks: 7
Data blocks: 1
Entries: 2
Used average: 2.000000
-s
提高可读性 -p
宽限期以秒显示
[root@ton test]#repquota -avsp
*** Report for user quotas on device /dev/sda5
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root +- 51220 10000 10000 1647558809 3 3 0 0
tom ++ 15360 1024 15360 1647558780 4 3 4 1647558766
Statistics:
Total blocks: 7
Data blocks: 1
Entries: 2
Used average: 2.000000