当前位置:首页>Linux>1.17 Linux系统-磁盘配额

1.17 Linux系统-磁盘配额

  • 2026-09-08 16:17:52
1.17 Linux系统-磁盘配额

磁盘配额(六版本)

一、quota磁盘配额      #多用户使用

#限制usr、grp的 容量、   数量      block   inode
操作系统:磁盘:1分区下的:block:占用空间。inode:文件数量。查看quota是否安装:rpm  -qa   |grep   quota

查看内核是否支持:

基本概念:

软限制(soft)(小):超出限制仍然能使用,会提示,超过宽限天数则会锁住硬限制(hard)(大):不能超过限制,超出则锁住,不能使用宽限天数(grace):超过软限制则启用,默认7天
步骤:分区、格式化、挂载
## 挂载:     1)临时挂载:  mount  分区 挂载点                    mount    -o   remount,usrquota,grpquota  挂载点       永久挂载:        UUID   挂载点     文件系统     defaults,usrquota,grpquota  0  0    2)关闭SElinux        getenforce   #查看selinux状态        setenforce  0  #临时关闭selinux        永久关闭selinux :#永久关闭selinux,改完配置文件需要重启后才生效                /etc/selinux/config   #SElinux的配置文件                    SELINUX=disable  #选项    3)quotacheck  #查看          1、quota  -avug  #生成quota配置        2、 edquota  -u   用户  #设置用户配额            edquota  -g   组  #设置组配额            edquota  -t    #修改宽限天数    edquota  -p   用户1    -u    用户2 #复制用户1的配额到用户2        3、设置挂载点权限,使其他用户能使用  chmod        4、 quotaon  -avug  #quota启用            quotaoff  -avug  #quota停用
查所有使用情况:

repquota      [选项]      分区

选项:      -a  #所有    -u  #用户    -g  #组    -v  #显示详细    -s  #常见单位显示
创建指定大小文件
$ dd   if=/dev/zero   of=/disk1/cc1    bs=1M   count=200    数据来源      数据去向      单次大小 索取次数
组设置quota,设置SGID,使子目录、子文件的所属组仍为父目录的所属组
1)chmod g+s  目录         #给目录设置SGID2)chown 所有者:所属组 目录        #设置目录的所有者、所属组3)edquota  -g  组名 目录     #设置组磁盘配额,给目录4)quotaoff  -avug &&  quotaon -avug  #重新启用quota5)组内其他成员,创建文件再测试  repquota   -gvs 

磁盘配额(七版本)

非交互式:执行后仍需键盘后续输入交互式:执行后不需要后续键盘输入查内核是否支持磁盘配额:  # [root@localhost ~]# grep CONFIG_QUOTA /boot/config-3.10.0-1160.el7.x86_64 CONFIG_QUOTA=yCONFIG_QUOTA_NETLINK_INTERFACE=y# CONFIG_QUOTA_DEBUG is not setCONFIG_QUOTA_TREE=yCONFIG_QUOTACTL=yCONFIG_QUOTACTL_COMPAT=y

步骤:

1、分区
[root@localhost ~]# fdisk /dev/sdb
2、格式化
[root@localhost ~]# mkfs.xfs /dev/sdb1
3、挂载:
[root@localhost ~]# mkdir /disk1## 临时挂载     mount  -o   特殊选项        设备文件   挂载点[root@localhost ~]# mount  -o   usrquota,grpquota,prjquota   /dev/sdb1    /disk1## 永久挂载UUID 挂载点   文件系统    defaults,usrquota,grpquota,prjquota  0 0[root@localhost ~]# blkid /dev/sdb1 |awk '{print $2}' | sed s/\"//g | awk '{print $1 "  /disk1   defaults,usrquota,grpquota,prjquota  0 0"}' >> /etc/fstab [root@localhost ~]# tail -n1 /etc/fstabUUID=b8d9fd16-6288-4660-b1da-dfae67e163ad  /disk1   defaults,usrquota,grpquota,prjquota  0 0
4、非交互式创建磁盘配额
(1) xfs_quota 命令
## xfs_quota -x  -c  “命令” # xfs_quota -x -c "print"#查看当前挂载情况[root@localhost ~]# xfs_quota -x -c "print"Filesystem          Pathname/                   /dev/sda3/boot               /dev/sda1/disk1              /dev/sdb1 (uquota, gquota, pquota)
# xfs_quota -x -c "df -h"#查看大小[root@localhost ~]# xfs_quota -x -c "df -h"Filesystem     Size   Used  Avail Use% Pathname/dev/sda3     37.0G   1.5G  35.4G   4% //dev/sda1     1014M 141.6M 872.4M  14% /boot/dev/sdb1     10.0G  32.2M  10.0G   0% /disk1Filesystem     Size   Used  Avail Use% Pathname/dev/sda3     37.0G   1.5G  35.4G   4% //dev/sda1     1014M 141.6M 872.4M  14% /boot/dev/sdb1     10.0G  32.2M  10.0G   0% /disk1Filesystem     Size   Used  Avail Use% Pathname/dev/sda3     37.0G   1.5G  35.4G   4% //dev/sda1     1014M 141.6M 872.4M  14% /boot/dev/sdb1     10.0G  32.2M  10.0G   0% /disk1
# xfs_quota -x -c "report  -选项 "  挂载点[root@localhost ~]# xfs_quota -x -c "report" /disk1/User quota on /disk1 (/dev/sdb1)                               Blocks                     User ID          Used       Soft       Hard    Warn/Grace     ---------- -------------------------------------------------- root                0          0          0     00 [--------]Group quota on /disk1 (/dev/sdb1)                               Blocks                     Group ID         Used       Soft       Hard    Warn/Grace     ---------- -------------------------------------------------- root                0          0          0     00 [--------]Project quota on /disk1 (/dev/sdb1)                               Blocks                     Project ID       Used       Soft       Hard    Warn/Grace     ---------- -------------------------------------------------- #0                  0          0          0     00 [--------]选项: -u  #显示用户            [root@localhost ~]# xfs_quota -x -c "report -u" /disk1/            User quota on /disk1 (/dev/sdb1)                                           Blocks                                 User ID          Used       Soft       Hard    Warn/Grace                 ---------- --------------------------------------------------             root                0          0          0     00 [--------]  -g     #显示组            [root@localhost ~]# xfs_quota -x -c "report -g" /disk1/            Group quota on /disk1 (/dev/sdb1)                                           Blocks                                 Group ID         Used       Soft       Hard    Warn/Grace                 ---------- --------------------------------------------------             root                0          0          0     00 [--------] -i  #显示inode            [root@localhost ~]# xfs_quota -x -c "report -i" /disk1/            User quota on /disk1 (/dev/sdb1)                                           Inodes                                 User ID          Used       Soft       Hard    Warn/ Grace                 ---------- --------------------------------------------------             root                3          0          0     00 [--------]            Group quota on /disk1 (/dev/sdb1)                                           Inodes                                 Group ID         Used       Soft       Hard    Warn/ Grace                 ---------- --------------------------------------------------             root                3          0          0     00 [--------]            Project quota on /disk1 (/dev/sdb1)                                           Inodes                                 Project ID       Used       Soft       Hard    Warn/ Grace                 ---------- --------------------------------------------------             #0                  3          0          0     00 [--------] -bh    #显示block            [root@localhost ~]# xfs_quota -x -c "report -bh" /disk1/            User quota on /disk1 (/dev/sdb1)                                    Blocks                          User ID      Used   Soft   Hard Warn/Grace               ---------- ---------------------------------             root            0      0      0  00 [------]            Group quota on /disk1 (/dev/sdb1)                                    Blocks                          Group ID     Used   Soft   Hard Warn/Grace               ---------- ---------------------------------             root            0      0      0  00 [------]            Project quota on /disk1 (/dev/sdb1)                                    Blocks                          Project ID   Used   Soft   Hard Warn/Grace               ---------- ---------------------------------             #0              0      0      0  00 [------]

