1、文件系统支持
quota是针对整个文件系统来进行规划,所以我们得先查一下/home是否是个独立的文件系统。
1 [root@Monitor home]# df -h /home 2 Filesystem Size Used Avail Use% Mounted on 3 /dev/xvda1 40G 5.9G 32G 16% / 4 [root@Monitor home]#
由于我的测试机系统的/home不是独立的文件系统,所以只能拿 / 来做试验了,不过强烈建议不要在正式服务器上的 / 做quota
1 [root@Monitor ~]# mount -o remount,usrquota,grpquota / 2 [root@Monitor ~]# mount 3 /dev/xvda1 on / type ext4 (rw,barrier=0,usrquota,grpquota) 4 proc on /proc type proc (rw) 5 sysfs on /sys type sysfs (rw) 6 devpts on /dev/pts type devpts (rw,gid=5,mode=620) 7 tmpfs on /dev/shm type tmpfs (rw) 8 none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw) 9 none on /proc/xen type xenfs (rw) 10 [root@Monitor ~]#
不过手动挂载的数据在下次重新挂载就会消失,因此最好写入配置文件中。
2、新建quota配置文件
quotacheck:扫描文件系统并新建quota的配置文件
-a:扫描所以在/etc/mtab 内,含有quota支持的文件系统
-u:针对用户扫描文件与目录的使用情况,会新建aquota.user
-g:针对用户组扫描与目录的使用情况,会新建aquota.group
-v:显示扫描过程的信息
-f:强制扫描文件系统,并写入新的quota配置文件(危险)
-M:强制以读写的方式扫描文件系统,只有在特殊情况下才会使用
1 [root@Monitor ~]# quotacheck -avug 2 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. 3 quotacheck: Quota for users is enabled on mountpoint / so quotacheck might damage the file. 4 Please turn quotas off or use -f to force checking.
由于我在写这篇博客前已经在这台测试机上做过quota,所以报错,只能加-f强制扫描了
1 [root@Monitor ~]# quotacheck -avug -mf 2 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. 3 quotacheck: Scanning /dev/xvda1 [/] done 4 quotacheck: Checked 13937 directories and 123932 files 5 [root@Monitor ~]#
这样配置文件就创建起来了!
3、quota启动、关闭与限制值设置
quotaon:启动quota服务
-u:针对用户启动quota(aquota.user)
-g:针对用户组启动quota(aquota.group)
-v:显示启动过程的相关信息
-a:根据/etc/mtab内的文件系统设置启动有关quota,若不加-a的话,则后面就需要加上特定的那个文件系统
启动quota
1 [root@Monitor ~]# quotaon -avug 2 /dev/xvda1 [/]: group quotas turned on 3 /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 501): Filesystem blocks soft hard inodes soft hard /dev/xvda1 996 8000 10000 10 0 0
然后将宽限时间改成14天
1 [root@Monitor ~]# edquota -tGrace period before enforcing soft limits for users: 2 Time units may be: days, hours, minutes, or seconds 3 Filesystem Block grace period Inode grace period 4 /dev/xvda1 14days 7days
4、quota限制值的报表
-g 列出群组的磁盘空间限制。
-q 简明列表,只列出超过限制的部分。
-u 列出用户的磁盘空间限制。
-v 显示该用户或群组,在所有挂入系统的存储设备的空间限制。
-V 显示版本信息。
-s 使用1024为倍数来指定单位,会显示如M之类的单位
1 [root@Monitor ~]# quota -uvs liu 2 Disk quotas for user liu (uid 501): 3 Filesystem blocks quota limit grace files quota limit grace 4 /dev/xvda1 996* 8000 10000 6days 10 0 0 5 [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