Use Quota to manage disk quotas

Source: Internet
Author: User
Article title: use Quota to manage disk quotas. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Author: moonsky
  
In network management, hard disk resources are limited, so users must be set for multiple users.
Disk quota. This function is especially required for public multi-user servers (free or charged ).
Yes. Quota is a tool for implementing disk quotas in Red Hat linux.
Quota installation
Different versions of quota packages are available in the/RedHat/RPMS Directory of the RHLinux CD.
, You can use ls quota * to view related information, such as the version number. Of course, you can easily obtain the software through the Tab key.
The full name of the package. run the following command to install the package:
Rpm-ivh quota-2.00pre3-7.i386.rpm
Of course, the version number provided here is only for convenience. this version is provided along with RH7. More
For the new version, follow the official site of RedHat. After the software package is installed, you can configure the disk quota.
  
Configure system disk quota support
First, the disk quota is regional. we can determine which partition is used for disk quota and which partition is not used.
(You do not need to configure it ). Generally, as a web virtual host server,/home and/www (or
Is used to store resource partitions. Therefore, you can set disk quotas for these two partitions. Assume that we
User-level restrictions must be imposed on/home partitions, while/www is subject to user quotas for each group.
◆ Step 1: vi/etc/fstab. (By the way, are you an administrator? ^ & ^)
Find the row corresponding to/home and/www, for example:
/Dev/sda5/home ext2 defaults 1 2
/Dev/sda7/www ext2 defaults 1 2
To implement user-level disk quota in/home, modify the mounting option field of sda5 as follows:
/Dev/sda5/home ext2 defaults, usrquota 1 2
Note: It's usrquota. Similarly, we can modify the/www line as follows:
/Dev/sda7/www ext2 defaults, maid 1 2
◆ Step 2: modify the/etc/rc. d/rc. local script and add the following script:
#############################
# Check quota and turn quota on
If [-x/sbin/quotacheck]; then
Echo "Checking quotas, This may take some time ..."
/Sbin/quotacheck-avug
Echo "Done ."
Fi
If [-x/sbin/quotaon]; then
Echo "Enabling disk quota ..."
/Sbin/quotaon-avug
Echo "Done ."
Fi
#############################
This script runs after the file system is loaded. it checks the disk quota and activates the disk.
Quota function.
◆ Step 3: Create a quota file for each partition with quota control.
Create a disk quota configuration file as follows:
Touch/home/quota. user
Touch/www/quota. group
Modify the license attributes of these two files so that they only have read and write permissions for the root user.
◆ Step 4: restart the system.
In this way, the system creates disk usage information in the quota file when running the quota check. Here, I
You have completed the system-level support configurations required for the disk quota. Then, we can allocate the quota to the user.
.
Set user and group quotas
The disk quota is generally based on the disk size occupied by a user and the number of all files.
. Before proceeding, let's take a look at the two basic concepts of disk quotas: soft limits and hard limits.
  
Soft limit: Maximum disk space and maximum number of files that a user can have in the file system.
This limit can be temporarily exceeded during the period.
Hard limit: the absolute number of disk space or files that a user can possess. the limit cannot be exceeded.
.
◆ Use the edit quota command edquota to configure quotas for users
After the system is restarted, if lanf is a system account that requires a quota, you can run the following command
Assign disk quota to users:
Edquota-u lanf
This command starts the default text EDITOR (such as vi or other editors specified by the $ EDITOR environment variable)
, The content is as follows:
Quotas for user lanf:
/Dev/sda5: blocks in use: 0, limits (soft = 0, hard = 0)
Inodes in use: 0, limits (soft = 0, hard = 0)
This indicates that the lanf user has used it in the/dev/sda5 partition (which is under the control of usrquota) so far.
Zero data blocks (in K), and no restrictions (including soft limitation and hard limitation ).
Lanf does not have any files or directories in this partition, and there are no hardware or software restrictions.
If we want to limit the disk capacity of users, we only need to modify the limits part of the blocks row.
The unit is K. For example, if you want to assign a M disk to a lanf instance and a M hard disk, you can
To use the following settings:
Quotas for user lanf:
/Dev/sda5: blocks in use: 0, limits (soft = 102400, hard = 409800)
Inodes in use: 0, limits (soft = 0, hard = 0)
Similarly, you can modify the inodes row to limit the number of file directories. We can also
Both are restricted. Only the following modifications are required.
Quotas for user lanf:
/Dev/sda5: blocks in use: 0, limits (soft = 102400, hard = 409800)
Inodes in use: 0, limits (soft = 12800, hard = 51200)
This indicates that in addition to the corresponding capacity limit, 12800 soft limits and 51
200 hard limits. After the new configuration is saved, the user's disk usage cannot exceed the hard limit. If the user
If you attempt to exceed this limit, the operation will be canceled and an error message will be returned.
However, if every user needs to make such a difficult setup, this repetitive physical labor would be a little tricky.
It's a waste of time. Fortunately, edquota also has a-q parameter (prototype)
Some users set to copy data. For example, we want to use the same limits as lanf for Jack, Tom, and Chen.
You can use the following command:
Edquota-p lanf-u Jack Tom Chen
In this way, these three users are assigned the same disk quota as lanf.
In addition to changing the-u parameter to the-g parameter in the edquota command
Operation:
Edquota-g webterm1
In fact, the above restrictions only apply to user-defined hard limits. If you need to make soft restrictions
If used, you also need to set a grace period for the user's soft restrictions-default, the grace period of the soft limit is infinite --
This can be achieved using the-t option of the edquota command. Run the following command:
Edquota-t
Edquota will open the default editor to display the following content:
Time units may be: days, hours, minutes, or seconds
Grace period before enforcing soft limits for users:
/Dev/sda5: block grace period: 0 days, file grace period: 0 days
You can set the grace period in days, hours, minutes, and seconds. For example, in the following example
The grace period of the space limit is two days, while the grace period of the document quantity limit is only six hours.
Time units may be: days, hours, minutes, or seconds
Grace period before enforcing soft limits for users:
/Dev/sda5: block grace period: 2 days, file grace period: 6 hours
◆ View your disk usage
To find out how much disk space a user uses, such as lanf, run the following command:
Quota-u lanf
Display:
Disk quotas for user lanf (uid 503 ):
Filesystem blocks quota limit grace file quota limit grace
/Dev/sda5 3 102400 409800 1 12800 51200
Similarly, you can use the quota-g groupname command to view the disk usage of a group.
Note: 1. if the user does not configure the disk quota, the output is shown as follows:
Disk quotas for user hujm (uid 503): none
2. if quota is run without any parameters, check your quota usage.
  
  
  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.