📄 1075.html
字号:
group: 有针对用户的自然会有针对用户组的文件系统限额方式。<br>
现在,你对文件系统限额的方式有一定的了解。好!下面我们就进入实战阶段, 真真
正正来配置系统的限额。<br>
首先,quota是需要linux内核支持才行,而现在使用的Linux Kernel 2.4.XX都支持
quota也就是说只要你使用linux distributions,例如Mandrake 9.0或Redhat 8.0 就可
以配置文件系统的限额。接着,我们了解与quota有关的系统命令,它们是quota,
quotacheck,edquota,quotaon和quotaoff,它们的详细说明如下:<br><br>
quota: 主要是用来查询用户的限额配置清况。下面是一个例子:<br><br>
[root@lustr root]# quota -u chase<br>
Disk quotas for user chase (uid 500):<br>
Filesystem blocks quota limit grace files quota limit grace<br>
/dev/sda5 6 10 20 6 0 0<br><br>
上面每一项具体的意思会在后面相关的地方会解释。<br><br>
quotacheck: 这个命令主要是用来扫描要实现限额的文件系统,并在第一次运行时建
立必要的限额配置文件,如果在建立quota后运行,它就会更新这两个文件。通常情况下,
quotacheck扫描文件系统时,它先把文件系统挂载成只读方式,因为当在扫描的过程中出
现文件的增加或减少都会使quotacheck出错。当扫描完毕后,它又会把文件系统挂载成读
写方式。linux还特别强调在文件系统quota on或off都要运行quotacheck。下面是一个例
子;<br><br>
[root@lustr root]# quotacheck -uvg /home/<br>
quotacheck: Scanning /dev/sda5 [/home] done<br>
quotacheck: Checked 3 directories and 7 files<br><br>
这个例子是扫描/home下面的文件系统其中参数u和g是表示要对user和group的限额都
要扫描,结果是在这个目录下有3个目录和7个文件。v就不用多说了, 除此之外还有一个
参数是a,它表示对所有在配置了quota的分区都要进行扫描。<br><br>
edquota: 这个命令是主要的文件配额命令, 它可以配置用户或用户组的文件系统限
额。除此之外,edquota还可以建立一个用户限额配置的拷贝, 并用于其他用户的限额配
置。下面是一个例子;<br><br>
[root@lustr root]# edquota -u chase<br><br>
当运行上命令后,edquota缺省调用vi来编辑quota文件, 如果你不想使用vi来编辑
quota的文件,你可以设定环境变量EDITOR或VISUAL为你希望的编辑器。 下面是vi的输出
结果;<br><br>
Disk quotas for user chase (uid 500):<br>
Filesystem blocks soft hard inodes soft hard<br>
/dev/sda5 6 10 20 6 0 0<br><br>
上面的结果和我们先前所运行quota的结果很类似的, 我在这里说说上面每一项的具
体意思以帮助大家理解quota的输出结果。<br><br>
Filesystem: 这个就不用多说啦。<br>
blocks: 这个是当前用户在这个分区里所使用的空间大小,单位是Kbyte。 这个
是文件系统自己计算出来的,所以在编辑该文件时不要修改这个参数。<br>
soft: 这个在一开始就介绍过了,就是soft限额方式的限额值。单位也是KBytes。<br>
hard: 这个在一开始就介绍过了,就是hard限额方式的限额值。单位也是KBytes。<br>
inodes: 这个是当前用户使用文件系统节点的个数。和blocks类似,它也是文件系统
自己计算出来的,所以在编辑该文件时不要修改这个参数。<br>
注意: 当soft,hard设定为0,0时,这表示没有限额。第一和第二对的soft和hard
时对block和inode的不同限额数,而在quota的输出结果就分别是blocks和files的限额数。<br><br>
下面有两个例子<br><br>
[root@lustr root]# quota -u test;edquota -p chase -u test;quota -u test<br>
Disk quotas for user test (uid 501): none<br>
Disk quotas for user test (uid 501):<br>
Filesystem blocks quota limit grace files quota limit grace<br>
/dev/sda5 5 10 20 5 0 0<br><br>
上面是一个用chase用户限额的拷贝实施在test用户上。<br><br>
[root@lustr root]# edquota -t<br><br>
下面是vi的输出结果:<br><br>
Grace period before enforcing soft limits for users:<br>
Time units may be: days, hours, minutes, or seconds<br>
Filesystem Block grace period Inode grace period<br>
/dev/sda5 7days 7days<br><br>
上面是一个设定超过soft限额时所允许的时限。从上面的例子看出:对于Block和
Inode的soft限额的时限为7天。如果你要不同的时间单位,你就可以用seconds,
minutes,hours,days,weeks和months来表示。<br><br>
quotaon: 这个命令是用来启动quota的,如果你还没有建立aquota.user和
aquota.group两个文件的话,运行这个命令就会出错,所以在此之前一定要完成
quotacheck的工作,然后直接运行quota -a就可以了。你还可以制定启动的是用户限额
(u)或是用户组限额(g),还有指定特定的以配置限额的分区启动。<br><br>
[root@lustr root]# quotaon -uv /home<br><br>
上面就是指定目录/home启动用户限额。<br><br>
quotaoff: 这个命令就是关闭quota,参数同上。<br><br>
好了,我说了一大堆的东西。下面说说配置限额的步骤:<br><br>
1. 先要启动文件系统的限额功能。这一步主要是要编辑/etc/fstab文件。<br>
在通常的没启动限额功能的文件系统的fstab文件内容如下:<br><br>
LABEL=/ / ext3 defaults 1 1<br>
none /dev/pts devpts gid=5,mode=620 0 0<br>
LABEL=/home /home ext3 defaults 1 2<br>
none /proc proc defaults 0 0<br>
none /dev/shm tmpfs defaults 0 0<br>
LABEL=/usr /usr ext3 defaults 1 2<br>
LABEL=/var /var ext3 defaults 1 2<br>
/dev/sda3 swap swap defaults 0 0<br>
/dev/cdrom /mnt/cdrom udf,iso9660 noauto,owner,kudzu,ro 0 0<br><br>
如果你想对/home这个目录下,也就是/dev/sda5分区启动限额功能的话,我们可以修
改对应的home项为:<br><br>
LABEL=/home /home ext3 defaults,usrquota,grpquota 1 2<br><br>
你可以看到,在home对应项增加usrquota和grpquota(注意拼写)来实现用户和用户组
的限额功能,然后重新启动linux。重起后,你要检查/etc/mtab是否在对应的home项加上
usrquota和grpquota,如下:<br><br>
/dev/sda1 / ext3 rw 0 0<br>
none /proc proc rw 0 0<br>
usbdevfs /proc/bus/usb usbdevfs rw 0 0<br>
none /dev/pts devpts rw,gid=5,mode=620 0 0<br>
/dev/sda5 /home ext3 rw,usrquota,grpquota 0 0<br>
none /dev/shm tmpfs rw 0 0<br>
/dev/sda2 /usr ext3 rw 0 0<br>
/dev/sda6 /var ext3 rw 0 0<br><br>
你是不是觉得有点奇怪,我刚才不是只编辑fstab,那和mtab有什么关系呢? 主要原
因是quota真正读取的文件是mtab,所以你一定要确认mtab在你修改fstab文件重起后一定
更新为上面,这样才可以确认你对fstab的修改成功。<br><br>
2. 首次扫描文件系统的使用情况。主要使用quotacheck来扫描文件系统。如上所说,在
扫描完毕后,就会在对应的目录下产生aquota.user和aquota.group, 这两个文件的位置
都是在顶层的目录里,例如你对/home启动quota功能,那么这两个文件就会位于/home/下面。<br><br>
[root@lustr home]# ls -l<br>
total 31<br>
-rw------- 1 root root 7168 Apr 22 04:29 aquota.group<br>
-rw------- 1 root root 7168 Apr 22 05:14 aquota.user<br>
drwx------ 2 chase chase 4096 Apr 22 05:05 chase<br>
drwx------ 2 test test 1024 Apr 22 05:13 test<br><br>
既然这两个文件都产生了,我们就可以启动文件系统限额功能对特定的用户或用户组
实行限额。<br><br>
4. 启动quota。我们可以用前面介绍的quotaon来启动。<br><br>
[root@lustr root]# quotaon -av<br>
/dev/sda5 [/home]: group quotas turned on<br>
/dev/sda5 [/home]: user quotas turned on<br><br>
这是一个启动的输出结果。<br><br>
5. 配置用户或用户组的限额。这一步可以参考edquota命令的说明。<br><br>
上面基本把与quota配置相关的命令和文件都介绍了。<br>
</FONT><br>
</TD>
</TR>
<TR>
<TD colSpan=2><FONT
class=middlefont></FONT><BR>
<FONT
class=normalfont>全文结束</FONT> </TD>
</TR>
<TR>
<TD background="images/dot.gif" tppabs="http://www.linuxhero.com/docs/images/dot.gif" colSpan=2
height=10></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE></DIV></TD>
<TD vAlign=top width="20%"
background="images/line.gif" tppabs="http://www.linuxhero.com/docs/images/line.gif" rowSpan=2>
<DIV align=center>
<table class=tableoutline cellspacing=1 cellpadding=4
width="100%" align=center border=0>
<tr class=firstalt>
<td noWrap background="images/bgline.gif" tppabs="http://www.linuxhero.com/docs/images/bgline.gif" colspan=2 height=21>
<font class=normalfont><b>所有分类</b></font></td>
</tr>
<tr class=secondalt> <td noWrap width=27%> <font class=normalfont>1:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type1.html" tppabs="http://www.linuxhero.com/docs/type1.html">非技术类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>2:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type2.html" tppabs="http://www.linuxhero.com/docs/type2.html">基础知识</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>3:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type3.html" tppabs="http://www.linuxhero.com/docs/type3.html">指令大全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>4:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type4.html" tppabs="http://www.linuxhero.com/docs/type4.html">shell</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>5:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type5.html" tppabs="http://www.linuxhero.com/docs/type5.html">安装启动</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>6:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type6.html" tppabs="http://www.linuxhero.com/docs/type6.html">xwindow</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>7:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type7.html" tppabs="http://www.linuxhero.com/docs/type7.html">kde</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>8:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type8.html" tppabs="http://www.linuxhero.com/docs/type8.html">gnome</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>9:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type9.html" tppabs="http://www.linuxhero.com/docs/type9.html">输入法类</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>10:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type10.html" tppabs="http://www.linuxhero.com/docs/type10.html">美化汉化</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>11:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type11.html" tppabs="http://www.linuxhero.com/docs/type11.html">网络配置</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>12:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type12.html" tppabs="http://www.linuxhero.com/docs/type12.html">存储备份</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>13:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type13.html" tppabs="http://www.linuxhero.com/docs/type13.html">杂项工具</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>14:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type14.html" tppabs="http://www.linuxhero.com/docs/type14.html">编程技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>15:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type15.html" tppabs="http://www.linuxhero.com/docs/type15.html">网络安全</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>16:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type16.html" tppabs="http://www.linuxhero.com/docs/type16.html">内核技术</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>17:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type17.html" tppabs="http://www.linuxhero.com/docs/type17.html">速度优化</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>18:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type18.html" tppabs="http://www.linuxhero.com/docs/type18.html">apache</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>19:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type19.html" tppabs="http://www.linuxhero.com/docs/type19.html">email</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>20:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type20.html" tppabs="http://www.linuxhero.com/docs/type20.html">ftp服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>21:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type21.html" tppabs="http://www.linuxhero.com/docs/type21.html">cvs服务</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>22:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type22.html" tppabs="http://www.linuxhero.com/docs/type22.html">代理服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>23:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type23.html" tppabs="http://www.linuxhero.com/docs/type23.html">samba</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>24:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type24.html" tppabs="http://www.linuxhero.com/docs/type24.html">域名服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>25:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type25.html" tppabs="http://www.linuxhero.com/docs/type25.html">网络过滤</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>26:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type26.html" tppabs="http://www.linuxhero.com/docs/type26.html">其他服务</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>27:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type27.html" tppabs="http://www.linuxhero.com/docs/type27.html">nfs</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>28:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type28.html" tppabs="http://www.linuxhero.com/docs/type28.html">oracle</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>29:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type29.html" tppabs="http://www.linuxhero.com/docs/type29.html">dhcp</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>30:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type30.html" tppabs="http://www.linuxhero.com/docs/type30.html">mysql</a></font></td> </tr> </table></td></tr><tr class=secondalt> <td noWrap width=27%> <font class=normalfont>31:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type31.html" tppabs="http://www.linuxhero.com/docs/type31.html">php</a></font></td> </tr> </table></td></tr><tr class=firstalt> <td noWrap width=27%> <font class=normalfont>32:</font> </td><td noWrap width=73%> <table width=100% border=0> <tr> <td><font class=normalfont><a href="type32.html" tppabs="http://www.linuxhero.com/docs/type32.html">ldap</a></font></td> </tr> </table></td></tr> </table>
</DIV></TD></TR>
<TR vAlign=top>
<TD width="80%">
<DIV align=center><BR>
</DIV>
</TD></TR></TBODY></TABLE></TD></TR>
</TABLE></TD></TR>
</TABLE>
<TABLE cellSpacing=0 cellPadding=4 width="100%" bgColor=#eeeeee
border=0><TBODY>
<TR>
<TD width="50%">
<P><FONT class=middlefont>版权所有 © 2004 <A
href="mailto:bjchenxu@sina.com">linux知识宝库</A><BR>
违者必究. </FONT></P>
</TD>
<TD width="50%">
<DIV align=right><FONT class=middlefont>Powered by: <A
href="mailto:bjchenxu@sina.com">Linux知识宝库</A> Version 0.9.0 </FONT></DIV>
</TD></TR></TBODY></TABLE>
<CENTER></CENTER></TD></TR>
</TABLE></CENTER></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -