1. 程式人生 > >Linux磁碟配額

Linux磁碟配額

Step1:修改fstab檔案,增加磁碟限額使用者和使用者組資訊

# /etc/fstab
# Created by anaconda on Sat Dec 29 04:48:18 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
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=e500f1cf-2bcb-445f-9255-5fb9254640d8 /boot xfs defaults 0 0
/dev/sdb1 /ess ext4 defaults,usrquota,grpquota 1 2    //在磁碟/dev/sdb1上配置磁碟配額,掛載點為/ess


/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0

修改完成後重啟系統。

Step2:執行quotacheck命令生成quota.user檔案

[[email protected] ~]# 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/sdb1 [/ess] done
quotacheck: Cannot stat old user quota file /ess/aquota.user: No such file or directory. Usage will not be subtracted.
quotacheck: Cannot stat old group quota file /ess/aquota.group: No such file or directory. Usage will not be subtracted.
quotacheck: Cannot stat old user quota file /ess/aquota.user: No such file or directory. Usage will not be subtracted.
quotacheck: Cannot stat old group quota file /ess/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.
[

[email protected] ~]#

Step3:建立使用者組ess,建立使用者tom並且加入該組

[[email protected] ~]# groupadd ess
[[email protected] ~]# useradd tom -g ess
[[email protected] ~]# passwd tom
Changing password for user tom.
New password:
Retype new password:
passwd: all authentication tokens updated successfully

Step4:使用edquota命令為使用者tom設定配額

[[email protected] ~]# edquota -u tom

Disk quotas for user tom (uid 1001):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 102400 150000 0 0 0 0    //設定軟限額為10G硬限額為15G

Step5:啟動磁碟配額

[[email protected] ~]# quotaon -avgu
/dev/sdb1 [/ess]: group quotas turned on
/dev/sdb1 [/ess]: user quotas turned on

Step6:使用quota檢視配額使用情況

[[email protected] ess]# quota tom
Disk quotas for user tom (uid 1001):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 150000* 102400 150000 6days 24 0 0
[[email protected] ess]#