Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1380471
  • 博文数量: 247
  • 博客积分: 10147
  • 博客等级: 上将
  • 技术积分: 2776
  • 用 户 组: 普通用户
  • 注册时间: 2008-01-24 15:18
文章分类

全部博文(247)

文章存档

2013年(11)

2012年(3)

2011年(20)

2010年(35)

2009年(91)

2008年(87)

我的朋友

分类: LINUX

2011-04-15 16:41: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) 
~ 
~ 
:x ;别忘存盘退出 
# 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.

阅读(1421) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
yjmyb 回复于:2003-05-22 13:37:31
老大,我在执行 
# edquota userq 
的时候,出现了/etc/mnttab: no UFS filesystems with quotas file 
这样的提示,该怎么解决啊!?

yong6 回复于:2003-05-22 15:51:07
add -o q

yong6 回复于:2003-05-22 16:01:34
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

nortell 回复于:2003-05-29 21:32:44
是在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 >

yong6 回复于:2003-06-02 17:01:43
是在vfstab里加一个参数,“rq”,他在一行的最后一个参数。对应的是:mount boot options 
例如: 
/dev/dsk/c0t4d0s0 /dev/rdsk/c0t4d0s0 /work ufs 3 yes rq