2.5 启动并配置文件大小配额限制
--检查配额文件
[root@rhce ~]# quotacheck/dave
quotacheck: Cannot create new quotafile/dave/aquota.user.new: Permission denied
quotacheck: Cannot initialize IO on newquotafile: Permission denied
这里关闭SELinux即可:
[root@rhce ~]# getenforce
Enforcing
[root@rhce ~]# setenforce 0
[root@rhce ~]# getenforce
Permissive
[root@rhce ~]#
--启动配额限制
[root@rhce ~]# quotaon -vug /dave
/dev/sdc1 [/dave]: group quotas turned on
/dev/sdc1 [/dave]: user quotas turned on
[root@rhce ~]#
--开启之后,会在/dave的目录下自动创建配额的管理文件:aquota.group和aquota.user
[root@rhce dave]# pwd
/dave
[root@rhce dave]# ll
total 32
-rw-------. 1 root root 6144 Jun 22 09:28 aquota.group
-rw-------. 1 root root 6144 Jun 22 09:28 aquota.user
drwx------. 2 root root 16384 Jun 22 05:00lost+found
[root@rhce dave]#
这个文件我们不能直接编辑,我们需要使用edquota命令来进行编辑。
[root@rhce dave]# edquota -u dave01
Disk quotas for user dave01 (uid 503):
Filesystem blocks soft hard inodes soft hard
/dev/sdc1 0 10240 20480 0 0 0
这里的限制分三种:
1.blocks:按block的数量
2.soft:软限制,单位为字节。
3.hard: 硬限制,单位为字节。
上例中,soft限制约为10MB,hard限制约为20MB,当用户dave01使用空间超过10MB时,系统会进行提示,但可以继续使用空间,而当用户dave01使用空间达到20MB时,就会限制用户dave01继续使用/dave空间。
--查看报告:
[root@rhce dave]# repquota /dave
*** Report for user quotas on device/dev/sdc1
Block grace time: 7days;Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 141436 0 0 4 0 0
--这里只有root用户的信息,因为其他用户还没有创建文件,一旦创建文件,就会限制了。
[root@rhce dave]#
--用dave01用户创建文件进行配额限制的测试
--创建5M的文件:成功
[dave01@rhce ~]$ dd if=/dev/zeroof=/dave/tf01 bs=1M count=5
5+0 records in
5+0 records out
5242880 bytes (5.2 MB) copied, 0.0445553 s,118 MB/s
--创建10M的文件,超过soft 的配额限制,有警告:
[dave01@rhce ~]$ dd if=/dev/zeroof=/dave/tf01 bs=1M count=10
sdc1: warning, user blockquota exceeded.
10+0 records in
10+0 records out
10485760 bytes (10 MB) copied, 0.0232663 s,451 MB/s
--在创建10M的文件,超过20M的配额限制,文件创建失败:
[dave01@rhce ~]$ dd if=/dev/zeroof=/dave/tf02 bs=1M count=10
sdc1: write failed, userblock limit reached.
dd: writing `/dave/tf02':Disk quota exceeded
10+0 records in
9+0 records out
10448896 bytes (10 MB) copied, 0.049051 s,213 MB/s
[dave01@rhce ~]$
--查看报告:
[root@rhce dave]# repquota /dave
*** Report for user quotas on device/dev/sdc1
Block grace time: 7days;Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 141432 0 0 3 0 0
dave01 +- 20480 10240 20480 6days 3 0 0
这里就显示了dave01这个用户的相关限制。我们这里的宽限时间变成了6days。
2.6 配置文件个数的配额限制
配额的限制,除了在磁盘大小上的限制,还可以在文件个数上进行限制。我们这里用dave02这个进行示例。
[root@rhce dave]# edquota -u dave02
Disk quotas for user dave02 (uid 504):
Filesystem blocks soft hard inodes soft hard
/dev/sdc1 0 0 0 0 20 30
soft和hard同上是软限制和硬限制,分别是20、30,当用户dave02创建文件超过20个时,系统会进行提示,但仍可以继续创建文件,而当用户dave02创建文件超过30个文件时,就会限制用户dave02继续创建文件。
注意:因为用户dave02是在/dave目录下进行了磁盘配额限制,所以/dave目录会算做一个文件,所以dave02最多只能创建29个文件。
[root@rhce ~]# chown dave02.grp02 /dave
--用脚本手动创建文件:
[dave02@rhce ~]$ cd /dave
[dave02@rhce dave]$ ls
aquota.group aquota.user lost+found tf01 tf02
[dave02@rhce dave]$
[dave02@rhce dave]$ for i in $(seq 1 22);
> do echo “dave02file$i”;
> touch dave02file$i;
> done
“dave02file1”
“dave02file2”
“dave02file3”
“dave02file4”
“dave02file5”
“dave02file6”
“dave02file7”
“dave02file8”
“dave02file9”
“dave02file10”
“dave02file11”
“dave02file12”
“dave02file13”
“dave02file14”
“dave02file15”
“dave02file16”
“dave02file17”
“dave02file18”
“dave02file19”
“dave02file20”
sdc1: warning, user filequota exceeded.
“dave02file21”
“dave02file22”
[dave02@rhce dave]$
到20就提示配额限制了。
--继续用脚本创建文件:
[dave02@rhce dave]$ for i in $(seq 23 33);
> do echo “dave02file$i”;
> touch dave02file$i;
> done
“dave02file23”
“dave02file24”
“dave02file25”
“dave02file26”
“dave02file27”
“dave02file28”
“dave02file29”
“dave02file30”
sdc1: write failed, userfile limit reached.
touch: cannot touch`dave02file30': Disk quota exceeded
“dave02file31”
touch: cannot touch `dave02file31': Diskquota exceeded
“dave02file32”
touch: cannot touch `dave02file32': Diskquota exceeded
“dave02file33”
touch: cannot touch `dave02file33': Diskquota exceeded
[dave02@rhce dave]$
这里我们最多只能创建29个文件。
--限制报告:
[root@rhce ~]# repquota /dave
*** Report for user quotas on device/dev/sdc1
Block grace time: 7days;Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 141432 0 0 3 0 0
dave01 +- 20476 10240 20480 6days 2 0 0
dave02 -+ 4 0 0 30 20 30 6days
