xfs quota功能

group quota 无法跟project quota同时生效
grace time:当超过了soft限额,grace时间启用倒计时,倒计时到期后soft 限额变为hard限额

  • 创建一个xfs文件系统
# dd if=/dev/zero of=/tmp/quota bs=1G count=5
# ll -h /tmp/quota 
-rw-r--r--. 1 root root 5.0G Mar 22 18:41 /tmp/quota

# mkfs.xfs /tmp/quota 
meta-data=/tmp/quota             isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

# mkdir /home/quota
  • 创建组及用户名密码
# groupadd myquotagrp
# useradd -g myquotagrp myquota1
# useradd -g myquotagrp myquota2
# useradd -g myquotagrp myquota3
# useradd -g myquotagrp myquota4
# useradd -g myquotagrp myquota5
# echo "password" | passwd --stdin myquota1
# echo "password" | passwd --stdin myquota2
# echo "password" | passwd --stdin myquota3
# echo "password" | passwd --stdin myquota4
# echo "password" | passwd --stdin myquota5
  • 挂载启用usrquota,grpquota的文件系统
# mount -o loop,usrquota,grpquota /tmp/quota /home/quota/ 
# mount | grep quota
/dev/mapper/centos-root on / type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
/tmp/quota on /home/quota type xfs (rw,relatime,seclabel,attr2,inode64,usrquota,grpquota)
  • 确定quota文件系统空间
# df -hT /home/quota/
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/loop0     xfs   5.0G   33M  5.0G   1% /home/quota
  • 查看quota文件系统状态
# xfs_quota -x -c "print"
Filesystem          Pathname
/                   /dev/mapper/centos-root
/boot               /dev/sda1
/home/quota         /dev/loop0 (uquota, gquota)

# xfs_quota -x -c "df -h" /home/quota/
Filesystem     Size   Used  Avail Use% Pathname
/dev/loop0     5.0G  32.2M   5.0G   1% /home/quota

# xfs_quota -x -c "report -ubih" /home/quota/
User quota on /home/quota (/dev/loop0)
                        Blocks                            Inodes              
User ID      Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
root            0      0      0  00 [------]      3      0      0  00 [------]


# xfs_quota -x -c "state"
User quota state on /home/quota (/dev/loop0)
  Accounting: ON
  Enforcement: ON
  Inode: #67 (1 blocks, 1 extents)
Group quota state on /home/quota (/dev/loop0)
  Accounting: ON
  Enforcement: ON
  Inode: #68 (1 blocks, 1 extents)
Project quota state on /home/quota (/dev/loop0)
  Accounting: OFF
  Enforcement: OFF
  Inode: #68 (1 blocks, 1 extents)
Blocks grace time: [7 days]
Inodes grace time: [7 days]
Realtime Blocks grace time: [7 days]
  • 对五个用户名启用quota
# xfs_quota -x -c "limit -u bsoft=250M bhard=300M myquota1" /home/quota/
# xfs_quota -x -c "limit -u bsoft=250M bhard=300M myquota2" /home/quota/
# xfs_quota -x -c "limit -u bsoft=250M bhard=300M myquota3" /home/quota/
# xfs_quota -x -c "limit -u bsoft=250M bhard=300M myquota4" /home/quota/
# xfs_quota -x -c "limit -u bsoft=250M bhard=300M myquota5" /home/quota/
  • 查看quota状态
# xfs_quota -x -c "report -ubih" /home/quota/
User quota on /home/quota (/dev/loop0)
                        Blocks                            Inodes              
User ID      Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
root            0      0      0  00 [------]      3      0      0  00 [------]
myquota1        0   250M   300M  00 [------]      0      0      0  00 [------]
myquota2        0   250M   300M  00 [------]      0      0      0  00 [------]
myquota3        0   250M   300M  00 [------]      0      0      0  00 [------]
myquota4        0   250M   300M  00 [------]      0      0      0  00 [------]
myquota5        0   250M   300M  00 [------]      0      0      0  00 [------]
  • 对group启用quota
# xfs_quota -x -c "limit -g bsoft=950M bhard=1G myquotagrp" /home/quota/

# xfs_quota -x -c "report -gbih" /home/quota/
Group quota on /home/quota (/dev/loop0)
                        Blocks                            Inodes              
Group ID     Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
root            0      0      0  00 [------]      3      0      0  00 [------]
myquotagrp      0   950M     1G  00 [------]      0      0      0  00 [------]
  • 修改grace timer
# xfs_quota -x -c "timer -b -u 14days" /home/quota/
# xfs_quota -x -c "timer -b -g 14days" /home/quota/

# xfs_quota -x -c "state"
User quota state on /home/quota (/dev/loop0)
  Accounting: ON
  Enforcement: ON
  Inode: #67 (2 blocks, 2 extents)
Group quota state on /home/quota (/dev/loop0)
  Accounting: ON
  Enforcement: ON
  Inode: #68 (2 blocks, 2 extents)
Project quota state on /home/quota (/dev/loop0)
  Accounting: OFF
  Enforcement: OFF
  Inode: #68 (2 blocks, 2 extents)
Blocks grace time: [14 days]
Inodes grace time: [7 days]
Realtime Blocks grace time: [7 days]
  • 测试quota
# su - myquota1
Last login: Sun Mar 22 19:23:16 CST 2020 on pts/0
$ dd if=/dev/zero of=/home/quota/123.img bs=1M count=299
299+0 records in
299+0 records out
313524224 bytes (314 MB) copied, 0.593406 s, 528 MB/s

# xfs_quota -x -c "report -ubh" /home/quota/
User quota on /home/quota (/dev/loop0)
                        Blocks              