查三限制是否开启

# xfs_quota   -x   -c     "state"[root@localhost ~]# xfs_quota   -x   -c     "state"User quota state on /disk1 (/dev/sdb1)  Accounting: ON  Enforcement: ON  Inode: #67 (1 blocks, 1 extents)Group quota state on /disk1 (/dev/sdb1)  Accounting: ON  Enforcement: ON  Inode: #68 (1 blocks, 1 extents)Project quota state on /disk1 (/dev/sdb1)  Accounting: ON  Enforcement: ON  Inode: #68 (1 blocks, 1 extents)Blocks grace time: [7 days]Inodes grace time: [7 days]Realtime Blocks grace time: [7 days]
(2)步骤:

1)创建磁盘配额:

格式:  xfs_quota -x  -c  “limit  -u  bsoft=大小   bhard=大小  用户”   挂载点  xfs_quota -x  -c  “limit  -u  isoft=数字   ihard=数字 用户”   挂载点  xfs_quota -x  -c “limit  -g  bsoft=大小      bhard=大小  组”    挂载点[root@localhost ~]# useradd yq1[root@localhost ~]# groupadd gyq[root@localhost ~]# xfs_quota -x -c "limit -u bsoft=300M bhard=500M yq1" /disk1/[root@localhost ~]# xfs_quota -x -c "limit -u isoft=10   ihard=15   yq1" /disk1/[root@localhost ~]# xfs_quota -x -c "limit -g bsoft=600M bhard=1G   gyq" /disk1/[root@localhost ~]# xfs_quota -x -c "limit -g isoft=20   ihard=25   gyq" /disk1/

2)设置权限

[root@localhost ~]# mkdir /disk1/test.d[root@localhost ~]# ls -ld /disk1/drwxr-xr-x 2 root root 6 6月  16 13:21 /disk1/[root@localhost ~]# chown -R yq1:gyq /disk1/[root@localhost ~]# ls -ld /disk1/drwxr-xr-x 2 yq1 gyq 6 6月  16 13:21 /disk1/

3)检查磁盘配额设置

检查: xfs_quota  -x -c “report  -ubih”  挂载点用户    -ubih    [root@localhost ~]# xfs_quota -x -c "report -ubih" /disk1/    User quota on /disk1 (/dev/sdb1)                            Blocks                            Inodes                  User ID      Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace      ---------- --------------------------------- ---------------------------------     root            0      0      0  00 [------]      3      0      0  00 [------]    yq1             0   300M   500M  00 [------]      0     10     15  00 [------]组     -gbih    [root@localhost ~]# xfs_quota -x -c "report -gbih" /disk1/    Group quota on /disk1 (/dev/sdb1)                            Blocks                            Inodes                  Group ID     Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace      ---------- --------------------------------- ---------------------------------     root            0      0      0  00 [------]      3      0      0  00 [------]    gyq             0   600M     1G  00 [------]      0     20     25  00 [------]
(3)设置宽限天数
格式:  xfs_quota   -x  -c  “timer -u -bir  天数”  挂载点[root@localhost ~]# xfs_quota -x -c "timer -u -bir 15days" /disk1/[root@localhost ~]# xfs_quota -x -c "state"User quota state on /disk1 (/dev/sdb1)  Accounting: ON  Enforcement: ON  Inode: #67 (2 blocks, 2 extents)Group quota state on /disk1 (/dev/sdb1)  Accounting: ON  Enforcement: ON  Inode: #68 (2 blocks, 2 extents)Project quota state on /disk1 (/dev/sdb1)  Accounting: ON  Enforcement: ON  Inode: #68 (2 blocks, 2 extents)Blocks grace time: [15 days]Inodes grace time: [15 days]Realtime Blocks grace time: [15 days]
(4)prjquota限制挂载点下子目录

