免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2424 | 回复: 5
打印 上一主题 下一主题

如何使用quota机制对用户进行磁盘限额控制 [复制链接]

论坛徽章:
1
荣誉会员
日期:2011-11-23 16:44:17
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-03-18 12:18 |只看该作者 |倒序浏览
如何使用quota机制对用户进行磁盘限额控制

Solaris中的quota机制是一个很有用的管理机制,它可以使系统管理员对用户的磁盘使用限额进行有效地控制。可以控制的方式包括:
限制用户占用磁盘总容量
限制用户建立文件总数量
限制某个文件系统中用户文件的存在时间

使用quota机制时,要在需限额的各文件系统之主目录下需事先建立quotas空文件(如无),然后使用edquota -v username命令修改指定用户在该文件系统下的限制份额(0=无限制,单位为k),或该用户在该文件系统下文件总个数限额。使用quotacheck命令使系统确认quotas中的新内容。最后使用quotaon命令使限额生效。检查quota的状态可以使用quota或repquota等命令。

下面举一示例进行说明。示例中对用户userq在根文件系统中的磁盘限额进行控制:
# cd /
# touch quotas              ;如果该文件已经存在则不需要
# edquota userq            ;edquota将自动启动vi
fs / blocks (soft = 0, hard = 0) inodes (soft = 0, hard = 0)
~
~
这里blocks是用户磁盘的限额,单位为k。soft是警告额度,hard是限制额度。
如果用户占用磁盘量超过警告额度,系统将在每次用户进行磁盘操作或登录时进行警告,要求用户减少磁盘占用量至软限制之下;如果用户的操作会导致超过hard限制,那么操作将失败。
inodes是用户文件数量,soft和hard的含义类似。
本例把该用户的限额改变为:警告限制=1024K,硬限制=1024K。
fs / blocks (soft = 1024, hard = 1024) inodes (soft = 0, hard = 0)
~
~
                                   ;别忘存盘退出
# quotacheck -a            ;通知系统确认新的quota
# quotaon /                   ;打开quota机制
# repquota -v /              ;显示一下结果
/dev/dsk/c0t0d0s0 (/):
                      Block limits                      File limits
User           used   soft   hard    timeleft    used   soft   hard    timeleft
userq     --      6   1024   1024                   0      0      0

建立两个试验用的文件:
# cd /tmp
# mkfile 1000k a1000k
# mkfile 1080k a1080k
# chmod 666 a1000k
# chmod 666 a1080k

# su - userq
Sun Microsystems Inc.   SunOS 5.8       Generic Patch   October 2001
$ ls -l
total 6
-rw-r--r--   1 userq    other        124 Mar 18 09:25 local.cshrc
-rw-r--r--   1 userq    other        607 Mar 18 09:25 local.login
-rw-r--r--   1 userq    other        582 Mar 18 09:25 local.profile
$ cp /tmp/a1000k .
$ cp /tmp/a1080k .
quota_ufs: over hard disk limit (pid 1070, uid 1002, inum 371751, fs /)
cp: /tmp/a1080k: Disc quota exceeded

列目录看看,第二个cp操作因超过硬限额而失败。
$ ls -l
total 2022
-rw-r--r--   1 userq    other    1024000 Mar 18 10:35 a1000k
-rw-r--r--   1 userq    other        124 Mar 18 09:25 local.cshrc
-rw-r--r--   1 userq    other        607 Mar 18 09:25 local.login
-rw-r--r--   1 userq    other        582 Mar 18 09:25 local.profile
$ exit

下面用edquota把userq的硬限制改为2124后,再重复试验(别忘quotacheck!):

......
$ cp /tmp/a1080k .
quota_ufs: Warning: over disk limit (pid 1151, uid 1002, inum 371751, fs /)

列目录看看,警告归警告,可是操作还是成功了。
$ ls -l
total 4198
-rw-r--r--   1 userq    other    1024000 Mar 18 10:35 a1000k
-rw-r--r--   1 userq    other    1105920 Mar 18 10:45 a1080k
-rw-r--r--   1 userq    other        124 Mar 18 09:25 local.cshrc
-rw-r--r--   1 userq    other        607 Mar 18 09:25 local.login
-rw-r--r--   1 userq    other        582 Mar 18 09:25 local.profile
$ exit

关闭quota机制可以用命令quotaoff,限制用户在文件系统中文件存在时间用命令edquota -t.

论坛徽章:
0
2 [报告]
发表于 2003-05-22 13:37 |只看该作者

如何使用quota机制对用户进行磁盘限额控制

老大,我在执行
# edquota userq
的时候,出现了/etc/mnttab: no UFS filesystems with quotas file
这样的提示,该怎么解决啊!?

论坛徽章:
0
3 [报告]
发表于 2003-05-22 15:51 |只看该作者

如何使用quota机制对用户进行磁盘限额控制

add    -o q

论坛徽章:
0
4 [报告]
发表于 2003-05-22 16:01 |只看该作者

如何使用quota机制对用户进行磁盘限额控制

The following /etc/vfstab example shows that the /export/home directory from the system pluto is mounted as an NFS file system on the local system. You can tell quotas are enabled by the rq entry under the mount options column.



#device           device   mount       FS    fsck   mount   mount
#to mount         to fsck  point       type  pass   at boot options
#
pluto:/export/home -       /export/home nfs    -     yes    rq

论坛徽章:
0
5 [报告]
发表于 2003-05-29 21:32 |只看该作者

如何使用quota机制对用户进行磁盘限额控制

是在vfstab 中加入这一行“  pluto:/export/home - /export/home nfs - yes rq ” 吗?
我加了但作mount all 时保错!
aaa1:root/etc >;mount all
mount: warning: line for "/export/home" in vfstab has too few entries
mount: mount point cannot be determined
aaa1:root/etc >;

论坛徽章:
0
6 [报告]
发表于 2003-06-02 17:01 |只看该作者

如何使用quota机制对用户进行磁盘限额控制

是在vfstab里加一个参数,“rq”,它在一行的最后一个参数。对应的是:mount boot options
例如:
/dev/dsk/c0t4d0s0 /dev/rdsk/c0t4d0s0 /work ufs  3    yes     rq
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP