1、文件系统支持
quota是针对整个文件系统来进行规划,所以我们得先查一下/home是否是个独立的文件系统。
[root@Monitor home]# df -h /home
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 40G .9G 32G % /
[root@Monitor home]#
由于我的测试机系统的/home不是独立的文件系统,所以只能拿 / 来做试验了,不过强烈建议不要在正式服务器上的 / 做quota
[root@Monitor ~]# mount -o remount,usrquota,grpquota /
[root@Monitor ~]# mount
/dev/xvda1 on / type ext4 (rw,barrier=,usrquota,grpquota)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=,mode=)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
none on /proc/xen type xenfs (rw)
[root@Monitor ~]#
不过手动挂载的数据在下次重新挂载就会消失,因此最好写入配置文件中。
2、新建quota配置文件
quotacheck:扫描文件系统并新建quota的配置文件
-a:扫描所以在/etc/mtab 内,含有quota支持的文件系统
-u:针对用户扫描文件与目录的使用情况,会新建aquota.user
-g:针对用户组扫描与目录的使用情况,会新建aquota.group
-v:显示扫描过程的信息
-f:强制扫描文件系统,并写入新的quota配置文件(危险)
-M:强制以读写的方式扫描文件系统,只有在特殊情况下才会使用
[root@Monitor ~]# quotacheck -avug
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: Quota for users is enabled on mountpoint / so quotacheck might damage the file.
Please turn quotas off or use -f to force checking.
由于我在写这篇博客前已经在这台测试机上做过quota,所以报错,只能加-f强制扫描了
[root@Monitor ~]# quotacheck -avug -mf
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/xvda1 [/] done
quotacheck: Checked directories and files
[root@Monitor ~]#
这样配置文件就创建起来了!
3、quota启动、关闭与限制值设置
quotaon:启动quota服务
-u:针对用户启动quota(aquota.user)
-g:针对用户组启动quota(aquota.group)
-v:显示启动过程的相关信息
-a:根据/etc/mtab内的文件系统设置启动有关quota,若不加-a的话,则后面就需要加上特定的那个文件系统
启动quota
[root@Monitor ~]# quotaon -avug
/dev/xvda1 [/]: group quotas turned on
/dev/xvda1 [/]: user quotas turned on
(quotaoff:关闭quota服务,参数和quotaon相同)
edquota:编辑账号/用户组的限值与宽限时间
-u:后面接账号名称。可以今日quota的编辑界面(vi)去设置username的限制值。
-g:后面接组名。可以进入quota的编辑界面(vi)去设置groupname的限制值,
-t:可以修改宽限时间。
-p:复制范本。那个“模板账号”为已经存在并且已设置好quota的用户,意义为将“范本账号”这个人的quota限制值复制给新账号! edquota -p 范本账号 -u 新账号
设置“liu”这个用户的quota限制值
[root@Monitor ~]# edquota -u liu
Disk quotas for user liu (uid ):
Filesystem blocks soft hard inodes soft hard
/dev/xvda1 8000 10000
然后将宽限时间改成14天
[root@Monitor ~]# edquota -tGrace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
Filesystem Block grace period Inode grace period
/dev/xvda1 14days 7days
4、quota限制值的报表
-g 列出群组的磁盘空间限制。
-q 简明列表,只列出超过限制的部分。
-u 列出用户的磁盘空间限制。
-v 显示该用户或群组,在所有挂入系统的存储设备的空间限制。
-V 显示版本信息。
-s 使用1024为倍数来指定单位,会显示如M之类的单位
[root@Monitor ~]# quota -uvs liu
Disk quotas for user liu (uid ):
Filesystem blocks quota limit grace files quota limit grace
/dev/xvda1 * 6days
[root@Monitor ~]#
repquota:针对文件系统的限制额做报表,参数和quota相同
5、测试与管理
利用“liu”的身份创建一个9M的文件,并查看quota结果
liu@Monitor home]$ dd if=/dev/zero of=/home/liu/text count=1M bs=9
xvda1: warning, user block quota exceeded.
xvda1: write failed, user block limit reached.
dd: writing `/home/liu/text': Disk quota exceeded
1024456+0 records in
1024455+0 records out
9220096 bytes (9.2 MB) copied, 1.45197 s, 6.4 MB/s