Linux Entry Disk Management (6) disk quotas

Source: Internet
Author: User

Linux Introduction to Disk Management (6) Disk Quotas

when storing data to disk in Linux, if more than one user is working on the same disk, and one of the files with large data causes the hard disk to run out of capacity, then other users will no longer be able to save the data, so the data size limit is required for each user. Linux provides a function of disk quotas to implement.

Initialization

Add partition Mount option: Usrquota,Grpquota

Initialize database: Quotacheck command

Using commands

Open or Cancel quotas: Quotaon,Quotaoff

Direct compilation quota: Edquota [username]

Case Description:

Create a quota database

The #/home directory will store the files of different users, the size will be affected each other , so you need to change the/home directory into a partition, where a partition to create a good file system is prepared.

[Email protected] ~]# blkid/dev/sda5/dev/sda5:label= "myhome" uuid= "97f71277-7b31-4bb6-ae0f-949cf8c18e6f" TYPE= " Ext4 "

#对其进行挂载使用

[[email protected] ~]# mkdir/mnt/myhome[[email protected] ~]# mount/dev/sda5/mnt/myhome/[[email protected] ~]# DF | grep ' myhome '/dev/sda5 2004852 3096 1896584 1%/mnt/myhome

Migrating Files #先将/home under Files

[[email protected] ~]# ls/home/hadoop mzf Tom U1 u2[[email protected] ~]# mv/home/*/mnt/myhome/[[email protected] ~ ]# ls/mnt/myhome/hadoop lost+found mzf Tom U1 U2

#然后将/dev/sda5 to the/home directory again, and add the disk quotas feature for users and groups

[[email protected] ~]# mount-l myhome-o usrquota,grpquota/home/[[email protected] ~]# DF |    grep ' Home '/dev/sda5 2004852 3288 1896392 1%/mnt/myhome/dev/sda5 2004852 3288 1896392 1%/Home

Mount point under the #卸载掉在/mnt/myhome

[Email protected] ~]# umount/mnt/myhome/

#这里我们再次挂载指定的用户磁盘配额和组磁盘配合选项以及添加

[email protected] ~]# Mount | grep ' home '/dev/sda5 on/home type EXT4 (Rw,usrquota,grpquota)

#当然也可以写入 the /etc/fstab file for re-mounting. For example, add content:

[Email protected] home]# Cat/etc/fstab | grep ' Home '

650) this.width=650; "src=" http://s2.51cto.com/wyfs02/M00/86/9E/wKiom1fFdAqiYTfFAAAq5P9gH6k723.jpg "title=" Fstab " alt= "Wkiom1ffdaqiytffaaaq5p9gh6k723.jpg"/>

#然后检查分区并创建配额数据库文件

[Email protected] home]# Quotacheck-cgu/dev/sda5quotacheck:cannot Create new Quotafile/home/aquota.user.new:permiss Ion Deniedquotacheck:cannot initialize IO on new quotafile:permission deniedquotacheck:cannot Create new Quotafile/hom E/aquota.group.new:permission Deniedquotacheck:cannot Initialize IO on new quotafile:permission denied

Parsing: This prompt does not have permissions, it is possible that the Linux kernel has the default enabled SELinux security control, which we can turn off first:

#查看当前setlinux是否开启

[[email protected] home]# getenforceenforcing# says [[email protected] home]# setenforce 0 #设置参数为0表示禁用 [Email Pro Tected] home]# Getenforce #再次查看已经显示为禁用Permissive

#再次进行磁盘配额数据库文件创建

[Email protected] home]# QUOTACHECK-CUG/DEV/SDA5

#查看指定分区单独挂载点目录下是否生成了磁盘配额数据库文件

[Email protected] home]# Ls/home | grep ' ^aquota\.\<\ (user\|group\) \> ' Aquota.groupaquota.user

Note: If you want to turn on disk quotas, the kernel module must check if there is a disk quota database file in the mount point that cannot be turned on or set successfully.

To enable disk quotas:

#开启指定分区的磁盘配额

[Email protected] home]# QUOTAON/DEV/SDA5

#添加默认磁盘配额成员

[Email protected] home]# edquota-p mzf Tom Hadoop

#设置指定成员配额

[Email protected] home]# Edquota Hadoop

#进入vim Editing interface

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/86/9E/wKioL1fFdSCgfTvJAAAjlFnaYRM067.jpg "title=" Edquota.jpg "alt=" Wkiol1ffdscgftvjaaajlfnayrm067.jpg "/>

Resolution: Where the first line represents which user sets the disk quota, which is divided into multiple columns, the first column is the specified file system,each of the following 6 columns3listed as a group,blocksindicates the size of the file that is already stored, by defaultk,Indodesis expressed as how many files have been created,Softrepresented as soft limit, storage size more thanSoftspecifies that an alert will appear, Hardas a hard limit, the data cannot be written again if this limit is reached.


#按文件所占大小设置配额 with a soft limit of 5Mand a hard limit of 10M

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M01/86/9E/wKioL1fFdXyQ7XCYAAAj29Phc2g997.jpg "title=" Edquota2.jpg "alt=" wkiol1ffdxyq7xcyaaaj29phc2g997.jpg "/>

#切换到设置配额的成员Hadoop users

[Email protected] home]# Su-hadoop

#此目录已经用了64K, here we add 5M data

[email protected] ~]$ dd If=/dev/zero of=/home/hadoop/temp.log bs=5m count=1sda5:warning, user block quota exceeded.1+0 Records in1+0 records out5242880 bytes (5.2 MB) copied, 0.130323 s, 40.2 MB/s

Note: Here the soft has been exceeded, the alarm is started, the user block data quota is displayed, but if you use echo to do some small-scale data append, disk quotas are not alerted:

#显示出文件多少个字节

[Email protected] ~]$ ls-l/home/hadoop/temp.log-rw-rw-r--. 1 Hadoop Hadoop 5242912 23:51/home/hadoop/temp.log

#追加字节

[Email protected] ~]$ echo "***************" >>/home/hadoop/temp.log

#再次显示大小已经增加, but disk quotas do not have an alert

[Email protected] ~]$ ls-l/home/hadoop/temp.log-rw-rw-r--. 1 Hadoop Hadoop 5242928 23:51/home/hadoop/temp.log

Parse: If the DD command to write to the temp.log file 5M is not writable, then write a new 5M file to test:

#再创建一个5M, you should have reached 10M .

[[email protected] ~]$ dd If=/dev/zero of=/home/hadoop/temp2.log bs=5m Count=1sda5:write failed, user block limit Reache D.dd:writing '/home/hadoop/temp2.log ': Disk quota exceeded1+0 Records in0+0 records out5185536 bytes (5.2 MB) copied, 0.0 0903 s, 574 MB/s

Parsing: The Write data error has been shown here and the block quota has been used

#这时写入一个字节内容的文件都写入不了了 .

[Email protected] ~]$ echo "1" > File1-bash:echo:write error:disk quota exceeded

Additional disk quota management tools

Quota Viewing quota information

[[email protected] home]# Quota hadoopdisk quotas for user Hadoop (UID 502): Filesystem blocks Quota limit Grace Files Quota limit grace/dev/sda5 10240* 5120 10240 6days 17 0 0

Resolution: Grace is expressed as grace period, and the file size to soft specified size 6 days later,soft will become a hard limit, will no longer be able to create files and write data.

Requota # View specified information

Warnquota # Check for warnings

This article is from the "Excalibur Trunks-kun" blog, please be sure to keep this source http://mengzhaofu.blog.51cto.com/10085198/1844491

Linux Entry Disk Management (6) disk quotas

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.