This is my first time to write a blog, if there is any wrong place or the wrong place, please do not hesitate to enlighten!!!
First, the concept of disk quotas
Because Linux is a multi-user managed operating system, Linux by default does not limit the size of disk space per user, if a user inadvertently or maliciously occupied disk space, will cause the system disk can not write or even crash, in order to ensure that the system disk has enough space, We need to restrict the use of disk space to users and groups.
Disk quota limit Type:
1. Limit the amount of disk space users and groups use
2. Limit the number of files that users and groups create on disk
Disk quota limit level:
- Soft limit: Low limit, this limit can be broken, the breakthrough will be warned, the excess will have a grace days, the grace period expires after the part is emptied, soft limit can not exceed the hard limit
- Hard limit: Absolute limit, this limit will not be breached, no more space can be used after the specified limit is reached
- Grace Days: When there is more data than soft limit, the excess will be timed, the grace period expires after the partial data will be emptied, the grace days default is 7 days
Note: Disk quotas are set for partitions and cannot be implemented "a user can only use 50MB of disk space in a system" only to set a limit where a user can use 30M in the/home partition. Remember: Disk quotas are for partitions!
Second, disk quota open conditions
Does the kernel support disk quotas?
#grep "Config_quota"/boot/config-2.6.32-431.el6.x86_64
are disk quota-related commands installed?
#rpm –q Quota
Three, the disk quota experiment plan
Prepare partitions of sufficient size, much larger than the experimental space of need
Create experimental users and groups
Users: CJ, BD, XZ,
Group: Thot
Disk quota Planning
Thot: Hard: 500M soft: Unlimited number of 450M files
CJ: Hard: 50M soft: 40M Hard: 10 Soft: 8 x
BD: Hard: 250M soft: Unlimited number of 200M files
XZ: Hard: 250M soft: Unlimited number of 200M files
Grace days modified to 8 days
Iv. disk Quota Experiment Flow
- To see if the system supports disk quotas
#grep "Config_quota"/boot/config-2.6.32-431.el6.x86_64
2. See if the Mount properties of the partition meet
DUMPE2FS–H/DEV/SDB1 | grep "Default mount Options"
See if the results contain Usrquota, Grpquota two mount properties?
If you do not have two mount properties, you will need to mount and add two properties and write an automatic mount
3. Create partitions, users, user groups
The partition size is much larger than the size of the experiment and avoids affecting the experimental results
Users: CJ, BD, XZ
Group: Thot
Note: When creating a user, specify Thot as the initial group
4. Generating profiles for users and groups
Quotacheck option Partition Name
-A scans all partitions in the/etc/mtab file that have the disk quotas feature enabled. If you add this parameter, you do not need to add a partition name after the command
-U establishes a profile for user quotas, that is, generates Aquota.user
-G Establish a configuration file for group quotas, that is, Aquota.group
-V shows the scanning process
-C Clear the original configuration file, re-establish the new configuration file
Note: If the error does not have permission to generate files, you need to close SELinux
5. Edit the configuration file, set the specified limit size
Edquota option user name or group name
-U user Name
-G Group Name
-T set wide time limit
-P Copy Disk quota rules, do not need to set each user or group manually once
# edquota-p Template user-u target user
Note: The write size in the configuration file is the default unit KB
6. Start and close disk quotas
Start:
Quotaon option Partition Name
-a disk quota for all partitions (not write partition name) based on the/etc/mtab file
-U start user's disk quota
-G Boot Group disk quotas
-V Displays startup process information
Shut down:
Quotaoff option Partition Name
-a disk quota for all partitions is closed according to the/etc/mtab file (no partition name is written)
-U shuts down the user's disk quotas
-G disk quotas for closed groups
-V Displays startup process information
7. View the disk quota information
To query quotas for a specified user and group:
Quota option user or group name
-U user Name
-G Group Name
-V Show More information
-s display size in common units
8. Query the disk quotas for the specified partition:
Repquota option Partition Name
-U Query user quotas
-G Query Group quotas
-V Show Details
-s displays in common units
9. Verify that disk quotas are in effect
Switch to the execution user to create the file as a preset user (SU)
Test tools:
DD generates a file of the specified size (the DD command is detailed in the attachment)
DD If=/dev/zero of=/partition name/testfile bs=1m count=60
Note: The user's test needs to switch to the specified user identity, while the group disk quota verification is required?
10. Non-interactive Set disk quotas
Setquota-u User name Soft (capacity) hard (capacity) soft (number) hard (number) partition name
Note: Similarly, such non-interactive commands are more suitable for writing scripts, and can be implemented with replication if a large number of users have the same disk quota configuration.
"Linux"--Advanced file System Management