Linux 磁盘配额(XFS & EXT4)
若是在Linux
中搭建了FTP
服务器,为了安全性,就要考虑磁盘配额,以防服务器磁盘空间被恶意占满。
磁盘配额概述
1.作用范围:只在指定的分区有效。
2.限制对象:主要针对用户、组进行限制,对组账号限制,组内所有用户的使用总和不能超过限制。
3.限制类型:磁盘容量限制(Block),默认单位KB、文件数量限制(Inode)。
4.限制方法:软限制、硬限制。软限制默认7天内允许超过,会有警告。硬限制不允许超过,硬限制应当比软限制大,否者软限制失效。
磁盘配额管理
XFS 文件系统
XFS
文件系统通过xfs_quota
工具进行管理。
查看xfsprogs
软件包的安装情况,列表查看xfsprogs
软件包安装的xfs_quota
配额管理程序。
[root@localhost ~]# rpm -q xfsprogs
xfsprogs-4.5.0-12.el7.x86_64
[root@localhost ~]# rpm -ql xfsprogs | grep -i "xfs_quota"
/usr/sbin/xfs_quota
/usr/share/man/man8/xfs_quota.8.gz
xfs_quota 等命令介绍
- mount -o usrquota,grpquota /dev/class/stu01 /mnt/stu01
-o usrquota,grpquota
:以支持配额的形式挂载
- xfs_quota -x -c 'limit -u bsoft=N bhard=N isoft=N ihard=N 用户名' 挂载点
配置磁盘配额
-x
:启动专家模式,在当前模式下允许对配额系统进行修改的所有管理命令可用
-c
:直接调用管理命令,
管理命令limit
后相关:
-u
:对用户限制
-g
:对组限制
bsoft
:磁盘容量软限制
bhard
:磁盘容量硬限制
isoft
:文件数量软限制
ihard
:文件数量硬限制
- xfs_quota -x -c 'report -abi' 挂载点
查看磁盘配额
管理命令report
后相关:
-u
:对用户查看
-g
:对组查看
-a
:查看所有可用分区的配额使用报告
-b
:查看磁盘容量
-i
:查看文件数
- dd if=指定输入设备或文件 of=指定输出设备或文件 bs=指定读取
block
的大小 count=指定读取block
的数量。
设备转换和复制命令
XFS 实验过程
1.关闭SELinux
,若启用SELinux
功能,不是所有的目录都能设定quota
,默认quota
仅能对/home
进行设定。
[root@localhost ~]# setenforce 0
2.为stu01
开启磁盘配额功能,并使其永久生效。
[root@localhost ~]# vim /etc/fstab
//修改stu01那行,这里为了方便,直接使用上一篇博客的实验成果。
/dev/class/stu01 /mnt/stu01 xfs defaults,usrquota,grpquota 0 0
3.查看stu01
的磁盘配额是否生效。(未生效)
[root@localhost ~]# mount | grep stu01
/dev/mapper/class-stu01 on /mnt/stu01 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
4.重新挂载stu01
,使磁盘配额生效。
[root@localhost ~]# umount /mnt/stu01/
[root@localhost ~]# mount -a
[root@localhost ~]# df -hT | grep stu01
/dev/mapper/class-stu01 xfs 33G 33M 33G 1% /mnt/stu01
5.查看stu01
的磁盘配额是否生效。(已生效)
[root@localhost ~]# mount | grep stu01
/dev/mapper/class-stu01 on /mnt/stu01 type xfs (rw,relatime,seclabel,attr2,inode64,usrquota,grpquota)
6.若是不存在名为zhangsan
的测试用户,则添加。
[root@localhost ~]# useradd zhangsan && echo "000000" | passwd --stdin zhangsan
Changing password for user zhangsan.
passwd: all authentication tokens updated successfully.
7.设置磁盘配额的数据。
[root@localhost ~]# xfs_quota -x -c 'limit -u bsoft=50M bhard=80M isoft=6 ihard=8 zhangsan' /mnt/stu01/
8.为了方便测试,放开权限。
[root@localhost ~]# chmod 777 /mnt/stu01/
9.切换到zhangsan
用户。
[root@localhost ~]# su - zhangsan
10.文件数量配额测试。
[zhangsan@localhost stu01]$ touch test{1..9}.txt
touch: cannot touch ‘test9.txt’: Disk quota exceeded
[zhangsan@localhost stu01]$ ls
test1.txt test2.txt test3.txt test4.txt test5.txt test6.txt test7.txt test8.txt
[zhangsan@localhost stu01]$ rm -f *
11.磁盘空间配额测试。
[zhangsan@localhost stu01]$ dd if=/dev/zero of=/mnt/stu01/test1.txt bs=1M count=100
dd: error writing ‘/mnt/stu01/test1.txt’: Disk quota exceeded
81+0 records in
80+0 records out
83886080 bytes (84 MB) copied, 0.0799075 s, 1.0 GB/s
[zhangsan@localhost stu01]$ ls -lh
total 80M
-rw-rw-r--. 1 zhangsan zhangsan 80M Aug 25 02:47 test1.txt
[zhangsan@localhost stu01]$ touch test2.txt
touch: cannot touch ‘test2.txt’: Disk quota exceeded
12.查看配额使用情况。
[root@localhost ~]# xfs_quota -x -c 'report -abi' /mnt/stu01/
User quota on /mnt/stu01 (/dev/mapper/class-stu01)
Blocks Inodes
User ID Used Soft Hard Warn/Grace Used Soft Hard Warn/ Grace
---------- -------------------------------------------------- --------------------------------------------------
root 0 0 0 00 [--------] 3 0 0 00 [--------]
zhangsan 81920 51200 81920 00 [6 days] 1 6 8 00 [--------]
Group quota on /mnt/stu01 (/dev/mapper/class-stu01)
Blocks Inodes
Group ID Used Soft Hard Warn/Grace Used Soft Hard Warn/ Grace
---------- -------------------------------------------------- --------------------------------------------------
root 0 0 0 00 [--------] 3 0 0 00 [--------]
zhangsan 81920 0 0 00 [--------] 1 0 0 00 [--------]
EXT4 文件系统
EXT3/4
文件系统通过quota
工具进行管理。
查看quota
软件包的安装情况。
[root@localhost ~]# rpm -q quota
quota-4.01-17.el7.x86_64
quota 相关命令介绍
- quotacheck
检测磁盘配额并生成配额文件
-a
:检测所有可用的分区
-u
:检测用户配额
-g
:检测组配额
-c
:创建配额数据文件
-v
:显示执行过程
quotacheck -ugcv 设备文件名
quotacheck -augcv
- edquota
编辑用户和组账号的配额设置
-u
:修改用户配额,默认KB。
-g
:修改组配额,默认KB。
-t
:修改宽限时间
edquota -u 用户名
edquota -g 组名
edquota -t
- quotaon & quotaoff
启动文件系统的磁盘配额功能
-u
:用户
-g
:组
-v
:显示过程
quotaon -ugv 设备文件名或挂载点
quotaoff -ugv 设备文件名或挂载点
- quota
查看用户、组配额使用情况
-u
:用户
-g
:组
quota -u 用户名
quota -g 组名
- repquota
查看分区磁盘配额使用情况
repquota 挂载点
EXT4 实验过程
1.关闭SELinux
,若启用SELinux
功能,不是所有的目录都能设定quota
,默认quota
仅能对/home
进行设定。
[root@localhost ~]# setenforce 0
2.为stu02
开启磁盘配额功能,并使其永久生效。
[root@localhost ~]# vim /etc/fstab
//修改stu02那行,这里为了方便,直接使用上一篇博客的实验成果。
/dev/class/stu02 /mnt/stu02 ext4 defaults,usrquota,grpquota 0 0
3.查看stu02
的磁盘配额是否生效。(未生效)
[root@localhost ~]# mount | grep stu02
/dev/mapper/class-stu02 on /mnt/stu02 type ext4 (rw,relatime,seclabel,data=ordered)
4.重新挂载stu02
,使磁盘配额生效。
[root@localhost ~]# umount /mnt/stu02/
[root@localhost ~]# mount -a
[root@localhost ~]# df -hT | grep stu02
/dev/mapper/class-stu02 ext4 23G 44M 22G 1% /mnt/stu02
5.查看stu02
的磁盘配额是否生效。(已生效)
[root@localhost ~]# mount | grep stu02
/dev/mapper/class-stu02 on /mnt/stu02 type ext4 (rw,relatime,seclabel,quota,usrquota,grpquota,data=ordered)
6.若是不存在名为zhangsan
的测试用户,则添加。
[root@localhost ~]# useradd zhangsan && echo "000000" | passwd --stdin zhangsan
Changing password for user zhangsan.
passwd: all authentication tokens updated successfully.
7.检测磁盘配额并生成配额文件。
[root@localhost ~]# ls /mnt/stu02/
lost+found
[root@localhost ~]# quotacheck -ugcv /dev/class/stu02
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/mapper/class-stu02 [/mnt/stu02] done
quotacheck: Cannot stat old user quota file /mnt/stu02/aquota.user: No such file or directory. Usage will not be subtracted.
quotacheck: Cannot stat old group quota file /mnt/stu02/aquota.group: No such file or directory. Usage will not be subtracted.
quotacheck: Cannot stat old user quota file /mnt/stu02/aquota.user: No such file or directory. Usage will not be subtracted.
quotacheck: Cannot stat old group quota file /mnt/stu02/aquota.group: No such file or directory. Usage will not be subtracted.
quotacheck: Checked 3 directories and 0 files
quotacheck: Old file not found.
quotacheck: Old file not found.
[root@localhost ~]# ls /mnt/stu02/
aquota.group aquota.user lost+found
8.编辑磁盘配额设置。
[root@localhost ~]# edquota -u zhangsan
Disk quotas for user zhangsan (uid 1000):
Filesystem blocks soft hard inodes soft hard
/dev/mapper/class-stu01 81920 51200 81920 1 6 8
/dev/mapper/class-stu02 0 40960 61440 0 4 6
9.启用磁盘配额功能。
[root@localhost ~]# quotaon -ugv /mnt/stu02/
/dev/mapper/class-stu02 [/mnt/stu02]: group quotas turned on
/dev/mapper/class-stu02 [/mnt/stu02]: user quotas turned on
10.为了方便测试,放开权限。
[root@localhost ~]# chmod 777 /mnt/stu02/
11.切换到zhangsan
用户。
[root@localhost ~]# su - zhangsan
12.磁盘空间配额测试。
[zhangsan@localhost stu02]$ dd if=/dev/zero of=/mnt/stu02/test1.txt bs=1M count=50
dm-3: warning, user block quota exceeded.
50+0 records in
50+0 records out
52428800 bytes (52 MB) copied, 0.509643 s, 103 MB/s
[zhangsan@localhost stu02]$ dd if=/dev/zero of=/mnt/stu02/test2.txt bs=1M count=50
dm-3: write failed, user block limit reached.
dd: error writing ‘/mnt/stu02/test2.txt’: Disk quota exceeded
11+0 records in
10+0 records out
10485760 bytes (10 MB) copied, 0.117714 s, 89.1 MB/s
[zhangsan@localhost stu02]$ ls -l
total 61472
-rw-------. 1 root root 7168 Aug 25 03:01 aquota.group
-rw-------. 1 root root 7168 Aug 25 03:08 aquota.user
drwx------. 2 root root 16384 Aug 25 00:20 lost+found
-rw-rw-r--. 1 zhangsan zhangsan 52428800 Aug 25 03:30 test1.txt
-rw-rw-r--. 1 zhangsan zhangsan 10485760 Aug 25 03:30 test2.txt
13.文件数量配额测试。
[zhangsan@localhost stu02]$ touch test{3..7}.txt
dm-3: warning, user file quota exceeded.
dm-3: write failed, user file limit reached.
touch: cannot touch ‘test7.txt’: Disk quota exceeded
[zhangsan@localhost stu02]$ ls -l
total 61472
-rw-------. 1 root root 7168 Aug 25 03:01 aquota.group
-rw-------. 1 root root 7168 Aug 25 03:08 aquota.user
drwx------. 2 root root 16384 Aug 25 00:20 lost+found
-rw-rw-r--. 1 zhangsan zhangsan 52428800 Aug 25 03:30 test1.txt
-rw-rw-r--. 1 zhangsan zhangsan 10485760 Aug 25 03:30 test2.txt
-rw-rw-r--. 1 zhangsan zhangsan 0 Aug 25 03:33 test3.txt
-rw-rw-r--. 1 zhangsan zhangsan 0 Aug 25 03:33 test4.txt
-rw-rw-r--. 1 zhangsan zhangsan 0 Aug 25 03:33 test5.txt
-rw-rw-r--. 1 zhangsan zhangsan 0 Aug 25 03:33 test6.txt
14.查看用户zhangsan的配额使用情况。
[root@localhost ~]# quota -u zhangsan
Disk quotas for user zhangsan (uid 1000):
Filesystem blocks quota limit grace files quota limit grace
/dev/mapper/class-stu01
81920* 51200 81920 6days 1 6 8
/dev/mapper/class-stu02
61440* 40960 61440 6days 6* 4 6 6days
总结
通过以上实验,可以发现,XFS
文件系统的磁盘配额只要文件数量、磁盘空间其中任何一个达到限额,就无法继续写文件;而EXT4
文件系统则不同,磁盘空间满了还可以创建空文件,直至数量达到限额,或者数量达到限额,覆盖已有文件创建非空文件,直至磁盘容量达到限额。
Linux 磁盘配额(XFS & EXT4)的更多相关文章
- Linux quota命令参数及用法详解---Linux磁盘配额限制设置和查看命令
功能说明:显示磁盘已使用的空间与限制. 语 法:quota [-quvV][用户名称...] 或 quota [-gqvV][群组名称...] 补充说明:执行quota指令,可查询磁盘空间的限制,并得 ...
- quota - linux磁盘配额管理
磁盘管理系列 linux磁盘管理系列一:磁盘配额管理 http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_040_quota.html l ...
- Linux磁盘配额与LVM
一.LVM概述 逻辑卷管理 Logical Volume Manager二.LVM机制的基本概念三.LVM的管理命令 ① 主要命令 ② ==LVM逻辑卷操作流程== ③ 举例四.磁盘配额概述 ...
- Linux磁盘配额实验
1.实现磁盘限额的条件 *需要Linux内核支持 *安装quota软件包2.Linux磁盘限额的特点 作用范围:针对指定 文件系统(分区) 限制对象:普通用户帐号.组帐号 限制类型:磁盘容量(默认单位 ...
- Linux磁盘配额
Step1:修改fstab文件,增加磁盘限额用户和用户组信息 # /etc/fstab# Created by anaconda on Sat Dec 29 04:48:18 2018## Acces ...
- linux 磁盘配额配置
1. 添加一块新磁盘 ,分区 .格式化 .(mkfs.etx3 /dev/sdc5/) 2.设置开机自动挂载(vi /etc/fstab) 添加磁盘配额支持 (用户配额usrquota.组配额grpq ...
- ★Linux磁盘配额的使用 ★——牛刀小试
磁盘配额的作用:限制普通用户使用磁盘的空间和创建文件的个数,不至于因为个别人的浪费而影响所有人的使用 需要用户程序quota软件包 #rpm -qa | grep quota 查看quota软件包安 ...
- —linux 磁盘配额按用户管理(quota)
我根据下面的ref链接整理的基本是的按用户额度管理步骤 (按组的额度管理被简化掉) 我在Ubuntu服务器12.04下整理,其他版本的Ubuntu和Linux应该都没有问题的 (有任何错误都指正给我, ...
- xfs文件系统磁盘配额
引言 这篇文章简单介绍一下xfs文件系统的磁盘配额配置. 文章目录 0×1.开启分区磁盘配额 0×2.使用xfs_quota命令配置磁盘配额 0×1.开启分区磁盘配额 对于ext4文件以前的文件系统, ...
随机推荐
- WebGL学习笔记(九):阴影
3D中实现实时阴影技术中比较常见的方式是阴影映射(Shadow Mapping),我们这里也以这种技术来实现实时阴影. 阴影映射背后的思路非常简单:我们先以光的位置为视角进行渲染,我们能看到的东西都将 ...
- Golang 连接ActiveMQ
使用ActiveMQ库:github.com/go-stomp/stomp 示例代码 package main import ( "net" "fmt" &qu ...
- Spring BeanFactory 初始化 和 Bean 生命周期
(version:spring-context-4.3.15.RELEASE) AbstractApplicationContext#refresh() public void refresh() t ...
- nginx入门系列之安装与卸载
目录 通过包管理器安装 安装nginx 卸载nginx 从源码编译安装 准备安装环境 执行编译安装 制作nginx免安装包 官方安装手册:https://nginx.org/en/docs/insta ...
- vue做页面按钮权限--分析
import * as types from '../mutation-types' const state = { btnCode: getBtnCode(), } const mutations ...
- SonarQube - 常用配置与操作
1 - SonarQube服务器中的数据库配置 2019年4月10号,SonarQube发文称在7.9之后,所有的SonarQube的版本(CE.DE.EE和DCE)中将停止对MySQL的支持. 建议 ...
- python:将时间戳格式化为yyyyMMdd hh:mm:ss
import time #将10位时间戳或者13位转换为时间字符串,默认为2017-10-01 13:37:04格式 def timestamp_to_date(time_stamp, format_ ...
- json对象转js对象
json数据: { "YD1": 0, "YD2": 0, "YD3": 0, "YD4": 0, "YD5& ...
- [转帖]LINUX PID 1 和 SYSTEMD
LINUX PID 1 和 SYSTEMD 2017年07月16日 陈皓 评论 46 条评论 57,176 人阅读 https://coolshell.cn/articles/17998.html ...
- Word 插入脚注、尾注与题注 -- 视频教程(5)
>> 视频教程链接:B站,速度快,清晰 未完 ...... 点击访问原文(进入后根据右侧标签,快速定位到本文)