--当对用户或组指定在块设备上可写空间时,我们可以通过quota磁盘配额方式进行设定。
1.适应对象
限制
普通用户使用空间
限制
组使用空间(成员共享容量)
2.主要应用
web
文件服务器
邮件服务器
* quota
它只能针对分区来做
只能限制普通用户,不能限制root
3.quota的限制方式:
一个为容量大小
另一个为文件个数(即 inode节点)
软硬之间期限限制:edquota –t 指软限到硬限这段容量还可以写的有效时间,默认0,不限制.
4.quota 的mount 参数
默认的挂载参数里没有包括quota的功能
defaults
Use default options: rw, suid, dev, exec,
auto, nouser, and async.
所以要重新挂载,并加上能使用quota的参数:
usrquota --用户参数
grpquota --组参数
例:假设对新划分的/dev/sda7以磁盘配额方式mount到 /quota下时,操作如下
a.
# mount -t ext3 -o
usrquota,grpquota /dev/sda7 /quota/
--如对已在使用的分区挂载磁盘配额使用方式时: -o
remount,usrquota,grpquota 即可
b.
# vim /etc/fstab
/dev/sda7
/quota ext3 defaults,usrquota,grpquota 0 0
做完这a.b.马上生效,不用重启系统
# mount |grep sda7
/dev/sda7 on /quota type ext3 (rw,usrquota,grpquota)
# cat /etc/mtab |grep sda7
/dev/sda7 /quota ext3 rw,usrquota,grpquota 0 0
# ls –a /quota
. .. lost+found
5.对分区生成磁盘配额必需的文件
命令
quotacheck - scan a filesystem for disk usage, create, check and repair quota files
# quotacheck -cauvg /quota
--cauvg即 –建立所有用户和组的磁盘配额文件并回显
--检测当前分区磁盘配额情况从面在当前目录生成
quota.group及
quota.user这两个文件才可以对编辑建立的磁盘配额,信息如下
quotacheck: Scanning /dev/sda7 [/quota] quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
done
quotacheck: Checked 3 directories and 2 files
quotacheck: Old file not found.
quotacheck: Old file not found.
# ls –a /quota
. .. aquota.group aquota.user lost+found
6.对用户或组设置磁盘配额
edquota - edit user quotas
例:
# id user4
uid=503(user4) gid=503(user4) groups=503(user4)
# id user5
uid=504(user5) gid=504(user5) groups=504(user5)
# edquota -u user4 /quota
技巧:(edquota –p “已分配用户” –u “待分配用户” )
Disk quotas for user user4 (uid 503):
Filesystem
blocks soft hard inodes soft hard
/dev/sda7
0 80000 100000 0 0 0
# edquota -u user5 /quota
Disk quotas for user user5 (uid 504):
Filesystem
blocks soft hard inodes soft hard
/dev/sda7
0 50000 70000 0 0 0
说明:
7.启用quota
#
quotaon /dev/sda7
repquota - summarize quotas for a filesystem
--关闭为
quotaoff
8.查看用户或组quota信息
#
repquota -avgus
*** Report for user quotas on device /dev/sda7
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User
used soft hard grace used soft hard grace
----------------------------------------------------------------------
root
-- 17632 0 0 4 0 0
user4
-- 0 80000 100000 0 0 0
user5
-- 0 50000 70000 0 0 0
Statistics:
Total blocks: 7
Data blocks: 1
Entries: 3
Used average: 3.000000
*** Report for group quotas on device /dev/sda7
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
Group
used soft hard grace used soft hard grace
----------------------------------------------------------------------
root
-- 17632 0 0 4 0 0
Statistics:
Total blocks: 6
Data blocks: 1
Entries: 1
Used average: 1.000000
测试:
# chmod o+w /quota/
# ll -d /quota/
drwxr-xrwx 3 root root 4096 Dec 9 13:56 /quota/
切换普通用户
$ dd if=/dev/zero of=/quota/user401 bs=1M count=75
75+0 records in
75+0 records out
78643200 bytes (79 MB) copied, 0.128789 seconds, 611 MB/s
$ dd if=/dev/zero of=/quota/user402 bs=1M count=5
sda7: warning, user block quota exceeded. --报警,超过软限制
5+0 records in
5+0 records out
5242880 bytes (5.2 MB) copied, 0.00809876 seconds, 647 MB/s
$ dd if=/dev/zero of=/quota/user403 bs=1M count=20
sda7: write failed, user block limit reached. --报错,超过硬限制
dd: writing `/quota/user403': Disk quota exceeded
18+0 records in
17+0 records out
18395136 bytes (18 MB) copied, 0.0345689 seconds, 532 MB/s
附:以上在rhel5.4下测试通过。
Blocks 当前磁盘容量单位:KB
# quotaon / 启动磁盘配额
#quota -u abc 查看用户磁盘配额
repquota -a 查看所有磁盘配额使用情况
quota -g abc 查看组配额
edquota -p 用户1 用户2 把用户1的配额复制给用户2
最后加到启动脚本里,系统启动时自动启动quota
可以加入到/etc/rc.d/rc.local 结尾加上一行
/usr/sbin/quotaon -aug
关机重启时在/etc/rc.d/rc.【0,6】中关闭quota语句
/usr/sbin/quotaoff -aug
本文出自 “IT工作实战” 博客,转载请与作者联系!