“Linux 磁盘配额管理”的版本间的差异
(→关闭配额管理) |
|||
第1行: | 第1行: | ||
==文件系统配额设置== | ==文件系统配额设置== | ||
+ | ==配额的基本概念== | ||
+ | 磁盘配额是一种磁盘空间的管理机制。使用磁盘配额可限制用户或某个组在某个特定文件系统中所能使用的最大空间。 | ||
+ | |||
+ | 根据配额特性的不同,可将配额分为硬配额和软配额。硬配额是用户和组可使用空间的最大值。软配额允许一定时间内被超过。 | ||
===编辑/etc/fstab文件=== | ===编辑/etc/fstab文件=== | ||
用vi编辑器打开/etc/fstab文件,对/home所在行进行修改,增加命令选项userquota 和grpquota | 用vi编辑器打开/etc/fstab文件,对/home所在行进行修改,增加命令选项userquota 和grpquota | ||
第24行: | 第28行: | ||
===创建配额文件=== | ===创建配额文件=== | ||
执行命令quotacheck命令 | 执行命令quotacheck命令 | ||
+ | |||
+ | quotacheck命令的基本功能是检查每个文件系统、建立目前硬盘使用率列表以及检查每个文件系统的空间限制。 | ||
[root@localhost ~]# quotacheck -avgu | [root@localhost ~]# quotacheck -avgu | ||
第43行: | 第49行: | ||
aquota.group aquota.user fly lost+found</nowiki> | aquota.group aquota.user fly lost+found</nowiki> | ||
− | === | + | ===执行edquota命令=== |
+ | 由于aquota.user和aquota.group文件的结构很复杂,无法直接打开进行编辑,因此必须执行edquota命令进行编辑。 | ||
+ | |||
edquota -u user1 | edquota -u user1 | ||
2018年10月10日 (三) 14:33的最新版本
目录
文件系统配额设置
配额的基本概念
磁盘配额是一种磁盘空间的管理机制。使用磁盘配额可限制用户或某个组在某个特定文件系统中所能使用的最大空间。
根据配额特性的不同,可将配额分为硬配额和软配额。硬配额是用户和组可使用空间的最大值。软配额允许一定时间内被超过。
编辑/etc/fstab文件
用vi编辑器打开/etc/fstab文件,对/home所在行进行修改,增加命令选项userquota 和grpquota
# # /etc/fstab # Created by anaconda on Thu Jun 28 04:40:29 2018 # # 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 # UUID=7867ecde-68a9-437f-b68c-1b8e16a53346 / ext4 defaults 1 1 UUID=eec138a9-9e94-4757-8a7f-fc3ccb56c153 /home ext4 defaults,userquota,grpquota 1 2 UUID=4657ef5a-8967-41c0-8818-04564bf6a4f0 swap swap defaults 0 0 tmpfs /dev/shm tmpfs defaults 0 0 devpts /dev/pts devpts gid=5,mode=620 0 0 sysfs /sys sysfs defaults 0 0 proc /proc proc defaults 0 0 /dev/sdb1 /mnt/hello ext4 defaults
重启系统
重启系统可使系统读取/etc/fstab文件的内容,重新挂载
创建配额文件
执行命令quotacheck命令
quotacheck命令的基本功能是检查每个文件系统、建立目前硬盘使用率列表以及检查每个文件系统的空间限制。
[root@localhost ~]# quotacheck -avgu
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/sda3 [/home] done quotacheck: Cannot stat old user quota file: No such file or directory quotacheck: Cannot stat old group quota file: No such file or directory quotacheck: Cannot stat old user quota file: No such file or directory quotacheck: Cannot stat old group quota file: No such file or directory quotacheck: Checked 7 directories and 3 files quotacheck: Old file not found. quotacheck: Old file not found.
查看/home目录
root@localhost ~]# cd /home [root@localhost home]# ls aquota.group aquota.user fly lost+found
执行edquota命令
由于aquota.user和aquota.group文件的结构很复杂,无法直接打开进行编辑,因此必须执行edquota命令进行编辑。
edquota -u user1
Disk quotas for user fly (uid 500): Filesystem blocks soft hard inodes soft hard /dev/sda3 32 10240 15360 8 0 0
执行
[root@localhost home]# edquota -u fly
[root@localhost home]# edquota -u fly
[root@localhost home]# useradd horse
[root@localhost home]# edquota -p fly horse
[root@localhost home]# groupadd user [root@localhost home]# gpasswd -a fly user Adding user fly to group user [root@localhost home]# gpasswd -a horse user Adding user horse to group user [root@localhost home]# edquota -g user
启动配额管理
[root@localhost home]# quotaon -aguv
/dev/sda3 [/home]: group quotas turned on /dev/sda3 [/home]: user quotas turned on
查看配额情况:
[root@localhost home]# quota fly Disk quotas for user fly (uid 500): Filesystem blocks quota limit grace files quota limit grace /dev/sda3 32 10240 15360 8 0 0
关闭配额管理
[root@localhost new]# quotaoff -aguv /dev/sda3 [/home]: group quotas turned off /dev/sda3 [/home]: user quotas turned off