Linux disk quota experiment

Source: Internet
Author: User
Tags disk usage inode usage

1. conditions for implementing disk quotas
* requires Linux kernel support
* Install quota package
2.features of Linux disk quotas
Scope: for the specified file system (partition)
restricted objects : Normal user accounts, group accounts
Restriction type: disk capacity (default is KB), number of files
Restriction methods: soft limit, hard limit
3.quota limitations on file systems are mainly divided into: capacity limit or file number limit
Limit inode usage: is the number of files that users can create
Limit block usage: The amount of disk capacity that users can use, and more common ways to restrict it

-------------------------------------------------------------------------------

Note:

The disk quota's record file is saved under the root directory of the disk quota partition, they are aquota.user and aquota.group;
Disk quotas are valid only for general-identity users and are not valid for root-privileged users

Minimum limit (soft limit, soft): Minimum limit capacity (can be exceeded, but warning will appear, excess portion will be saved to grace time expires);
Maximum limit (hard limit): limits that cannot be exceeded;
Grace time: When the user uses more space than the minimum limit, but has not reached the maximum limit, before the expiry of this grace period must be reduced to the minimum limit (the default is 7 days), when the grace period expires, the system will automatically clear the excess data;
===========================================

Lab Environment:

Linux RedHat 6.5

Set selinux=disabled

Previous configuration section

1. New user, set password

Useradd Losnau Echo " Losnau " | passwd Losnau--stdin

2. Create a logical partition and format the Ext4 file system

Fdisk/dev/sdb
Mkfs.ext4/dev/sdb1

4, create hang in directory, and modify permissions 777, you can let other users have all permissions

mkdir /publicchmod777 /public

5. Create file to hang at point

Method 1) Edit the/etc/fstab

Echo " /dev/sdb1               /public                 ext4    defaults,usrquota,grpquota      0 0"  >>/etc/ Fstab
#第一个字段为被挂载的分区,第二个字段为挂载的目录,第三个字段是被挂载的分区的文件系统类型,后面的几个字段是支持quota的参数。各字段用空格分隔
Mount -a #读取/etc/fstab, re-hung in effect, or reboot is OK

Method 2) Manually mount it Yourself

Mount -o remount,usrquota,grpquota/public #立即生效

Mount grep /dev/sdb1. #只要括号里面显示 "usrquota,grpquota"/dev/sdb1 on/  ls  /public#看到目录下有lost+found This directory is a success.

6. Use the Quotacheck command to generate a database file that configures the disk configuration

#若selinux Open will prompt insufficient authority, by Setenforce 0 temporarily shut down SELinux can be

#创建磁盘配额配置文件, the command parameters are interpreted as follows:
#-v display scanning process;
#-u set up Aquota.user for scanning situation and the use of catalogue;
#-g to the user scan files and use of the establishment of Aquota.group;

Quotacheck-vug/public
Ls/public
#Quotacheck executed successfully you can see that there are two more files under/public/.

7.配置losnau用户使用/dev/sdb1分区的限额

Edquota-u Losnau

#: Wq Edit Save Exit

Explain the above actions:
#输入上面的命令后, it will go into a VI editing interface
#对其中各字段解释如下:
#Filesystem下显示实现磁盘配额的分区;
#blocks下为当前已经使用的大小, without modification;
#soft为软限制, the warning will be given after exceeding, and the excess portion will be saved for 7 days by default;
#hard为硬限制, the limit is not exceeded (the default unit for soft and hard limits is KB);
#后面的两个相同的soft, hard, respectively, indicates the number of files that the user can create in the partition.
#本例中设置, Qingsword can use/DEV/SDB1 partition soft limit size 10KB, hard limit 20KB, the number of files can be created soft limit is 3, hard limit of 5;
Disk quotas for user Qingsword (UID 500):
Filesystem blocks soft hard inodes soft hard

8. Turn on disk quotas for this partition

Quotaon/public #挂在点看你前面做了什么操作, can be modified by itself
Note: To configure additional users, refer to step 7th Test section

======================= Test disk usage Quota =========================

su Losnau #进入/dev//public

#使用dd命令进行文件写入测试,
# If=/dev/zero means output from "/dev/zero" file, of=/public/testfile1 means input into "/public/testfile1" file, that is, read the garbage data from the/dev/zero file to write/ Public/testfile1 in this document;
# bs=1k indicates that the size of a read write is 1kb,count=12 to read 12 times;
The data for the #所以理论上最后写入/sdb1/testfile1 should be 12KB.

DD if=/dev/zero of=/public/testfile1 bs=1k count=  #因为针对qingsword用户在这个分区的软限制设置是10KB, So here's a warning message.
DD if=/dev/zero of=/public/testfile3 bs=1k count=  #出现了一个警告, and only 8K of data is copied below, this is because the hard limit we set is 20KB
#第一个文件已经占用了12KB的数据, the second file only writes 8KB data, the hard limit cannot be exceeded, and the soft limit 10KB can be exceeded, beyond the data, will be saved in this partition by default for 7 days, and then the system will automatically delete the data

======================= number of test files limit =========================
#, as described in the previous introduction and our configuration, the soft limit of more than 3 files will give a warning, and cannot exceed the hard limit of 5 files, use touch to create an empty file
Create empty file omit ....
#超过3个文件时出现了警告
Create empty file omit ....
#touch第6个文件的时候提示创建失败
#超过文件数量软限制的部分同样会被保存7天 and then automatically deleted by the system
#查看当前用户的磁盘配额使用情况, the two exceeded configurations are file size and number of files, and grace time is 6 days

Quota-vugs #dev/sdb1    20k*  10K  20K   6days   5*    3     5 -T    
Turn off disk quotas
    #关闭单个磁盘的磁盘配额   /public    #关闭所有已经开启的磁盘配额   -a    #反之, turn on all disk quotas  -A    #如果不再使用磁盘配额, you can also delete  the configuration file rm -rf/public/aquota.*    #最后删除/ Automatic mounting in the Etc/fstab

Linux disk quota experiment

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.