⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lsg21.htm

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTM
字号:


<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->


























<LINK REL="ToC" HREF="index.htm">







<LINK REL="Index" HREF="htindex.htm">







<LINK REL="Next" HREF="lsg22.htm">



















<A NAME="I0"></A>







<H2>Linux System Administrator's Survival Guide lsg21.htm</H2>







<P ALIGN=LEFT>







































<HR ALIGN=CENTER>







<P>







<UL>







<UL>







<UL>







<LI>







<A HREF="#E68E113" >Understanding Quotas</A>







<UL>







<LI>







<A HREF="#E69E138" >Hard and Soft Limits</A>







<LI>







<A HREF="#E69E139" >When to Use Quotas</A></UL>







<LI>







<A HREF="#E68E114" >Setting User Quotas</A>







<LI>







<A HREF="#E68E115" >Using the quota Command</A>







<LI>







<A HREF="#E68E116" >Using the quotacheck Command</A>







<LI>







<A HREF="#E68E117" >Summary</A></UL></UL></UL>







<HR ALIGN=CENTER>







<A NAME="E66E24"></A>







<H1 ALIGN=CENTER>







<CENTER>







<FONT SIZE=6 COLOR="#FF0000"><B>Chapter 21</B></FONT></CENTER></H1>







<BR>







<A NAME="E67E27"></A>







<H2 ALIGN=CENTER>







<CENTER>







<FONT SIZE=6 COLOR="#FF0000"><B>Managing Resources</B></FONT></CENTER></H2>







<BR>







<P>Even with today's high-capacity hard disks at reasonable prices, disk space shortages are chronic (especially on multiuser systems). Even the largest hard drives can get reduced to small available space when multiple operating systems, the full Linux system, swap space, and several users are brought into play. To combat this space shortage, there are several ways to manage the disk space you have available more effectively.







<BR>







<P>For multiuser systems, the ideal solution is to restrict the amount of space each user can use. This concept was first implemented in BSD UNIX with the quota command; the command then carried over to most versions of the software. Linux, because it is based primarily on BSD UNIX, also includes the quota system. This chapter looks at the quota command and how you can use it.







<BR>







<BR>







<A NAME="E68E113"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>Understanding Quota</B><B>s</B></FONT></CENTER></H3>







<BR>







<P>One of the best tools for managing resources is quota and its attendant utilities. The quota tool is used to display users' disk usage and their limits. When invoked, quota scans the /etc/fstab file and checks disk usage in the order of filesystems in the /etc/fstab file.







<BR>







<P>Quotas are preassigned amounts of disk space that a user or group can occupy. Normally, the limits do not prevent users or groups from exceeding their allotment, but exceeding the limits can result in warning messages appearing on-screen and usage reports being sent to root.







<BR>







<BR>







<A NAME="E69E138"></A>







<H4 ALIGN=CENTER>







<CENTER>







<FONT SIZE=4 COLOR="#FF0000"><B>Hard and Soft Limits</B></FONT></CENTER></H4>







<BR>







<P>Even if a user is considerably over quota, restricting the user from saving information can be difficult and may be the wrong thing to do in many cases. To help enforce restrictions and minimize complications, though, limits come in two types: soft and hard. A hard limit cannot be exceeded regardless of circumstances. If the user is trying to save valuable information and is over the hard limit, something has to go first. Because a user receives no warning when they are approaching a hard limit, this step is rather drastic, but it can be necessary with some users. A soft limit allows users to exceed their quotas for a while, but they get warning messages. You can set the system to allow only so many warnings before imposing a hard limit. Ideally, you should set your system to have a soft limit somewhat smaller than a hard limit, so users get warnings before they are unable to save anything else. Just setting a hard limit with no warning mechanism can result in annoyed users!







<BR>







<BR>







<A NAME="E69E139"></A>







<H4 ALIGN=CENTER>







<CENTER>







<FONT SIZE=4 COLOR="#FF0000"><B>When to Use Quotas</B></FONT></CENTER></H4>







<BR>







<P>Not all filesystems need quotas. If you have several hard drives broken into filesystems, you may use some for unlimited storage, and others, which are near capacity, may need quotas. The decision as to which filesystems require quotas is up to you. Most versions of Linux that adhere closely to the BSD standards require a modification in the /etc/fstab file to indicate that the filesystem uses quotas. The word quota must go in the fourth column of the file, as in the following entry:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">/dev/sda3 /usr rw,quota 1 3</FONT></PRE>







<P>This entry indicates that quotas are in place on the /usr filesystem. If the entry has the keyword noquota, you can change it to quota.







<BR>







<BR>







<A NAME="E68E114"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>Setting User Quotas</B></FONT></CENTER></H3>







<BR>







<P>The system administrator sets user quotas in a file called quota.user in the root directory of the filesystem to which the quotas apply. Similarly, group quotas (if used) are set in the file quota.group also in the root directory of the filesystem. You need to manually create the quota files, either by using cat to save a blank file or by using touch. The following commands show how to set quotas on the /usr filesystem:







