5-磁盘配额


2016.6.13

quota

以支持配额功能等的方式挂载文件系统

 除了内核和quota软件的支持以外,实施磁盘配额功能还有一个前提条件,即指定的分区必须已经挂载且支持磁盘配额功能。

前期的准备:

[root@test1 mail_store]# mount /dev/mail_store/mbox /mailbox/
[root@test1 mail_store]# mount
/dev/mapper/vg_test-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sr0 on /mnt type iso9660 (ro)
/dev/sde1 on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/mapper/mail_store-mbox on /mailbox type ext4 (rw)
[root@test1 mail_store]# df -hT
Filesystem                  Type     Size  Used Avail Use% Mounted on
/dev/mapper/vg_test-lv_root ext4      35G   13G   21G  39% /
tmpfs                       tmpfs    932M     0  932M   0% /dev/shm
/dev/sda1                   ext4     485M   40M  421M   9% /boot
/dev/sr0                    iso9660  4.2G  4.2G     0 100% /mnt
/dev/sde1                   ext4      20G  175M   19G   1% /home
/dev/mapper/mail_store-mbox ext4      25G  172M   24G   1% /mailbox
[root@test1 mail_store]#

支持配额前后的对比:

[root@test1 mail_store]# mount -o remount,usrquota,grpquota /dev/mail_store/mbox /mailbox
[root@test1 mail_store]# mount
/dev/mapper/vg_test-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sr0 on /mnt type iso9660 (ro)
/dev/sde1 on /home type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/mapper/mail_store-mbox on /mailbox type ext4 (rw,usrquota,grpquota)
[root@test1 mail_store]#

检测磁盘配额并生成配额文件

命令:quotacheck

quotacheck

[root@test1 mail_store]# quotacheck -augcv
quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/mapper/mail_store-mbox [/mailbox] done
quotacheck: Cannot stat old user quota file /mailbox/aquota.user: No such file or directory. Usage will not be substracted.
quotacheck: Cannot stat old group quota file /mailbox/aquota.group: No such file or directory. Usage will not be substracted.
quotacheck: Cannot stat old user quota file /mailbox/aquota.user: No such file or directory. Usage will not be substracted.
quotacheck: Cannot stat old group quota file /mailbox/aquota.group: No such file or directory. Usage will not be substracted.
quotacheck: Checked 2 directories and 0 files
quotacheck: Old file not found.
quotacheck: Old file not found.
[root@test1 mail_store]#
  • -a:表示扫描所有分区
  • -u:表示检测用户的配额信息
  • -g:表示检测组配额信息
  • -c:表示创建新的配额文件
  • -v:表示显示命令执行过程中的细节信息

未使用“-a”选项时,必须制定一个分区(设备文件或挂载点目录)作为命令参数。

查看生成的配额文件

[root@test1 mail_store]# ls -l /mailbox/aquota.*
-rw------- 1 root root 6144 Jun 15 09:43 /mailbox/aquota.group
-rw------- 1 root root 6144 Jun 15 09:43 /mailbox/aquota.user
[root@test1 mail_store]#
注意:这里如果无法生成配额文件,有一种可能是selinux没有关闭

编辑用户和组账号的配额设置

命令:edquota

对用户jason的配额进行编辑

[root@test1 mail_store]# edquota -u kylin
edquota: user kylin does not exist.
[root@test1 mail_store]# edquota -u jason

Disk quotas for user jason (uid 502):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/mapper/mail_store-mbox          0          0          0          0        0        0
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"/tmp//EdP.amY0XqE" 3L, 219C
  • Filesystem:表示本行配置记录对应的文件系统(分区),即配额的作用方位
  • blocks:表示用户当前已经使用的磁盘容量,默认单位为KB,该数值由edquota程序自动计算,无需修改
  • inodes:表示用户当前已经拥有的文件数量(即占用i节点的个数),该数值也是由edquota程序自动计算的
  • soft:第三列中的soft对应为磁盘容量的软限制数值,默认单位为KB;第六列中的soft对应为文件数量的软限制数值,默认单位为个。
  • hard:第4列中的hard对应为磁盘容量的硬限制数值,默认单位为KB;第7列中的hard对应为文件数量的硬限制数值,默认单位为个


在/dev/mapper/mail_store-mbox中给jason分配配额:

[root@test1 mail_store]# edquota -u jason

Disk quotas for user jason (uid 502):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/mapper/mail_store-mbox          0    80000       100000     0       40        50
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
:wq

从/dev/mapper/mail_store-mbox中给users 组分配配额:

[root@test1 mail_store]# edquota -g users

Disk quotas for group users (gid 100):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/mapper/mail_store-mbox     252          0       10240000     39        0        0
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
:wq

给users分配出现问题:

[root@test1 mail_store]# edquota -g users
edquota: WARNING - /dev/mapper/mail_store-mbox: cannot change current block allocation
edquota: WARNING - /dev/mapper/mail_store-mbox: cannot change current inode allocation
[root@test1 mail_store]# chmod 777 /mailbox/
[root@test1 mail_store]# edquota -g users
edquota: WARNING - /dev/mapper/mail_store-mbox: cannot change current block allocation
edquota: WARNING - /dev/mapper/mail_store-mbox: cannot change current inode allocation
[root@test1 mail_store]#

修改宽限期:

[root@test1 ~]# edquota -t

Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
  Filesystem             Block grace period     Inode grace period
  /dev/mapper/mail_store-mbox                  3days                  3days
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
:wq

启动文件系统的磁盘配额功能

命令:quotaon

启动/mailbox:

[root@test1 ~]# quotaon -ugv /mailbox/
/dev/mapper/mail_store-mbox [/mailbox]: group quotas turned on
/dev/mapper/mail_store-mbox [/mailbox]: user quotas turned on
[root@test1 ~]#

验证磁盘配额功能

[root@test1 ~]# dd if=/dev/zero of=/mailbox/ddtest.data bs=1M count=4
4+0 records in
4+0 records out
4194304 bytes (4.2 MB) copied, 0.00362501 s, 1.2 GB/s
[root@test1 ~]# ls -lh /mailbox/ddtest.data
-rw-r--r-- 1 root root 4.0M Jun 15 10:05 /mailbox/ddtest.data
[root@test1 ~]#

以jason用户来进行测试:

[jason@test1 root]$ cd /mailbox/
[jason@test1 mailbox]$ dd if=/dev/zero of=myfile bs =1M count=60
dd: unrecognized operand `bs'
Try `dd --help' for more information.
[jason@test1 mailbox]$ dd if=/dev/zero of=myfile bs=1M count=60
60+0 records in
60+0 records out
62914560 bytes (63 MB) copied, 0.184167 s, 342 MB/s
[jason@test1 mailbox]$ ls -lh myfile
-rw-rw-r-- 1 jason jason 60M Jun 15 10:08 myfile
[jason@test1 mailbox]$ dd if=/dev/zero of=myfile bs=1M count=90
dm-2: warning, user block quota exceeded.
90+0 records in
90+0 records out
94371840 bytes (94 MB) copied, 0.236257 s, 399 MB/s
[jason@test1 mailbox]$ ls -lh myfile
-rw-rw-r-- 1 jason jason 90M Jun 15 10:09 myfile
[jason@test1 mailbox]$ dd if=/dev/zero of=myfile bs=1M count=120
dm-2: warning, user block quota exceeded.
dm-2: write failed, user block limit reached.
dd: writing `myfile': Disk quota exceeded
98+0 records in
97+0 records out
102400000 bytes (102 MB) copied, 0.173761 s, 589 MB/s
[jason@test1 mailbox]$ ls -lh myfile
-rw-rw-r-- 1 jason jason 98M Jun 15 10:09 myfile
[jason@test1 mailbox]$

查看用户或分区的配额使用情况

[jason@test1 mailbox]$ quota -u jason
Disk quotas for user jason (uid 502):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
/dev/mapper/mail_store-mbox
                 100000*  80000  100000   2days       1      40      50
[jason@test1 mailbox]$ quota -g users
quota: users (gid 100): Permission denied
[jason@test1 mailbox]$ su
Password:
[root@test1 mailbox]# quota -g users
Disk quotas for group users (gid 100): none
[root@test1 mailbox]#

repquota 可以直接查看/mailbox文件系统的配额使用情况。

[root@test1 mailbox]# repquota /mailbox/
*** Report for user quotas on device /dev/mapper/mail_store-mbox
Block grace time: 3days; Inode grace time: 3days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --    4116       0       0              3     0     0
jason     +-  100000   80000  100000  2days       1    40    50

[root@test1 mailbox]#

results matching ""

    No results matching ""