Linux 磁盘配额(XFS EXT4)(2)

-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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/11714.html