<BR>







<PRE>







<FONT COLOR="#000080">cd /usr







touch quota.user







chmod 600 quota.user







touch quota.group







chmod 600 quota.group</FONT></PRE>







<P>The chmod command makes the file writable by root only. You set the quota limits with the edquota command, which is usable only by root. Follow edquota with the name of the user (or multiple users) or group that you want to set quotas for, as in the following example:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">/usr/etc/edquota tparker ychow bsmallwood</FONT></PRE>







<P>You may not need to specify the path if the edquota command is in the default system search path. This command starts an editor (the default is vi). If you provide a group name, a temporary file stores information about the users in the group, and then writes the information to the quota.group file afterwards.







<BR>







<P>You can control edquota's behavior with a number of options. These options are usually supported by Linux' version of edquota:







<BR>















<TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







-g







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Edit a group's quota</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







-p







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Duplicate quotas of one user for others</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







-t







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Edit soft time limits (before a hard limit is imposed)</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







-u







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Edit a user's quota (default action)</FONT>







</TABLE><P>If you want to use the same quota entries for several users, you need edit only one and then use the -p option to duplicate the entries. For example, the command







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">edquota -p tparker ychow bsmallwood</FONT></PRE>







<P>uses the tparker user entries for ychow and bsmallwood.







<BR>







<P>After you set the quotas you want to use on the filesystems, you must turn on the quota system with the quotaon command. You can turn on quotas for a single filesystem with the command







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">quotaon /dev/sda3</FONT></PRE>







<P>which turns on quota checking for the partition /dev/sda3. To turn on quota checking for all partitions, use the following command:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">quotaon -a</FONT></PRE>







<P>The quotaoff command, not surprisingly, performs the reverse action with the same arguments.







<BR>







<BR>







<A NAME="E68E115"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>Using the quota Command</B></FONT></CENTER></H3>







<BR>







<P>The syntax for the quota command is as follows:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">quota [options] [user] [group]</FONT></PRE>







<P>These options for the quota command are valid:







<BR>















<TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







-g







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Displays group quotas for the group of which the user is a member</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







-q







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Displays only filesystems where usage is over quota</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







-u







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Displays quotas for users (the default action)</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







-v







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Displays quotas on a filesystem where no storage is allocated</FONT>







</TABLE><P>You can combine these options. For example, if you use both -g and -u, both the user and group quotas are displayed. The system administrator can display quotas for all users with the -u option followed by a username, as in the following:







<BR>







<BR>







<PRE>







<FONT COLOR="#000080">quota -u tparker</FONT></PRE>







<P>You can only use the command with this option when logged in as root. If a non-root users issue the quota command, they can display only their user quotas and their group's quota.







<BR>







<BR>







<A NAME="E68E116"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>Using the quotacheck Command</B></FONT></CENTER></H3>







<BR>







<P>When you have quotas in place and running, you can use the quotacheck command at any time to scan your filesystems for current disk usage. The results of the scan are written into the quota.user and quota.group files in the filesystem root directories.







<BR>







<P>Set the quotacheck command to run every time the system is booted so that the quota files are updated automatically. The best way to accomplish this task is to place the quotacheck command in the rc startup files. Because checking filesystems can take some time, use this command primarily with multiuser systems that see a lot of use. Otherwise, get in the habit of using quotacheck at intervals or when an error has occurred on a mounted filesystem.







<BR>







<P>The quotacheck command accepts a number of options to display different information:







<BR>















<TABLE  BORDERCOLOR=#000040 BORDER=1 CELLSPACING=2 WIDTH="100%" CELLPADDING=2 >







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







<A NAME="I2"></A>-a







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Checks all filesystems (not all versions of Linux quota support this option)</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







-d







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Debugs information displayed during checking (slows down the check considerably)</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







-g







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Followed by a group ID, checks only that group</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







-u







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Followed by a user ID, checks only that user (or all users if no user is specified, which is the default)</FONT>







<TR>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







-v







</FONT>







<TD VALIGN=top  BGCOLOR=#80FFFF ><FONT COLOR=#000080>







Verbose output showing what quotacheck is doing</FONT>







</TABLE><P>Using quotacheck regularly helps make sure the filesystem quotas are being followed.







<BR>







<BR>







<A NAME="E68E117"></A>







<H3 ALIGN=CENTER>







<CENTER>







<FONT SIZE=5 COLOR="#FF0000"><B>Summary</B></FONT></CENTER></H3>







<BR>







<P>The quota system lets you set limits on the amount of disk space your users occupy in order to prevent potential problems when capacities are exceeded. Using quotas also makes sense when you are sharing your system with friends, but don't want them to take your system for granted as a storage depot!







<P ALIGN=LEFT>























































</td>
</tr>
</table>

<!-- begin footer information -->



</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -