比如想在文件系统 /home 启用对 user 的配额限制:
chfs -a "quota = userquota" /home
# chfs -a "quota = userquota" /home
Initializing quota file /home/quota.user
*** Checking user quotas for /dev/hd1 (/home)
root fixed: inodes 0 -> 29 blocks 0 -> 3004
bin fixed: inodes 0 -> 1 blocks 0 -> 4
guest fixed: inodes 0 -> 1
duxs fixed: inodes 0 -> 33 blocks 0 -> 1892
dongzw fixed: inodes 0 -> 49 blocks 0 -> 172
想在 /home 上对user 和 group 启用配额限制:
chfs -a "quota = userquota,groupquota" /home
# chfs -a "quota = userquota,groupquota" /home
Initializing quota file /home/quota.group
*** Checking user and group quotas for /dev/hd1 (/home)
system fixed: inodes 0 -> 30 blocks 0 -> 3036
staff fixed: inodes 0 -> 96 blocks 0 -> 2100
bin fixed: inodes 0 -> 1 blocks 0 -> 4
usr fixed: inodes 0 -> 1
# lsfs -q /home
Name Nodename Mount Pt VFS Size Options Auto Accounting
/dev/hd1 -- /home jfs2 10485760 -- yes no
(lv size: 10485760, fs size: 10485760, block size: 4096, sparse files: yes, inline log: no, inline log size: 0, EAformat: v1, Quota: userquota,groupquota, DMAPI: no, VIX: yes, EFS: no, ISNAPSHOT: no)
相应的,在/etc/filesystems 文件中可以看到:
/home:
dev = /dev/hd1
vfs = jfs2
log = /dev/hd8
mount = true
check = true
vol = /home
free = false
quota = userquota,groupquota
当然可以使用其他的磁盘限额文件名(userquota)。 quota.user 和 quota.group 是默认的文件名,位置就在启用了磁盘配额的文件系统的跟目录下。也可以使用其他的磁盘配额文件名,在/etc/filesystems 文件中,可以看到配额文件名(userquota 和 groupquota 属性)。
下面例子使用 chfs 命令创建 user 和group 配额,文件系统 /home, 使用配额文件名为 myquota.user 和 myquota.group
chfs -a "userquota = /home/myquota.user" -a "groupquota = /home/myquota.group" /home
可以看到 /etc/filesystems 文件中就有了这些东西
/home:
dev = /dev/hd1
vfs = jfs
log = /dev/hd8
mount = true
check = true
quota = userquota,groupquota
userquota = /home/myquota.user
groupquota = /home/myquota.group
options = rw
如果文件系统处于为挂载状态, 将文件系统mount上。
为想要进行磁盘限制的用户或者组设置磁盘限额, 使用jfs2(jfs文件系统命令是edquota) 命令来设置每个user 或者 group,允许使用的磁盘空间和最大文件数额的软限制和硬限制。
下来我们来设置用户 duxs的磁盘配额限制
#j2edlimit -e -u /home
User Limits Classes for file system /home
Block Limits units: g=gigabyte, m=megabyte, or optional k=kilobyte
Grace Period units: d=days, h=hours, m=minutes, or s=seconds
Limits Class ID 0 is the default class.
Prepend '-' to ID to delete Limits Class.
Use '+' for ID to add new Limits Class.
Block Limits File Limits Grace Period
ID soft hard soft hard block file
0 0 0 0 0 0 0
+ 100m 150m 20 30 2d 3d
+ 110m 160m 20 30 2d 3d
注意上面红色部分是我添加的内容,保存并退出vi编辑器,再看下面红色显示部分
# j2edlimit -l -u /home
User Limits Classes for file system /home
Block Limits units: g=gigabyte, m=megabyte, or optional k=kilobyte
Grace Period units: d=days, h=hours, m=minutes, or s=seconds
Limits Class ID 0 is the default class.
Block Limits File Limits Grace Period
ID soft hard soft hard block file
0 0 0 0 0 0 0
1 100m 150m 20 30 2d 3d
2 100m 150m 20 30 2d 3d
解释一下我们都设置了些什么(下面解释是从IBM网站抄来的http://www.ibm.com/developerworks/cn/aix/library/1003_linhai_jfs2quota/)
在建立了配额限制类后,我们就可以针对用户或组进行配额设置了,该操作同样通过 j2edlimit 命令进行
# j2edlimit -a 1 -u duxs /home
User Limits Classes for file system /home
Block Limits units: g=gigabyte, m=megabyte, or optional k=kilobyte
Grace Period units: d=days, h=hours, m=minutes, or s=seconds
Block Limits File Limits Grace Period
ID soft hard soft hard block file
1 100m 150m 20 30 2d 3d
# j2edlimit -a 2 -u dongzw /home
User Limits Classes for file system /home
Block Limits units: g=gigabyte, m=megabyte, or optional k=kilobyte
Grace Period units: d=days, h=hours, m=minutes, or s=seconds
Block Limits File Limits Grace Period
ID soft hard soft hard block file
2 110m 160m 20 30 2d 3d
两个命令执行后,达到了何种效果呢
我们可以使用 repquota 命令来显示配额使用的情况:
# repquota /home
Block limits File limits
Group used soft hard grace used soft hard grace
system -- 3036 0 0 30 0 0
staff -- 2100 0 0 96 0 0
bin -- 4 0 0 1 0 0
usr -- 0 0 0 1 0 0
Block limits File limits
User used soft hard grace used soft hard grace
root -- 3036 0 0 30 0 0
bin -- 4 0 0 1 0 0
guest -- 0 0 0 1 0 0
duxs -+ 1892 102400 153600 33 20 30 none
dongzw -+ 172 112640 163840 49 20 30 none
可以看到,上面的限制,duxs和dongzw文件数目都已经超过了软限制20个硬限制30了,如果配额生效,那么此时,这个用户不能再创建文件
我们试试
# su - duxs
$ pwd
/home/duxs
$ touch aa
touch: 0652-046 Cannot create aa.
/home: operation failed, user inode quota limit reached
可见我们的设置是成功的,修改配额限制类1的限制数,文件数目软限制为49硬限制为51
j2edlimit -e /home
User Limits Classes for file system /home
Block Limits units: g=gigabyte, m=megabyte, or optional k=kilobyte
Grace Period units: d=days, h=hours, m=minutes, or s=seconds
Limits Class ID 0 is the default class.
Block Limits File Limits Grace Period
ID soft hard soft hard block file
0 0 0 0 0 0 0
1 100m 150m 49 51 2d 3d
2 110m 160m 20 30 2d 3d
查看目前配额使用情况
# repquota /home
Block limits File limits
Group used soft hard grace used soft hard grace
system -- 3036 0 0 30 0 0
staff -- 2100 0 0 96 0 0
bin -- 4 0 0 1 0 0
usr -- 0 0 0 1 0 0
Block limits File limits
User used soft hard grace used soft hard grace
root -- 3036 0 0 30 0 0
bin -- 4 0 0 1 0 0
guest -- 0 0 0 1 0 0
yanghz -- 12 0 0 5 0 0
zhangcy -- 8 0 0 3 0 0
duxs -- 1892 102400 153600 33 49 51
chkuser -- 16 0 0 6 0 0
dongzw -+ 172 112640 163840 49 20 30 none
下来duxs用户开始创建文件
su - duxs
cd test
for i in `seq 1 15`
do
touch $i.txt
done
# repquota /home
Block limits File limits
Group used soft hard grace used soft hard grace
system -- 3036 0 0 30 0 0
staff -- 2104 0 0 111 0 0
bin -- 4 0 0 1 0 0
usr -- 0 0 0 1 0 0
Block limits File limits
User used soft hard grace used soft hard grace
root -- 3036 0 0 30 0 0
bin -- 4 0 0 1 0 0
guest -- 0 0 0 1 0 0
yanghz -- 12 0 0 5 0 0
zhangcy -- 8 0 0 3 0 0
duxs -- 1896 102400 153600 48 49 51
chkuser -- 16 0 0 6 0 0
dongzw -+ 172 112640 163840 49 20 30 none
在切换到duxs
cd test
$ touch 16.txt
$ touch 17.txt
/home: warning, user inode quota exceeded
$
$ ls 17.txt
17.txt
可见配额中,文件数目的限制是有效的
如果不想启用quota了,
# chfs -a quota=no /home
# lsfs -q /home
Name Nodename Mount Pt VFS Size Options Auto Accounting
/dev/hd1 -- /home jfs2 10485760 -- yes no
(lv size: 10485760, fs size: 10485760, block size: 4096, sparse files: yes, inline log: no, inline log size: 0, EAformat: v1, Quota: no, DMAPI: no, VIX: yes, EFS: no, ISNAPSHOT: no)
如果觉得我的文章对您有用,请点赞。您的支持将鼓励我继续创作!
赞0
添加新评论0 条评论