加入收藏 | 设为首页 | 会员中心 | 我要投稿 天瑞地安资讯网 (https://www.52baoding.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Unix > 正文

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

发布时间:2022-12-03 08:30:19 所属栏目:Unix 来源:未知
导读: 如何使用quota机制对用户进行磁盘限额控制
Solaris中的quota机制是个很有用的管理机制,他能够使系统管理员对用户的磁盘使用限额进行有效地控制。能够控制的方式包括:
限制用户占用磁盘总

如何使用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是警告额度unix磁盘限额,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.

(编辑:天瑞地安资讯网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章