本文将介绍XFS文件系统上的用户配额限制。
本文档介绍如在xfs文件系统上对用户进行quota限制。
如果还没有火山引擎账号,点击此链接注册账号
如果还没有云服务器,创建云服务器,参考链接。
$ apt-get update $ apt-get install xfsprogs
fdisk -l /dev/vdb Disk /dev/vdb: 20 GiB, 21474836480 bytes, 41943040 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes
$ mkfs.xfs -f /dev/vdb
$ mkdir /data $ mount -o usrquota /dev/vdb /data $ mount|grep data /dev/vdb on /data type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,usrquota)
$ xfs_quota -xc 'state -gpu' User quota state on /data (/dev/vdb) Accounting: ON # 已经开启 Enforcement: ON # 已经开启 Inode: #131 (1 blocks, 1 extents) Blocks grace time: [7 days] Blocks max warnings: 5 Inodes grace time: [7 days] Inodes max warnings: 5 Realtime Blocks grace time: [7 days] Group quota state on /data (/dev/vdb) Accounting: OFF Enforcement: OFF Inode: N/A Blocks grace time: [--------] Blocks max warnings: 0 Inodes grace time: [--------] Inodes max warnings: 0 Realtime Blocks grace time: [--------] Project quota state on /data (/dev/vdb) Accounting: OFF Enforcement: OFF Inode: N/A Blocks grace time: [--------] Blocks max warnings: 0 Inodes grace time: [--------] Inodes max warnings: 0 Realtime Blocks grace time: [--------]
$ useradd quota-test $ echo "quota-test:password" | chpasswd
$ xfs_quota -xc 'limit -u bsoft=300M bhard=500M quota-test' /data/
$ xfs_quota -xc 'report -ugphbir' /data User quota on /data (/dev/vdb) Blocks Inodes Realtime Blocks User ID Used Soft Hard Warn/Grace Used Soft Hard Warn/Grace Used Soft Hard Warn/Grace ---------- --------------------------------- --------------------------------- --------------------------------- root 0 0 0 00 [------] 3 0 0 00 [------] 0 0 0 00 [------] quota-test 0 300M 500M 00 [------] 0 0 0 00 [------] 0 0 0 00 [------]
$ chmod 777 /data
$ su - quota1 dd if=/dev/zero of=/data/quota1.txt bs=1M count=200 200+0 records in 200+0 records out 209715200 bytes (210 MB, 200 MiB) copied, 0.0727318 s, 2.9 GB/s $ ls -lh /data/ total 200M -rw-rw-r-- 1 quota-test quota-test 200M Feb 26 16:05 quota1.txt
$ dd if=/dev/zero of=/data/quota2.txt bs=1M count=200 200+0 records in 200+0 records out 209715200 bytes (210 MB, 200 MiB) copied, 0.0738258 s, 2.8 GB/s $ ls -lh /data/ total 400M -rw-rw-r-- 1 quota-test quota-test 200M Feb 26 16:05 quota1.txt -rw-rw-r-- 1 quota-test quota-test 200M Feb 26 16:07 quota2.txt
$ dd if=/dev/zero of=/data/quota3.txt bs=1M count=150 dd: error writing '/data/quota3.txt': Disk quota exceeded 101+0 records in 100+0 records out 104857600 bytes (105 MB, 100 MiB) copied, 0.0370117 s, 2.8 GB/s $ ls -lh /data/ total 500M -rw-rw-r-- 1 quota-test quota-test 200M Feb 26 16:05 quota1.txt -rw-rw-r-- 1 quota-test quota-test 200M Feb 26 16:07 quota2.txt -rw-rw-r-- 1 quota-test quota-test 100M Feb 26 16:10 quota3.txt
$ root@iv-yc9exq1dl338df7pjgs8:~# xfs_quota -xc 'report -ugphbir' /data User quota on /data (/dev/vdb) Blocks Inodes Realtime Blocks User ID Used Soft Hard Warn/Grace Used Soft Hard Warn/Grace Used Soft Hard Warn/Grace ---------- --------------------------------- --------------------------------- --------------------------------- root 0 0 0 00 [------] 3 0 0 00 [------] 0 0 0 00 [------] quota-test 500M 300M 500M 00 [6 days] 3 0 0 00 [------] 0 0 0 00 [------]
https://manpages.ubuntu.com/manpages/jammy/man8/xfs_quota.8.html