注意:usr、grp、prj 在以前版本不能同时开启

1) 设置prjquota权限需要两个配置文件

>     覆盖式写入>>    追加式写入  echo   “数字标识 : /挂载点/目录”   >>   /etc/projects  echo   “名称 : 数字标识”   >>  /etc/projid[root@localhost ~]# echo "15:/disk1/test.d" >> /etc/projects[root@localhost ~]# cat /etc/projects 15:/disk1/test.d[root@localhost ~]# echo "yqprj:15" >> /etc/projid[root@localhost ~]# cat /etc/projid yqprj:15

2) 初始化prj

[root@localhost ~]# xfs_quota -x -c "project -s yqprj"Setting up project yqprj (path /disk1/test.d)...Processed 1 (/etc/projects and cmdline) paths for project yqprj with recursion depth infinite (-1).Setting up project yqprj (path /disk1/test.d)...Processed 1 (/etc/projects and cmdline) paths for project yqprj with recursion depth infinite (-1).Setting up project yqprj (path /disk1/test.d)...Processed 1 (/etc/projects and cmdline) paths for project yqprj with recursion depth infinite (-1).## 验证[root@localhost ~]# xfs_quota -x -c "print"Filesystem          Pathname/                   /dev/sda3/boot               /dev/sda1/disk1              /dev/sdb1 (uquota, gquota, pquota)/disk1/test.d       /dev/sdb1 (project 15, yqprj)

3) 设置prjquota限制

格式:  xfs_quota  -x  -c  “limit  -p  软限制=  硬限制= 名称”  挂载点[root@localhost ~]# xfs_quota -x -c "limit -p bsoft=300M bhard=500M yqprj" /disk1/[root@localhost ~]# xfs_quota -x -c "limit -p isoft=10   ihard=15   yqprj" /disk1/[root@localhost ~]# [root@localhost ~]# xfs_quota -x -c "report -pbih" /disk1/Project quota on /disk1 (/dev/sdb1)                        Blocks                            Inodes              Project ID   Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  ---------- --------------------------------- --------------------------------- #0              0      0      0  00 [------]      3      0      0  00 [------]yqprj           0   300M   500M  00 [------]      1     10     15  00 [------]
测试:
## block 测试[root@localhost ~]# dd if=/dev/zero of=/disk1/test.d/aa1 bs=1M count=400记录了400+0 的读入记录了400+0 的写出419430400字节(419 MB)已复制,0.153693 秒,2.7 GB/秒[root@localhost ~]# xfs_quota -x -c "report -pbih" /disk1/Project quota on /disk1 (/dev/sdb1)                        Blocks                            Inodes              Project ID   Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  ---------- --------------------------------- --------------------------------- #0              0      0      0  00 [------]      3      0      0  00 [------]yqprj        400M   300M   500M  00 [15 days]      2     10     15  00 [------]## inode测试[root@localhost ~]# touch /disk1/test.d/aa{1..16}touch: 无法创建"/disk1/test.d/aa15": 超出磁盘限额touch: 无法创建"/disk1/test.d/aa16": 超出磁盘限额[root@localhost ~]# ls /disk1/test.d/aa1  aa10  aa11  aa12  aa13  aa14  aa2  aa3  aa4  aa5  aa6  aa7  aa8  aa9[root@localhost ~]# xfs_quota -x -c "report -pbih" /disk1/Project quota on /disk1 (/dev/sdb1)                        Blocks                            Inodes              Project ID   Used   Soft   Hard Warn/Grace     Used   Soft   Hard Warn/Grace  ---------- --------------------------------- --------------------------------- #0              0      0      0  00 [------]      3      0      0  00 [------]yqprj        400M   300M   500M  00 [14 days]     15     10     15  00 [15 days]

最新文章

随机文章