File system disk quota management ---

1.1 Introduction disk quotas

Linux disk quota system is to limit specific users or groups of ordinary consume disk space or the number of files on the specified partition.

note:

  1. Limit of users and user groups can only ordinary users and groups that do not superuser root disk quotas.

  2. The disk quota restrictions only for the partition, but not for a directory.

  3. The user can limit the size of the disk capacity is occupied, of course, it allows the user to limit the number of files occupy.

Conditions for the use of disk quota

  1. The kernel must support the disk quotas. Centos7.3 version of linux disk quota support by default. Check to see if the kernel configuration file can support disk quotas. Command is as follows:

[root@andy ~]# grep CONFIG_QUOTA /boot/config-3.10.0-514.el7.x86_64
CONFIG_QUOTA=y
CONFIG_QUOTA_NETLINK_INTERFACE=y
# CONFIG_QUOTA_DEBUG is not set
CONFIG_QUOTA_TREE=y
CONFIG_QUOTACTL=y
CONFIG_QUOTACTL_COMPAT=y
[root@andy ~]#

  2. The quota system must be installed on the tool, install the view command as follows:

installation

[root@andy ~]# yum install quota -y

View

[root@andy ~]# rpm -qa | grep quota
quota-nls-4.01-19.el7.noarch
quota-4.01-19.el7.x86_64
[root@andy ~]#

  3. To support the partition disk quota, disk quota feature must be turned on manually turned on, the following talk

1.2 Disk Quota common concept

  1. user quotas and group quotas

User quotas means for the user's personal quota and group quota means the quota for the entire user group. If we limit the small number of users, you can specify quotas for each user individually.

If more users, the user can join a user group, and then specify a quota to a group.

note:

Users in the group, is shared space, or the number of files, first-served basis.

  2. File and disk capacity constraints limit the number of

In addition we can restrict user available disk capacity by limiting the number of available block users also can limit the number of users by inode limit the number of users can upload or create a new file.

  3. soft and hard limits

Soft limit we can be understood as a warning limit, hard limit is the real limit. For example, the provisions of the soft limit is 100M, the hard limit is 200M, then, when the disk space used by the user when to 100M ~ 200M, users can continue to upload and create a new file,

But every time the landing will receive a warning message telling the user's disk is nearly full.

  4. grace period

If the number of occupied space between users in soft and hard limits, then the system will warn the user when the user logs disk will be full, but that a warning would not have been carried out, but there is a time limit of this time is the grace period, default 7 days.

If you reached this time, the user disk usage still exceeds the soft limit, the soft limit will be upgraded to a hard limit. That is, if the soft limit is 100M, hard limit to 200M, grace period of 7 days at which time the user takes up 120M so the next 7 days

User warning every time a disk is nearing full landing, if the user is ignored, then after 7 days the user will become a hard limit 100M instead of 200M.

1.3 disk quota implementation process

  Experimental plan

1. disk quotas to limit the number of files and disk space on the partition ordinary users are using, you need to specify a partition, then we manually created / dev / sdb1 a 5GB partition, and mount it to the / disk directory which

2. We need to create users and user groups is limited. Suppose you want to limit lamp1, lamp2, and lamp3 users, three users belong to the user group brother

Hard disk capacity 3.brother group is limited to 500MB, the soft limit is 450MB, the number of files is not limited. lamp1 hard disk capacity limit set to 50M, the soft limit is 40M, the number of files is limited to 10, the soft limit is 8, and LAMP2

lamp3 user's hard disk capacity is limited to 250M, 200M soft limit is no limit to the number of files.

4.lamp1, lamp2 and lamp3 user's hard disk capacity is limited to 550M, exceeding the group of hard disk capacity brother limit 500M. As a result, a user may not reach their user limit, while it can not reach the set limit then write

The data, that is, if the user sets limits and restrictions exist, then the restrictions which small, which is given preference.

5. The system of grace period of 8 days

  Pilot deployment

1. To establish the quota specified partition

Adding a hard disk partition a primary fdisk separated 5G sdb1 size and mkfs formatted using the system is mounted xfs / disk

