第一步:创建用户,用户组
脚本:
-
#!/bin/bash
groupadd quotagrp
for username in quota1 quota2 quota3 quota4 quota5
do
useradd -g quotagrp $username
echo "password" |passwd --stdin $username
done
第二步:由于quota只能针对文件系统进行配置,所以选择支持的文件系统(ext2,ext3),编辑系统挂载配置文件/etc/fstab,在文件中对应的文件系统加入,usrquota,grpquota字样,样式如下:
Bash代码
-
LABEL=/home /home ext3
defaults[color=red],usrquota,grpquota [/color] 1 2
第三步:重新挂载设置磁盘配额后的文件系统
Bash代码
mount -o remount,usrquota,grpquota /home
第四步:新建quota配置文件,利用quotacheck检查命令生成配置文件aquota.user,aquota.group,文件在文件系统根目录下。
quotachck -avug -mf
第五步:设置用户的磁盘限额,使用命令edquota -u username
-
Block limits File limits
User used soft hard grace used soft hard grace
myquota1 -- 88 400000 500000 11 0 0
第六步:查看quota限制值报表,命令:rpquota -auvs,效果如下:
-
*** Report for user quotas on device /dev/sda2
Block grace time: 14days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 173M 0 0 4 0 0
chenlixin -- 11832 0 0 481 0 0
pro1 -- 168 0 0 21 0 0
pro2 -- 160 0 0 20 0 0
pro3 -- 80 0 0 10 0 0
myquota1 -- 88 391M 489M 11 0 0
myquota2 -- 80 391M 489M 10 0 0
myquota3 -- 80 391M 489M 10 0 0
myquota4 -- 80 391M 489M 10 0 0
myquota5 -- 80 391M 489M 10 0 0
quota1 -- 80 391M 489M 10 0 0
quota2 -- 80 0 0 10 0 0
quota3 -- 80 0 0 10 0 0
quota4 -- 80 0 0 10 0 0
quota5 -- 80 0 0 10 0 0
Statistics:
Total blocks: 8
Data blocks: 1
Entries: 15
Used average: 15.000000