User ID      Used   Soft   Hard Warn/Grace   
---------- --------------------------------- 
root            0      0      0  00 [0 days]
myquota1     299M   250M   300M  00 [13 days]
myquota2        0   250M   300M  00 [------]
myquota3        0   250M   300M  00 [------]
myquota4        0   250M   300M  00 [------]
myquota5        0   250M   300M  00 [------]

$ dd if=/dev/zero of=/home/quota/123.img bs=1M count=310
dd: error writing ‘/home/quota/123.img’: Disk quota exceeded
301+0 records in
300+0 records out
314572800 bytes (315 MB) copied, 0.199085 s, 1.6 GB/s

配置project quota:
环境准备:

# umount -f /home/quota/
# mount | grep home
# mount -o loop,usrquota,prjquota /tmp/quota /home/quota/
# mount | grep home
/tmp/quota on /home/quota type xfs (rw,relatime,seclabel,attr2,inode64,usrquota,prjquota)

# xfs_quota -x -c "state"
User quota state on /home/quota (/dev/loop0)
  Accounting: ON
  Enforcement: ON
  Inode: #67 (2 blocks, 2 extents)
Group quota state on /home/quota (/dev/loop0)
  Accounting: OFF
  Enforcement: OFF
  Inode: #68 (2 blocks, 2 extents)
Project quota state on /home/quota (/dev/loop0)
  Accounting: ON
  Enforcement: ON
  Inode: #68 (2 blocks, 2 extents)
Blocks grace time: [14 days]
Inodes grace time: [7 days]
Realtime Blocks grace time: [7 days]
  • 指定项目目标识符的对应在/etc/projects
# echo "11:/home/quota" >> /etc/projects
  • 指定规范名称与标识符的对应在 /etc/projid
# echo "myquotaproject:11" >> /etc/projid
  • 初始化专案名称
# xfs_quota -x -c "project -s myquotaproject"
Setting up project myquotaproject (path /home/quota)...
Processed 1 (/etc/projects and cmdline) paths for project myquotaproject with recursion depth infinite (-1).
Setting up project myquotaproject (path /home/quota)...
Processed 1 (/etc/projects and cmdline) paths for project myquotaproject with recursion depth infinite (-1).
Setting up project myquotaproject (path /home/quota)...
Processed 1 (/etc/projects and cmdline) paths for project myquotaproject with recursion depth infinite (-1).

# xfs_quota -x -c "print" /home/quota/
Filesystem          Pathname
/home/quota         /dev/loop0 (uquota, pquota)
/home/quota         /dev/loop0 (project 11, myquotaproject)

# xfs_quota -x -c "report -pbih " /home/quota/
Project quota on /home/quota (/dev/loop0)
                        Blocks                            Inodes              
Project ID   Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
#0              0      0      0  00 [------]      2      0      0  00 [------]
myquotaproject   300M      0      0  00 [------]      2      0      0  00 [------]
  • 限制projectquota
# xfs_quota -x -c "limit -p bsoft=450M bhard=500M myquotaproject" /home/quota/
[root@localhost ~]# xfs_quota -x -c "report -pbih " /home/quota/
Project quota on /home/quota (/dev/loop0)
                        Blocks                            Inodes              
Project ID   Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
#0              0      0      0  00 [------]      2      0      0  00 [------]
myquotaproject   300M   450M   500M  00 [------]      2      0      0  00 [------]
  • 测试已经生效
$ dd if=/dev/zero of=/home/quota/1234.img bs=1M count=310
dd: error writing ‘/home/quota/1234.img’: No space left on device
201+0 records in
200+0 records out
209715200 bytes (210 MB) copied, 1.07474 s, 195 MB/s
# xfs_quota -x -c "report -pbih " /home/quota/
Project quota on /home/quota (/dev/loop0)
                        Blocks                            Inodes              
Project ID   Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  
---------- --------------------------------- --------------------------------- 
#0              0      0      0  00 [------]      2      0      0  00 [------]
myquotaproject   460M   450M   500M  00 [14 days]      4      0      0  00 [------]
  • 暂时关闭xfs文件系统quota功能
# xfs_quota -x -c "disable -up" /home/quota/
# xfs_quota -x -c "state " /home/quota/
User quota state on /home/quota (/dev/loop0)
  Accounting: ON
  Enforcement: OFF
  Inode: #67 (2 blocks, 2 extents)
Group quota state on /home/quota (/dev/loop0)
  Accounting: OFF
  Enforcement: OFF
  Inode: #68 (2 blocks, 2 extents)
Project quota state on /home/quota (/dev/loop0)
  Accounting: ON
  Enforcement: OFF
  Inode: #68 (2 blocks, 2 extents)
Blocks grace time: [14 days]
Inodes grace time: [7 days]
Realtime Blocks grace time: [7 days]
  • 打开xfs quota功能
# xfs_quota -x -c "enable -up" /home/quota/
# xfs_quota -x -c "state " /home/quota/
User quota state on /home/quota (/dev/loop0)
  Accounting: ON
  Enforcement: ON
  Inode: #67 (2 blocks, 2 extents)
Group quota state on /home/quota (/dev/loop0)
  Accounting: OFF
  Enforcement: OFF
  Inode: #68 (2 blocks, 2 extents)
Project quota state on /home/quota (/dev/loop0)
  Accounting: ON
  Enforcement: ON
  Inode: #68 (2 blocks, 2 extents)
Blocks grace time: [14 days]
Inodes grace time: [7 days]
Realtime Blocks grace time: [7 days]
  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值