[root @ andy ~] # df -hT
file system type with capacity has been available by the mount point%
/ dev / Mapper / Cl-12 is the root XFS%. 17G 16G 2.0G /
devtmpfs devtmpfs 902M 0 902M 0% / dev
tmpfs tmpfs 0% 0 912M 912M / dev / SHM
tmpfs tmpfs 912M 904M. 1% 8.6 M / RUN
tmpfs tmpfs 912M 0 912M 0% / SYS / FS / a cgroup
/ dev / sda1 XFS 139M 876M 14% of 10-14m / Boot
tmpfs tmpfs 183M 0 0 183M % / RUN / User / 0
/ dev / sdb1 XFS 33M 5.0G 5.0G. 1% / Disk
/ dev / ISO9660 SR0 4.1G 4.1G 0 100% / mnt
[Andy the root @ ~] #

2. Set up users and groups need to be restricted

Command is as follows:

[root @ andy ~] # groupadd the Brother
[root @ andy ~] # useradd -G the Brother LAMP1
[root @ andy ~] # useradd -G the Brother LAMP2
[root @ andy ~] # useradd -G the Brother LAMP3
[root @ andy ~ ] # echo "123" | passwd --stdin lamp1
change a user's password lamp1.
passwd: all authentication tokens have been successfully updated.
[root @ andy ~] # echo "123" | passwd --stdin lamp2
change a user's password lamp2.
passwd: all authentication tokens have been successfully updated.
[root @ andy ~] # echo "123" | passwd --stdin lamp3
change a user's password lamp3.
passwd: all authentication tokens have been successfully updated.
[root @ andy ~] #

3. Open the disk quota feature in the partition

If the temporary turn, can be used as a command to turn on / disk partition the disk quota feature. Command is as follows:

[root@andy ~]# mount -o remount,usrquota,grpquota /disk
[root@andy ~]#

# Remount / disk, disk quota feature and add users and user groups

note:

  1. If a command to open the way disk quota feature, then only take effect in this boot, once the system is restarted, this function will fail

  2. Open the disk quota feature parameters are usrquota and grpquota

Use command to temporarily mount the partition, the system will synchronize update / etc / mtab file

/ Etc / mtab and / etc / fstab file the difference between these two

/ Etc / mtab file is recorded in the operating system has been mounted file system (partition), the virtual file system including the operating system build, so use this command is to modify file

/ Etc // fstab file recorded in the operating system is ready to mount a file system, which is after the next start will be mounted file system.

  So let the disk quota feature permanent, you need to modify / etc / fstab file commands are as follows:

[root@andy ~]# vim /etc/fstab

/dev/sdb1               /disk                   xfs     defaults,usrquota,grpquota   0  0

[root@andy ~]# mount -o remount /disk
[root@andy ~]#

# If you want to modify the configuration files to take effect, you must restart the system, otherwise it will need to re-mount the partition again

When modifying etc / fstab file must be careful, once the error correction is likely to cause the system to not start properly.

4. Set up a disk quota profile

This profile is not created by hand, but by the quotacheck command to scan established. quotacheck command scans the partition, view the partition for each user and user groups have occupied

The total number of files and disk space, and the scan results are recorded in the highest-level directory of the partition, and aquota.group aquota.user saved as a file, that is, we will make use of quotacheck

Command generates aquota.user (user quotas file) and aquota.group (group quota file) both disk quota configuration files, these two files are saved in the / disk directory as / disk is a separate partition, quotacheck

Command format is as follows:

quotacheck -avug

The quota set for users and groups

edquota

-u User name: set the user quota

-g Group name: set a group quota

-t set grace period

-p copy quota

6. Copy quota

edquota -p lamp2 -u lamp3 -p -u user source target user

7. Modify the grace period

edquota -t

8. Startup and Shutdown quota

Start command:

quotaon -avug

Close quota command:

quotaoff -a

9. query disk quotas

Query disk quotas, there are two methods: one is to use the quota command to query the user or group quotas, and the other method is to use the command to query quota repquota the entire partition.

quota

-u Username: query user quotas

-g Group name: Query group quotas

-s size display capacity, such as M, G customary units

-v Show Details

eg:quota -uvs lamp1

Another query method

repquota -augvs

Guess you like

Origin www.cnblogs.com/yzandy/p/12074290.html
Recommended