In the work of network management, due to the limited resources of hard disk, it is often necessary to set Linux disk quota for multi-user servers. This function is necessary for public multi-user servers (free or charged). Quota is a tool to realize Linux disk quota under red hatlinux. Quota only supports a separate mount file system, not a directory.
1. Mount the directory and add quota
View the / home directory mount
The code is as follows:
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 2.0G 35M 1.8G 2% /home
The code is as follows:
/dev/sda3 on /home type ext4 (rw)
User and group quota file system support parameters: usrquota, grpquota
The code is as follows:
Check to make sure that usrquota and grpquota are added
The code is as follows:
/dev/sda3 on /home type ext4 (rw,usrquota,grpquota)
Edit the fstab file to mount quota when the system starts
The code is as follows:
LABEL=/home /home ext4 defaults,usrquota,grpquota 1 2
Re mount
The code is as follows:
[[email protected] ~]# mount -a
[[email protected] ~]# mount | grep home
2. Quota installation generates usrquota and grpquota directories
The file system with usrquota and grpquota parameters is scanned by quotacheck
The code is as follows:
-bash: command not found
The code is as follows:
Install quota
The code is as follows:
Automatically create two directories, usrquota and grpquota
The code is as follows:
-rw——- 1 root root 8192 Mar 6 11:58 /home/aquota.group
-rw——- 1 root root 9216 Mar 6 11:58 /home/aquota.user
At this point, because of some need, or in some situation, “have to” run this command:
The code is as follows:
It is necessary to make sure that the process of “reading and writing” is not in “write” mode. It is recommended to operate in single user mode.).
The code is as follows:
Launch quota
/dev/sda3 [/home]: group quotas turned on
/dev/sda3 [/home]: user quotas turned on
3. Quota limit size setting
Myquota1 account adds quota restriction. Here, the disk size used by each user is fixed to 500m
The code is as follows:
Filesystem blocks soft hard inodes soft hard
/dev/sda3 80 500000 600000 10 0 0
Copy myquota1 user information to myquota2
The code is as follows:
The code is as follows:
Edit the total used size of the myquotagrp group
Filesystem blocks soft hard inodes soft hard
/dev/sda3 160 10000000 12000000 20 0 0
The code is as follows:
Modify the grace time when the user file exceeds the size
The code is as follows:
Query usage
Filesystem blocks quota limit grace files quota limit grace
/dev/sda3 80 495M 595M 10 0 0
Disk quotas for user myquota2 (uid 501):
Filesystem blocks quota limit grace files quota limit grace
/dev/sda3 80 495M 595M 10 0 0
The code is as follows:
Query myquotagrp group usage
The code is as follows:
Filesystem blocks soft hard inodes soft hard
/dev/sda3 160 1000M 1200M 20 0 0
The code is as follows:
User used soft hard grace used soft hard grace
———————————————————————-
root — 20 0 0 2 0 0
myquota1 — 32 495M 595M 10 0 0
myquota2 — 32 495M 595M 10 0 0
myquotagrp — 64 1000M 1200M 20 0 0
Statistics:
Total blocks: 7
Data blocks: 1
Entries: 4
Used average: 4.000000
4. Quota test
Use the identity of myquota1 to build a large file of 550mb and observe the result of quota!
The code is as follows:
[[email protected] ~]# repquota -auv
Block limits File limits
User used soft hard grace used soft hard grace
———————————————————————-
myquota1 +- 556840 500000 600000 13days 11 0 0
You can find grace in myquota1!
Create another large file to make the total capacity more than 600m!
The code is as follows:
du -sk
600000. The file size has checked the set size. The operation failed
The code is as follows:
If you want to cancel the limit of disk space, you can use the following command, please see:
The code is as follows:
(remove the disk space limit.)
The code is as follows:
(start disk space limit now.)
Sorting out the basic usage of PS: quota command
grammar
quota [ -u [ User ] ] [ -g [ Group ] ] [ -v | -q ]
describe
The root user can use the – U flag with the optional user parameter to see the restrictions of other users. Users without root user rights can view the restrictions on the groups they belong to by using the – G flag with the optional group parameter.
Note:
If a particular user has no files on the file system for which it has a quota, the command displays quota: none for that user. When the user has files in the file system, the actual quota of the user is displayed.
sign
-G displays the quota for the user group.
-U displays the user quota. This flag is the default option.
-V shows the quota on a file system without allocated storage.
-Q print a brief message that contains only information about the use of file systems that exceed the quota.
Note:
-Take precedence over the flag.
Security
Access control: this command is owned by the root user and the bin group.
Privilege control: This program is setuid to allow non privileged users to view personal quotas.
Examples
(1) . to display the quota of user Keith, enter:
The code is as follows:
The system displays the following information:
User quotas for user keith (uid 502):
Filesystem blocks quota limit grace Files quota limit grace
/u 20 55 60 20 60 65
(2) . to display the quota of user davec as root, enter:
The code is as follows:
The system displays the following information:
User quotas for user davec (uid 2702):
Filesystem blocks quota limit grace files quota limit grace
/u 48 50 60 7 60 60
file
The code is as follows:
Specify user quota.
The code is as follows:
Specify group limits.
The code is as follows:
Contains the file system name and location.