CentOS summary and practices on quota
1. Theoretical Basis
1.1 concepts of Quota
Quota refers to the Quota, which is used to limit the space used by users, groups, and folders.
1.2 usage examples
-The web server controls the available space of the site.
-The mail server controls the user's available space.
-The file server controls the size of the user's available space.
1.3 restricted mode
-Control the available space size of each user based on the user (UID)
-Control the available space size of each group based on the group (GID)
-Control the available space of each directory based on directory (project) (xfs available project mode)
1.4 conditions of use
-Only file systems can be restricted in EXT format, and projects can be restricted in xfs format.
-The kernel must be pre-enabled for Quota support
-Quota is only valid for non-administrators.
-By default, Quota is only enabled for/home, And SELinux needs to be configured for others.
1.5 restricted configurable objects
-User, Group, and project)
-Capacity limit or file quantity limit (block/inode)
-Restricted values: soft (warning and extended time for exceeding the space usage) and hard (the user's right to use is denied if the space usage is exceeded)
-Grace time: the amount of space exceeds the soft limit and the processing time limit is not reached. (The soft value becomes hard)
2. Actual Operation
2.1 preparations before configuration
2.1.1 create a user group
groupaddgp1
2.1.2 add group members
useradd
-ggp1user1
echo
"pwd1"
|
passwd
--stdinuser1
useradd
-ggp1user2
echo
"pwd1"
|
passwd
--stdinuser2
2.1.2 create a user directory and change all Groups
mkdir
/home/gp1
chgrp
gp1
/home/gp1
chmod
2770
/home/gp1
2.1.2 check the file system type
df
-hT
/home
Shown as follows:
FilesystemTypeSizeUsedAvailUse%Mountedon
/dev/mapper/centos-home
xfs5.0G67M5.0G2%
/home
2.2 enable the file system's quota Function
2.2.1 edit fstab
vim
/etc/fstab
The modification content is as follows:
/dev/mapper/centos-home
/home
xfsdefaults,usrquota,grpquota00
Note:
-User (uquota/usrquota/quota)
-Group (gquota/kgquota)
-Directory (pquota/prjquota)
2.2.2 uninstall and re-mount
umount
/home
mount
-a
2.2.3 check
mount
|
grep
home
Shown as follows:
/dev/mapper/centos-home
on
/home
type
xfs(rw,relatime,seclabel,attr2,inode64,usrquota,grpquota)
2.3 check Quota Information
2.3.1 Command Format
xfs_quota-x-c
"Sub-commands"
[Mount point]
Option:
-X: EXPERT mode.-c can be used only when-x is used.
-C: Sub-Command Options
Sub-command:
Print: list the current system parameters.
df
: Similar
df
The options include-B (block)-I (inode)-h (plus a single bit) and so on.
Report: List
quota
Project, including-ugr (user
/group/project
) And-bi
State: List currently supported
quota
File System Information and Related startup items
2.3.2 query partitions that support Quota
xfs_quota-x-c
"print"
2.3.3 query the usage of the Quota directory
xfs_quota-x-c
"df-h"
/hom
2.3.4 display the user's Quota restrictions
xfs_quota-x-c
"report-ubih"
/home
Note: The "-u" parameter is displayed for the project"
2.4 configuration restrictions
2.4.1 command format:
xfs_quota-x-c
"limit[-ug]b[soft|hard]=Ni[soft|hard]=Nname"
xfs_quota-x-c
"timer[-ug][-bir]Ndays"
Option:
Limit: Restricted object, including user
/group/project
bsoft
/bhard
: Block soft
/hard
Limit Value
isoft
/ihard
: Inode soft
/hard
Limit Value
Name: user and group name
Timer: grace
time
)
2.4.2 user and block size restrictions
xfs_quota-x-c
"limit-ubsoft=250Mbhard=300Muser1"
/home
xfs_quota-x-c
"limit-ubsoft=250Mbhard=300Muser2"
/home
Check Configuration:
xfs_quota-x-c
"report-ubih"
/home
2.4.3 group and block size restrictions
xfs_quota-x-c
"limit-gbsoft=950Mbhard=1Ggp1"
/home
Check Configuration:
xfs_quota-x-c
"report-gbih"
/home
2.4.5 configure the grace period
xfs_quota-x-c
"timer-ug-b14days"
/home
Verify Configuration:
xfs_quota-x-c
"state"
/home
2.4.6 verify Quta
su
-user1
dd
if
=
/dev/zero
of=123.imgbs=1Mcount=310
ll-h
exit
xfs_quota-x-c
"report-ubh"
/home
2.5 project restrictions
2.5.1 modify fstab
vim
/etc/fstab
2.5.2 Unmount and remount
umount
/home
mount
-a
2.5.3 check canceled
xfs_quota-x-c
"state"
2.5.4 create a project storage location
mkdir
/home/proj01
2.5.5 specify the project identification number
echo
"01:/home/proj01"
>>
/etc/projects
2.5.6 specify the project name and associate it with the Project Identification Number
echo
"proj01:01"
>>
/etc/projid
2.5.7 initialize the project name
xfs_quota-x-c
"project-sproj01"
Check Configuration:
xfs_quota-x-c
"print"
/home
xfs_quota-x-c
"report-pbih"
/home
2.5.8 configure the limit based on the block size
xfs_quota-x-c
"limit-pbsoft=450Mbhard=500Mproj01"
/home
Check Configuration:
xfs_quota-x-c
"report-pbih"
/home
2.5.9 Verify Configuration
dd
if
=
/dev/zero
of=
/home/myquota/123
.imgbs=1Mcount=510
2.6 Quota Management
2.6.1 temporarily disable the Quota restriction
xfs_quota-x-c
"disable-up"
/home
Check disabled:
xfs_quota-x-c
"state"
/home
Disable Verification:
dd
if
=
/dev/zero
of=
/home/user1/123
.imgbs=1Mcount=520
Check the Quota status:
xfs_quota-x-c
"report-pbh"
/home
Clear test files:
rm
-rf
/home/user1/123
.img
2.6.2 temporary start of Quota restrictions
xfs_quota-x-c
"enable-up"
/home
Check Start:
dd
if
=
/dev/zero
of=
/home/user1/123
.imgbs=1Mcount=520
2.6.3 completely disable the Quota restriction
xfs_quota-x-c
"off-up"
/home
Close test:
xfs_quota-x-c
"enable-up"
/home
Close recovery:
umount
/home
;
mount
-a
2.6.4Delete the Quota limit (cannot be recovered)
xfs_quota-x-c
"off-up"
/home
xfs_quota-x-c
"remove-p"
/home
Verify deletion:
xfs_quota-x-c
"report-phb"
/home
2.7 implement Quota using soft connections
1) enable the/home partition's Quota Function
Edit fstab
vim
/etc/fstab
The modification content is as follows:
/dev/mapper/centos-home
/home
xfsdefaults,usrquota,grpquota00
2) create a soft connection to the Quota Partition
ln
-s
/home/mail
/var/spool/mail
-------------------------------------------------------------
See documentation
-------------------------------------------------------------
Http://linux.vbird.org/linux_basic/0420quota.php
Http://www.centoscn.com/CentOS/config/2013/1103/2043.html
Http://www.jb51.net/ OS /RedHat/400503.html