首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >xfs文件系统xfs_quota配额设置(1)- 配置步骤及说明

xfs文件系统xfs_quota配额设置(1)- 配置步骤及说明

原创
作者头像
skystone
发布2025-11-20 16:56:08
发布2025-11-20 16:56:08
90
举报

xfs文件系统xfs_quota配额设置(1)- 配置步骤及说明

1. 开启或者关闭配额控制

通过在挂载(mount)xfs文件系统时,指定挂载参数来控制开启或关闭配额管理特性。默认是关闭的。

例如,开启project配额,则

挂载命令如下。

代码语言:shell
复制
mount -o prjquota /dev/sdb1 /datb

如果使用/etc/fstab, 那么配置文件中的写法如下。

代码语言:shell
复制
/dev/sdb1 /datb                       xfs     defaults,prjquota        0 0

挂载时如果没有指定配额控制参数,那么在执行xfs_quota命令对目录进行limit时,会提示“函数未实现”的告警。

代码语言:shell
复制
xfs_quota: cannot set limits: 函数未实现

配额相关的参数如下:

noquota

Forcibly turns off all quota accounting and enforcement within the filesystem.

强制关闭文件系统中的所有配额计数和限制。

uquota/usrquota/uqnoenforce/quota

User disk quota accounting enabled, and limits (optionally) enforced.

开启用户磁盘配额计数,是否强制限制是可选的,默认限制。

gquota/grpquota/gqnoenforce

Group disk quota accounting enabled and limits (optionally) enforced.

开启用户组磁盘配额计数,是否强制限制是可选的,默认限制。

pquota/prjquota/pqnoenforce

Project disk quota accounting enabled and limits (optionally) enforced.

开启项目磁盘配额计数,是否强制限制是可选的,默认限制。

日常我们主要使用project方式,针对目录进行空间配置限制。

2. 磁盘空间配额设置

2.1. xfs_quota命令说明

格式:xfs_quota -x -c cmd ... -d project ... path ...

日常就用2个选项,-x, 专家模式,能修改; -c 后面跟指令字符串,就是具体配额配置指令。-p和-d不用。path是分区挂载路径,不是具体目录。

主要使用limit指令,

针对user, group, project分别使用-u, -g, -p 3个参数。

针对使用空间大小限制、inode数量限制、realtime block限制,分别使用bsoft/bhard, isoft/ihard, rtbsoft/rtbhard 3组参数。

id为project id,name为user/group/project name。

代码语言:shell
复制
limit [ -g | -p | -u ] bsoft=N | bhard=N | isoft=N | ihard=N | rtbsoft=N | rtbhard=N -d | id | name

manual手册对此指令的解释如下:

代码语言:shell
复制
Set  quota  block  limits (bhard/bsoft), inode count limits (ihard/isoft) and/or realtime block limits (rtbhard/rtbsoft). The -d option (defaults) can be used to set the default value that will be used, otherwise a specific user/group/project name or numeric identifier must be specified.

在同时使用soft和hard进行限制时,还有一个timer宽限期的设置命令。

代码语言:shell
复制
timer [ -g | -p | -u ] [ -bir ] value

manual手册对此指令的解释如下:

代码语言:shell
复制
Allows the quota enforcement timeout (i.e. the amount of time allowed to pass before the soft limits are enforced as the hard limits) to be modified. The   current timeout setting can be displayed using the state command. The value argument is a number of seconds, but units of 'minutes', 'hours', 'days', and    'weeks' are also understood (as are their abbreviations 'm', 'h', 'd', and 'w').

为了简化配额管理,尽量不要使用soft和timer,只使用hard限制即可。

2.2. 配额配置及场景

(1) 对目录进行配额限制。

常用于配合nfs服务器为不同目录设置磁盘空间限制。

需要采用project配额方式。

代码语言:shell
复制
    # mount -o prjquota /dev/xvm/var /var
    # xfs_quota -x -c 'project -s -p /var/log 42' /var
    # xfs_quota -x -c 'limit -p bhard=1g 42' /var

另一种方式,是在配置文件中定义好path, name和id关系,

代码语言:shell
复制
    /etc/projects       Mapping of numeric project identifiers to directories trees.
    /etc/projid         Mapping of numeric project identifiers to project names.

然后再执行配额管理命令。

代码语言:shell
复制
    # mount -o prjquota /dev/xvm/var /var
    # echo 42:/var/log >> /etc/projects
    # echo logfiles:42 >> /etc/projid
    # xfs_quota -x -c 'project -s logfiles' /var
    # xfs_quota -x -c 'limit -p bhard=1g logfiles' /var       

实际使用中,如果配额条目较少,可以不需要本地配置文件。

(2) 用户配额

代码语言:shell
复制
    # mount -o uquota /dev/xvm/home /home
    # xfs_quota -x -c 'limit -u bsoft=500m bhard=550m tanya' /home

(3) 组配额

代码语言:shell
复制
    # mount -o gquota /dev/xvm/home /home
    # xfs_quota -x -c 'limit -g bsoft=500m bhard=550m tanya' /home

配置完成后,可以查看相关配额配置情况。

(4) 查看当前分区配额设置情况

print, quota, report, state 4个命令。

代码语言:shell
复制
    # xfs_quota -x -c 'print ' /dev/sdb1
    Filesystem          Pathname
    /datb               /dev/sdb1 (pquota)
    # xfs_quota -x -c 'report -p ' /dev/sdb1
    Project quota on /datb (/dev/sdb1)
                                Blocks                     
    Project ID       Used       Soft       Hard    Warn/Grace     
    ---------- -------------------------------------------------- 
    #0                  0          0          0     00 [--------]
    #65        1011133980          0 1073741824     00 [--------]
    #70        5707854544          0 6442450944     00 [--------]
    #75          10603812          0 1073741824     00 [--------]

    # xfs_quota -x -c 'report ' /dev/sdb1
    Project quota on /datb (/dev/sdb1)
                                Blocks                     
    Project ID       Used       Soft       Hard    Warn/Grace     
    ---------- -------------------------------------------------- 
    #0                  0          0          0     00 [--------]
    #65        1011133980          0 1073741824     00 [--------]
    #70        5707854544          0 6442450944     00 [--------]
    #75          10603812          0 1073741824     00 [--------]

    # xfs_quota -x -c 'quota ' /dev/sdb1
    # xfs_quota -x -c 'quota -p ' /dev/sdb1
    xfs_quota: must specify a project name/ID
    # xfs_quota -x -c 'quota -p 65' /dev/sdb1
    Disk quotas for Project #65 (65)
    Filesystem              Blocks      Quota      Limit  Warn/Time      Mounted on
    /dev/sdb1           1011133980          0 1073741824   00 [--------] /datb
    # xfs_quota -x -c 'state' /dev/sdb1
    User quota state on /datb (/dev/sdb1)
    Accounting: OFF
    Enforcement: OFF
    Inode: #0 (0 blocks, 0 extents)
    Group quota state on /datb (/dev/sdb1)
    Accounting: OFF
    Enforcement: OFF
    Inode: #1027 (2 blocks, 2 extents)
    Project quota state on /datb (/dev/sdb1)
    Accounting: ON
    Enforcement: ON
    Inode: #1027 (2 blocks, 2 extents)
    Blocks grace time: [7 days]
    Inodes grace time: [7 days]
    Realtime Blocks grace time: [7 days]

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • xfs文件系统xfs_quota配额设置(1)- 配置步骤及说明
    • 1. 开启或者关闭配额控制
    • 2. 磁盘空间配额设置
      • 2.1. xfs_quota命令说明
      • 2.2. 配额配置及场景
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档