Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Disk Management for getting started with Linux (6) disk quota

2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Disk Management for getting started with Linux (6) disk quota

When saving data to disk in linux, if there are multiple users operating on the same disk, and one of them put a very big data file which causes the hard disk capacity to be used up, then other users will no longer be able to store data, then it is necessary to limit the size of data stored for each user. Linux provides a function of disk quota to achieve.

Initialize:

Add partition mount options: usrquota, grpquota

Initialize database: quotacheck command

Use the command

Enable or cancel quotas: quotaon, quotaoff

Direct compilation quota: edquota [username]

Case description:

Create a quota database

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

[root@mzf ~] # blkid / dev/sda5/dev/sda5: LABEL= "myhome" UUID= "97f71277-7b31-4bb6-ae0f-949cf8c18e6f" TYPE= "ext4"

# Mount and use it

[root@mzf ~] # mkdir / mnt/myhome [root@mzf ~] # mount / dev/sda5 / mnt/myhome/ [root@mzf ~] # df | grep 'myhome'/dev/sda5 2004852 3096 1896584 / mnt/myhome

# migrate the files under / home first

[root@mzf ~] # ls / home/hadoop mzf tom U1U2 [root@mzf] # mv / home/* / mnt/myhome/ [root@mzf] # ls / mnt/myhome/hadoop lost+found mzf tom U1U2

# then mount / dev/sda5 to the / home directory again and add disk quotas for users and groups

[root@mzf ~] # mount-L myhome-o usrquota,grpquota / home/ [root@mzf ~] # df | grep 'home'/dev/sda5 2004852 3288 1896392 1% / mnt/myhome/dev/sda5 2004852 3288 1896392 1% / home

# Uninstall the mount point under / mnt/myhome

[root@mzf ~] # umount / mnt/myhome/

# here we mount the specified user disk quota and group disk matching option again and add

[root@mzf ~] # mount | grep 'home'/dev/sda5 on / home type ext4 (rw,usrquota,grpquota)

# of course, you can also write / etc/fstab file to remount. For example, add content:

[root@mzf home] # cat / etc/fstab | grep'/ home'

# then check the partition and create a quota database file

[root@mzf home] # quotacheck-cgu / dev/sda5quotacheck: Cannot create new quotafile / home/aquota.user.new: Permission deniedquotacheck: Cannot initialize IO on new quotafile: Permission deniedquotacheck: Cannot create new quotafile / home/aquota.group.new: Permission deniedquotacheck: Cannot initialize IO on new quotafile: Permission denied

Resolution: this prompt indicates that there is no permission, which may be caused by the control of the selinux security mechanism enabled by default in the linux kernel. Here, we can disable it:

# check whether the current setlinux is enabled

[root@mzf home] # getenforceEnforcing# indicates that [root@mzf home] # setenforce 0 # has been enabled. Setting parameter 0 means disabling [root@mzf home] # getenforce # once again, it has been shown to disable Permissive.

# create the disk quota database file again

[root@mzf home] # quotacheck-cug / dev/sda5

# check whether disk quota database files are generated under the specified partition's separate mount point directory

[root@mzf home] # ls / home | grep'^ aquota\.\ 'aquota.groupaquota.user

Note: if you want to enable disk quota, the kernel module must check whether there is a disk quota database file in the mount point, otherwise it cannot be enabled or set successfully.

Enable disk quotas:

# enable disk quota for specified partition

[root@mzf home] # quotaon / dev/sda5

# add default disk quota members

[root@mzf home] # edquota-p mzf tom hadoop

# set specified member quota

[root@mzf home] # edquota hadoop

# enter the vim editing interface

Parsing: the first line indicates which user to set the disk quota, the following is divided into multiple columns, the first column is the specified file system, and the last 6 columns are listed in a group of 3. Blocks indicates the file size that has been stored, the default is kmaine indodes, indicates how many files have been created, soft indicates a soft limit, and the storage size exceeds the soft specified will be alerted, and hard is a hard limit. If this limit is reached, the data will not be written again.

# set quota by file size, with soft limit of 5m and hard limit of 10m

# switch to hadoop users who set quotas

[root@mzf home] # su-hadoop

# 64K has been used in this directory. Here we add 5m data.

[hadoop@mzf ~] $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.2MB) copied, 0.130323 s, 40.2 MB/s

Note: here the soft has been exceeded, and the alarm starts to show the user block data quota, but if you use echo to do some small-scale data appending, the disk quota will not be alerted:

# shows how many bytes of the file

[hadoop@mzf] $ls-l / home/hadoop/temp.log-rw-rw-r--. 1 hadoop hadoop 5242912 Aug 17 23:51 / home/hadoop/temp.log

# append bytes

[hadoop@mzf ~] $echo "*" > > / home/hadoop/temp.log

# once again, the size has been increased, but the disk quota is not alerted

[hadoop@mzf] $ls-l / home/hadoop/temp.log-rw-rw-r--. 1 hadoop hadoop 5242928 Aug 17 23:51 / home/hadoop/temp.log

Parsing: if it is impossible to write 5m to the temp.log file with the dd command, then write a new 5m file to test:

# create another 5m, then it should have reached 10m

[hadoop@mzf ~] $dd if=/dev/zero of=/home/hadoop/temp2.log bs=5M count=1sda5: write failed, user block limit reached.dd: writing `/ home/hadoop/temp2.log': Disk quota exceeded1+0 records in0+0 records out5185536 bytes (5.2MB) copied, 0.00903 s, 574MB/s

Parsing: a write data error has been shown here, and the block quota has been used up

# at this time, files that write one byte of content cannot be written.

[hadoop@mzf ~] $echo "1" > file1-bash: echo: write error: Disk quota exceeded

Other disk quota management tools

Quota to view quota information

[root@mzf 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

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

Requota # View specified information

Warnquota # check warning

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report