磁盘配额quota用途:
www server限制用户网页空间量
mail server限制用户的邮件空间量
等
使用限制:
1.针对整个文件系统或者说整个分区
2.核心必须支持quota
3.只对一般身份有限制,root无限制
限制方式:
1.限制inode数量,即创建文件的数量
2.限制block数量,即管理用户使用磁盘量的限制(常用)
限制值有两个:
hard:当用户决不能使用磁盘超过此值
soft:当用户使用磁盘量低于soft时无问题,当使用磁盘量超过soft未超过hard时,每次登陆系统都会报警,且会给与一个宽限的时间点。
实例:
环境准备,文件系统/dev/sdg 挂载在/test_quota上,额外参数(defaults,usrquota,grpquota)
创建quota记录文件,quota是分析整个文件系统,将每个用户可以使用的inode和block记录在文件系统的最顶层文件。然后在该记录文件中使用每个账号去限制所有量。
[root@www ~]# quotacheck -avug #-a根据扫描所有/etc/mtab支持的quota的文件系统,v显示详细过程 u针对用户创建记录文件 g根据群组创建记录文件 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/sdg [/test_quota] done quotacheck: Cannot stat old user quota file /test_quota/aquota.user: No such file or directory. Usage will not be substracted. quotacheck: Cannot stat old group quota file /test_quota/aquota.group: No such file or directory. Usage will not be substracted. quotacheck: Cannot stat old user quota file /test_quota/aquota.user: No such file or directory. Usage will not be substracted. quotacheck: Cannot stat old group quota file /test_quota/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@www ~]#
启动quota服务,使用quotaon命令,选项-avug,关闭quota服务使用quotaoff,选项-a -u -g
[root@www ~]# quotaon -avug /dev/sdg [/test_quota]: group quotas turned on /dev/sdg [/test_quota]: user quotas turned on
编辑帐号和群组的限制值和宽限时间,使用edquota命令
-u + 用户,修改用户的限制值
-g + 群组,修改群组的限制值
-t + 时间,修改限制值
-p 复制范本
[root@www ~]# edquota testquota -u Disk quotas for user testquota (uid 665): Filesystem blocks soft hard inodes soft hard /dev/sdg 0 5 10 0 4 10 [root@www ~]# edquota -p testquota -u testquota1 #复制规则给其他用户
设置宽限时间,默认7天。
[root@www ~]# edquota testquota -u 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/sdg 7days 7days
查看每个用户的限制值
[root@www ~]# quota -uvs testquota testquota1 Disk quotas for user testquota (uid 665): Filesystem blocks quota limit grace files quota limit grace /dev/sdg 0 5 10 0 4 10 Disk quotas for user testquota1 (uid 666): Filesystem blocks quota limit grace files quota limit grace /dev/sdg 0 5 10 0 4 10 [root@www ~]#
测试:
[testquota@www test_quota]$ touch a [testquota@www test_quota]$ touch b [testquota@www test_quota]$ touch c sdg: warning, user file quota exceeded. [testquota@www test_quota]$ touch d [testquota@www test_quota]$ touch f [testquota@www test_quota]$ touch e [testquota@www test_quota]$ touch i [testquota@www test_quota]$ touch w [testquota@www test_quota]$ touch o sdg: write failed, user file limit reached. touch: 无法创建"o": 超出磁盘限额 [testquota@www test_quota]$