关键词:
Linux CentOS 8(磁盘容量配额(Quota))
目录
一、项目介绍
本节将介绍Linux(Centos8)中的磁盘容量配额(Quota)。
二、相关概念
2.1 配额(Quota)的概念
磁盘配额是计算机中指定磁盘的储存限制,就是管理员可以为用户所能使用的磁盘空间进行配额限制,每一用户只能使用最大配额范围内的磁盘空间。在linux系统中,是多用户多任务的环境,所以会有很多人共用一个磁盘的情况。针对每个用户去限定一定量的磁盘空间是有必要的,这样才显得公平。
2.2 配额(Quota)的功能作用
磁盘配额可以限制指定账户能够使用的磁盘空间,这样可以避免因某个用户的过度使用磁盘空间造成其他用户无法正常工作甚至影响系统运行。在服务器管理中此功能非常重要,但对单机用户来说意义不大。quota命令还有软限制和硬限制的功能:
- 软限制:当达到软限制时会提示用户,但仍允许用户在限定的额度内继续使用。
- 硬限制:当达到硬限制时会提示用户,且强制终止用户的操作。
三、任务操作
任务1- quota的主要模块
1.1 安装quota软件
[root@localhost ~]# yum -y install quota //安装quota软件
Last metadata expiration check: 0:11:54 ago on Mon 26 Jul 2021 09:54:55 PM CST.
Dependencies resolved.
===========================================================================================
Package Architecture Version Repository Size
===========================================================================================
Installing:
quota x86_64 1:4.04-12.el8 BaseOS 213 k
Installing dependencies:
quota-nls noarch 1:4.04-12.el8 BaseOS 95 k
Transaction Summary
===========================================================================================
Install 2 Packages
Total download size: 307 k
Installed size: 1.1 M
Downloading Packages:
(1/2): quota-nls-4.04-12.el8.noarch.rpm 3.6 kB/s | 95 kB 00:26
(2/2): quota-4.04-12.el8.x86_64.rpm 7.9 kB/s | 213 kB 00:26
-------------------------------------------------------------------------------------------
Total 5.9 kB/s | 307 kB 00:52
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : quota-nls-1:4.04-12.el8.noarch 1/2
Installing : quota-1:4.04-12.el8.x86_64 2/2
Running scriptlet: quota-1:4.04-12.el8.x86_64 2/2
Verifying : quota-1:4.04-12.el8.x86_64 1/2
Verifying : quota-nls-1:4.04-12.el8.noarch 2/2
Installed:
quota-1:4.04-12.el8.x86_64 quota-nls-1:4.04-12.el8.noarch
Complete!
1.2 quota的主要模块
[root@localhost ~]# quota //tab键按两下
quota quotacheck quotaoff quotaon quotastats quotasync
1.3 查看“quota”的选项
[root@localhost ~]# quota -h
quota: Usage: quota [-guPqvswim] [-l | [-Q | -A]] [-F quotaformat]
quota [-qvswim] [-l | [-Q | -A]] [-F quotaformat] -u username ...
quota [-qvswim] [-l | [-Q | -A]] [-F quotaformat] -g groupname ...
quota [-qvswugPQm] [-F quotaformat] -f filesystem ...
-u, --user display quota for user
-g, --group display quota for group
-P, --project display quota for project
-q, --quiet print more terse message
-v, --verbose print more verbose message
-s, --human-readable display numbers in human friendly units (MB, GB...)
--always-resolve always try to translate name to id, even if it is
composed of only digits
-w, --no-wrap do not wrap long lines
-p, --raw-grace print grace time in seconds since epoch
-l, --local-only do not query NFS filesystems
-Q, --quiet-refuse do not print error message when NFS server does
not respond
-i, --no-autofs do not query autofs mountpoints
-F, --format=formatname display quota of a specific format
-f, --filesystem-list display quota information only for given filesystems
-A, --all-nfs display quota for all NFS mountpoints
-m, --no-mixed-pathnames trim leading slashes from NFSv4 mountpoints
--show-mntpoint show mount point of the file system in output
--hide-device do not show file system device in output
-h, --help display this help message and exit
-V, --version display version information and exit
Bugs to: jack@suse.cz
quota
命令常用选项,如表1所示。
表1 quota命令常用选项的用法
选项 | 说明 |
---|---|
-g | 显示某个组的限额 |
-u | 显示某个用户的限额 |
-v | 显示更多详细消息 |
-s | 选择inod或硬盘空间来显示 |
1.4 查看“quotacheck”的选项
[root@localhost ~]# quotacheck -h
Utility for checking and repairing quota files.
quotacheck [-gucbfinvdmMR] [-F <quota-format>] filesystem|-a
-u, --user check user files
-g, --group check group files
-c, --create-files create new quota files
-b, --backup create backups of old quota files
-f, --force force check even if quotas are enabled
-i, --interactive interactive mode
-n, --use-first-dquot use the first copy of duplicated structure
-v, --verbose print more information
-d, --debug print even more messages
-m, --no-remount do not remount filesystem read-only
-M, --try-remount try remounting filesystem read-only,
continue even if it fails
-R, --exclude-root exclude root when checking all filesystems
-F, --format=formatname check quota files of specific format
-a, --all check all filesystems
-h, --help display this message and exit
-V, --version display version information and exit
Bugs to jack@suse.cz
quotacheck命令常用选项,如表2所示。
表2 quotacheck命令常用选项的用法
选项 | 说明 |
---|---|
-a | 扫描所有已经mount的具有quota支持的磁盘 |
-u | 扫描某个使用者的文件以及目录 |
-g | 扫描某个组的文件以及目录 |
-v | 显示扫描过程 |
-m | 强制进行扫描 |
1.5 查看“edquota”的选项
[root@localhost ~]# edquota -h
edquota: Usage:
edquota [-rm] [-u] [-F formatname] [-p username] [-f filesystem] username ...
edquota [-rm] -g [-F formatname] [-p groupname] [-f filesystem] groupname ...
edquota [-rm] -P [-F formatname] [-p projectname] [-f filesystem] projectname ...
edquota [-u|g|-P] [-F formatname] [-f filesystem] -t
edquota [-u|g|-P] [-F formatname] [-f filesystem] -T username|groupname|projectname ...
-u, --user edit user data
-g, --group edit group data
-P, --project edit project data
-r, --remote edit remote quota (via RPC)
-m, --no-mixed-pathnames trim leading slashes from NFSv4 mountpoints
-F, --format=formatname edit quotas of a specific format
-p, --prototype=name copy data from a prototype user/group
--always-resolve always try to resolve name, even if it is
composed only of digits
-f, --filesystem=filesystem edit data only on a specific filesystem
-t, --edit-period edit grace period
-T, --edit-times edit grace time of a user/group
-h, --help display this help text and exit
-V, --version display version information and exit
Bugs to: jack@suse.cz
edquota命令常用选项,如表3所示。
表3 edquota命令常用选项的用法选项 | 说明 |
---|---|
-u | 编辑某个用户的quota |
-g | 编辑某个组的quota |
-t | 编辑宽限时间 |
-p | 拷贝某个用户或组的quta到另一个用户或组 |
1.6 查看“edquota”的选项
[root@localhost ~]# quotaon -h
quotaon: Usage:
quotaon [-guPvp] [-F quotaformat] [-x state] -a
quotaon [-guPvp] [-F quotaformat] [-x state] filesys ...
-a, --all turn quotas on for all filesystems
-f, --off turn quotas off
-u, --user operate on user quotas
-g, --group operate on group quotas
-P, --project operate on project quotas
-p, --print-state print whether quotas are on or off
-x, --xfs-command=cmd perform XFS quota command
-F, --format=formatname operate on specific quota format
-v, --verbose print more messages
-h, --help display this help text and exit
-V, --version display version information and exit
quotaon命令常用选项,如表4所示。
表4 quotaon命令常用选项的用法选项 | 说明 |
---|---|
-a | 全部设定的quota启动 |
-u | 启动某个用户的quota |
-g | 启动某个组的quota |
-s | 显示相关信息 |
quotaoff -a | 关闭全部的quota |
任务2- 磁盘配额的应用
假设现在我们要对jan16 这个用户对/public
目录的写入容量进行限制,具体:软限制:10KB 硬限制:20KB ;创建的文件数量软限制:3个 硬限制 5个
2.1 新建用户,设置密码
[root@localhost ~]# useradd jan16
[root@localhost ~]# echo 'jan16' |passwd jan16 --stdin
Changing password for user jan16.
passwd: all authentication tokens updated successfully.
2.2 创建一个2G的逻辑分区,并格式化为ext4文件系统
[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x5691659a.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-41943039, default 2048):
Last sector, +sectors or +sizeK,M,G,T,P (2048-41943039, default 41943039): +2G
Created a new partition 1 of type 'Linux' and of size 2 GiB.
Command (m for help): p
Disk /dev/sdb: 20 GiB, 21474836480 bytes, 41943040 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x5691659a
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 4196351 4194304 2G 83 Linux
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 524288 4k blocks and 131072 inodes
Filesystem UUID: 63795614-6fb9-4dcf-93a2-d14604e42858
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
2.3 创建挂载目录,并且修改权限777,让其他用户拥有所有权
[root@localhost ~]# mkdir /public
[root@localhost ~]# chmod 777 /public
2.4 创建文件挂载点,编辑/ect/fstab
[root@localhost ~]# echo "/dev/sdb1 /public ext4 defaults,usrquota,grpquota 0 0" >>/etc/fstab
[root@localhost ~]# mount -a
[root@localhost ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Jun 3 22:25:51 2021
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
/dev/mapper/cl-root / xfs defaults 0 0
UUID=ad229ff4-8126-495a-b98f-954230112e1a /boot ext4 defaults 1 2
/dev/mapper/cl-swap swap swap defaults 0 0
/dev/sdb1 /public ext4 defaults,usrquota,grpquota 0 0
2.5 查看/dev/sdb1是否开启quota
方法一:
[root@localhost ~]# mount |grep /dev/sdb1
/dev/sdb1 on /public type ext4 (rw,relatime,seclabel,quota,usrquota,grpquota)
方法二:
[root@localhost ~]# ls /public/
lost+found //挂载成功
2.6 使用quotacheck命令生成配置磁盘配置的数据库文件
- 若selinux开启的话会提示权限不够,通过setenforce 0临时关掉selinux就可以了
- 创建磁盘配额配置文件,命令参数解释如下:
[root@localhost ~]# setenforce 0
[root@localhost ~]# quotacheck -vug /public/
// -v 显示扫描过程;
// -u 针对扫描情况与目录的使用情况建立aquota.user;
// -g 针对用户扫描文件与使用情况建立aquota.group;
quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/sdb1 [/public] done
quotacheck: Checked 3 directories and 2 files
2.7 配置jan16用户使用/dev/sdb1分区的限额
[root@localhost ~]# edquota -u jan16
Disk quotas for user jan16 (uid 2223):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 20 10 20 5 3 5
# 输入上面的命令后,会进入一个vi编辑界面
# 对其中各字段解释如下:
# Filesystem下显示实现磁盘配额的分区;
# blocks下为当前已经使用的大小,不用修改;
# soft为软限制,超出后会给出警告,超出的部分默认会保存7天;
# hard为硬限制,不可超越的限制(软硬限制默认单位都是KB);
# 后面的两个相同的soft、hard分别表示分区中这个用户可以创建的文件数目软硬限制;
# 本实验中设置,jan16可以使用/dev/sdb1分区的软限制大小10KB,硬限制20KB,可创建的文件个数软限制是3个,硬限制5个;
2.8 开启这个分区的磁盘配额
[root@localhost ~]# quotaon /public
任务3- 实验测试
3.1 切换用户jan16,并进入目录/public
[root@localhost ~]# su - jan16
[jan16@localhost ~]$ cd /public
3.2 使用dd命令进行文件写入测试
[jan16@localhost public]$ dd if=/dev/zero of=/public/testfile1 bs=1K count=12
sdb1: warning, user block quota exceeded.
12+0 records in
12+0 records out
12288 bytes (12 kB, 12 KiB) copied, 0.000130243 s, 94.3 MB/s
[jan16@localhost public]$ dd if=/dev/zero of=/public/testfile3 bs=1K count=磁盘容量配额(转)
...的硬盘空间,一旦超出预算就不再允许他们使用。quota的磁盘配额可以限制用户的硬盘可用空间或最大创建文件数量,并且还有软/硬限制的区别:软限制 查看详情
磁盘配额(quota)的应用与实践
...该适当限制硬盘的空间给用户,以妥善分配系统资源,使磁盘的容量使用较为公平;举例来说,我们用户的默认主文件夹都是在/home下 查看详情
quota磁盘配额
quota磁盘配额(user)1.开启配额功能:[[email protected]/]#mount-ousrquota/dev/sda5/mnt/2.设置用户配额:[[email protected]/]#edquota-urobin/mnt3.查询配额的使用情况[[email protected]/]#repquota-u/mnt4.启动配额:[[email 查看详情
磁盘配额(quota)(代码片段)
磁盘配额的学习目录一.什么是Quota二.Quota的使用三.Quota用法总结一.什么是Quota在Linux系统中,由于多用户共用一个磁盘,如果其中几个用户过多的使用了磁盘里的内容(比如某个用户用了%90空间),那么肯定会影响到其他用户的... 查看详情
磁盘配额quota
磁盘配额1启用磁盘配额首先创建新的分区/dev/sd5,并创建文件系统。[[email protected]~]#mkfs.ext4/dev/sda5由于xfs不磁盘配额能成功,这里使用ext4.然后把/dev/sda5分区挂载到/home[[email protected]~]#mount/dev/sda5/home[[email protected]~]#blki 查看详情
磁盘配额-quota
本文内容实现从lvm创建文件系统到实现磁盘配额目的。一、LVM利用两块20G的硬盘Lvm的管理命令功能物理卷管理卷组管理逻辑卷管理Scan扫描pvscanvgscanlvscanCreate建立pvcreatevgcreatelvcreateDisplay显示pvdisplayvgdisplaylvdisplayRemove删除pvremovevgrem... 查看详情
linux磁盘配额可以通过哪两种方法对用户进行限制?
Linux磁盘配额1.磁盘配额的使用限制仅针对整个分区:磁盘配额实际运行时,是针对“整个分区”进行限制的,例如,如果/dev/hda5载入在/home下,那么,在/home下面的所有目录都会受到限制。核心必须支持磁盘配额:Linux系统核心... 查看详情
磁盘配额限制
磁盘配额的限制类型磁盘容量文件数量思路以支持配额功能的方式挂载文件系统 mount-o vi/etc/fstab检测磁盘配额并生成配额文件 quotacheck-augcvls-l编辑用户和组账号的配额设置edquota-u edquota-g启动文件系统的磁盘配额功... 查看详情
磁盘配额(quota)(代码片段)
一、什么是磁盘配额磁盘配额从字面意思上看就是给一个磁盘配置多少额度,而quota就是有多少限额的意思,所以总的来说就是限制用户对磁盘空间的使用量。因为Linux是多用户多任务的操作系统,许多人公用磁盘空间,举个例... 查看详情
quota磁盘配额(代码片段)
一、什么是磁盘配额磁盘配额从字面意思上看就是给一个磁盘配置多少额度,而quota就是有多少限额的意思,所以总的来说就是限制用户对磁盘空间的使用量。因为Linux是多用户多任务的操作系统,许多人公用磁盘空间,举个例... 查看详情
高级文件系统管理磁盘配额,raid
磁盘配额 quota命令显示磁盘使用情况和限额。quota命令报告文件中列出的所有文件系统的限额。如果quota命令以非零状态退出,一个或多个文件系统超过限额。1、ext系列文件系统的quota的步骤方式1.1、开启quota(e... 查看详情
quota就是在redhatlinux下实现磁盘配额的工具
...新的版本请关注RedHat的官方站点安装好软件包后就可以对磁盘配额进行配置了 配置系统的磁盘配额支持 首先磁盘配额是区域性的我们可以决定哪块分区进行磁盘配额哪块分区不用 (自然也就不用配置了)一般而... 查看详情
【xfs"a】xfs文件系统中quota的使用
...help#yuminfoxfsprogs#man xfs_quota如果用户需要使用大容量的磁盘空间,需要使用volume.Quota主要来限制容器的rootfs, 这个rootfs一般是在host的磁盘会和别的容器共享,所以需要对它做限制。容器实战高手课/在实战中深入理解容器技... 查看详情
linux磁盘限额配置:quota命令
LINUX下也有类似WINDOWSNTFS所用的磁盘限额,用的是quota来实现通过rpm-qquota确定是否已安装用quota只能对patation做限额,要做到针对某个目录来做只能靠ln-s来实现了。所以一开始就规划好使用还是比较重要的。举例,给用户yuyii增加... 查看详情
基于lvm逻辑卷下的磁盘配额操作(代码片段)
我们继续接上篇进行的LVM逻辑卷进行接下来的磁盘配额的学习本章操作内容接上篇lvm逻辑卷,如果没有看过上篇博客操作的小伙伴,可在操作完逻辑卷的内容时候再继续跟着本篇内容进行磁盘配额的操作!磁盘配额概述:1.需要... 查看详情
quota和lvm
...nux是多用户任务的操作系统,所以就会出现多个用户共享磁盘的情况,如何解决不同用户合理使用磁盘的问题,就可以通过磁盘配额来解决。 针对用户,设置用户的磁盘配置。 相关知识点 ... 查看详情
磁盘配额(代码片段)
磁盘配额限定用户或组对磁盘空间的使用。安装quota[[email protected]dev]#yuminstallquota-y以支持磁盘配额的方式挂载,查看[[email protected]dev]#mount-oremount,usrquota,grpquota/dev/sdb3[[email protected]dev]#mount|grepusrquot 查看详情
ext4文件系统quota
quota配额什么是磁盘配额?限制磁盘资源的使用。 限制原因就是因为资源不是无限的。应用场景:1.网络存储空间有限网盘2.邮件服务器3.公司的文件共享服务器能限制谁?1.限制普通用户2.限制用户组注意:不能限制root用户root... 查看详情