Use QUOTA (Disk QUOTA) to limit user space

Source: Internet
Author: User
Use QUOTA (Disk QUOTA) to restrict user space-Linux Enterprise Application-Linux server application information. The following is a detailed description. In a VM, you must limit the size of user space and the number of files. These restrictions are implemented using QUOTA in linux and FreeBSD. Here I will talk about the implementation method in FreeBSD;

Enable QUOTA support
First, you need to modify the kernel and add support for quota.

Machine i386
Cpu I686_CPU
# Ident GENERIC
Ident CNOSvhost
Maxusers 0
Options QUOTA # This is the line.

After modification, re-compile the kernel.
Then add the following in/etc/rc. conf:

Enable_quotas = "YES"
Check_quotas = "YES"

In this way, your system starts to use QUOTA. You should add QUOTA support by editing the attributes of a file system in/etc/fstab.
The fstab file below sets the user quota and group quota for use on the/pub file system.

# See the fstab (5) manual page for important information on automatic mounts
# Of network filesystems before modifying this file.
# Device Mountpoint FStype Options Dump Pass #
/Dev/ad0s1b none swap sw 0 0
/Dev/ad0s1a/ufs rw 1 1
/Dev/ad0s1h/pub ufs rw, userquota, groupquota 2 2
/Dev/ad0s1e/tmp ufs rw 2 2
/Dev/ad0s1g/usr ufs rw 2 2
/Dev/ad0s1f/var ufs rw 2 2
/Dev/acd0c/cdrom cd9660 ro, noauto 0 0
Proc/proc procfs rw 0 0



After setting the fstab file, run the following command to open quota

# Quotacheck-av
# Repquota-

Basically all the work in the early stage has been completed, and the rest is to edit the user quota.

Edit user quota
# Edquota c4st will edit the user's c4st quota settings. A Text Editor interface is displayed:

Quotas for user c4st:
/Pub: kbytes in use: 3438, limits (soft = 100000, hard = 100020)
Inodes in use: 25, limits (soft = 25, hard = 26)

We can see that the settings are divided into two rows.
Kbyters in use: 3438 indicates that the 3438kb limits limit has been used (soft = 100000 soft limit 100 M, hard = 100020 hard limit)
Soft indicates a warning when this value is reached, and hard indicates the actual size that users can use.
Inodes in use: 25, limits (soft = 25, hard = 26) can have a limit on the number of files. Of course, the value given in the example is not practical,
You can create only 26 files. In actual application, you can adjust the inodes value as needed. For example, you need to install a text library-based program, such as lb5000 (A webbbs ),
For some cgi Article management systems, do you need to adjust hard settings of inode appropriately?

Common quota commands
# Edquota-t specifies the time before the use of soft limits on quota users. days, hours, minutes, or seconds can all be the units set here, and the value can be reasonable.

Time units may be: days, hours, minutes, or seconds
Grace period before enforcing soft limits for users:
/Pub: block grace period: 1 day, file grace period: 1 day

# Repquota-a reports information about the file system quota.

Block limits File limits
User used soft hard grace
Wheel -- 2 0 0-1 0 0-
Operator -- 128 0 0-2 0 0-
Mysql -- 18 0 0-9 0-
Vhostuser -- 36164 100000 100050-342 1000 1005-

Block limits File limits
User used soft hard grace
Root -- 9136 0 0-12 0 0-
Mysql -- 18 0 0-9 0-
Testmin -- 18 1000 1050-9 1000 1005-
Web -- 22152 0 0-122 0-
Coms_cn -- 1550 0 0-177 0 0-
C4st-+ 3438 100000 100020-25 25 26



# Quota: displays the user's disk usage and upper limit.
-G: displays the group quota of the user's group.
-L do not display the quota on the NFS System
-U Display User quota
-Q: The brief information about the usage exceeding the quota is displayed.
-V check the user's quota settings

# Edquota-p test c4st c4st1 c4st2 .....
Copy the user test quota settings to user c4st c4st1 c4st2 .....

# The quotacheck-a command can be periodically executed to check whether all settings are normal (which can be executed in crontab ).

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.