磁碟配額 限制用戶/群組在特定檔案系統上的空間與 inode 使用,防止單一用戶佔滿磁碟導致服務中斷。CentOS 6 透過 quota 套件、usrquota/grpquota 掛載選項、quotacheck 掃描、edquota 編輯、quotaon 啟用、repquota 報告,構建完整配額生命週期管理。

/home 獨立分區 /dev/sda3 (ext4)vbird1~vbird5,附屬群組 vbirdgroup# groupadd vbirdgroup
# for u in vbird1 vbird2 vbird3 vbird4 vbird5; do
useradd -G vbirdgroup $u
echo "password" | passwd --stdin $u
done
# mkdir /home/vbirdgroup
# chgrp vbirdgroup /home/vbirdgroup
# chmod 2770 /home/vbirdgroup # SGID 確保新檔案屬組繼承
# vi /etc/fstab
UUID=xxx /home ext4 defaults,usrquota,grpquota 1 2
# 重新掛載生效
# umount /home && mount -a
# mount | grep home
/dev/sda3 on /home type ext4 (rw,usrquota,grpquota)
# yum install quota
# quotacheck -avug
quotacheck: Scanning /dev/sda3 [/home] done
quotacheck: Cannot stat old quota file... (首次執行正常)
quotacheck: Checked 33 directories and 18 files
產生 /home/aquota.user、/home/aquota.group。
# quotaon -avug
/dev/sda3 [/home]: group quotas turned on
/dev/sda3 [/home]: user quotas turned on
# edquota -u vbird1
Disk quotas for user vbird1 (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/sda3 32 8000 10000 8 0 0
# soft=8MB, hard=10MB (blocks 單位 1K)
# 複製給其他用戶
# edquota -p vbird1 vbird2 vbird3 vbird4 vbird5
# edquota -g vbirdgroup
# 設定群組總配額
# edquota -t
Time units may be: days, hours, minutes, seconds
Grace period before enforcing soft limits for users:
Filesystem Block grace period Inode grace period
/dev/sda3 7days 7days
# su - vbird1
$ dd if=/dev/zero of=testfile bs=1M count=9 # 9MB < soft, 成功
$ dd if=/dev/zero of=testfile2 bs=1M count=3 # 總計 12MB > hard, 失敗
$ quota -v
Disk quotas for user vbird1 (uid 501):
Filesystem blocks quota limit grace files quota limit grace
/dev/sda3 12288 8192 10240 6days 2 0 0
# repquota -avug # 完整報表
# repquota -a # 簡略報表
# warnquota # 發送郵件警告 (需配置 /etc/warnquota.conf)
quotacheck -vugm (僅掛載點) 減少掃描範圍。xfs_quota 管理,不需傳統 quota 套件。quota 結果。#!/bin/bash
# daily_quota_report.sh
repquota -a | awk '$3 > $4*0.9 {print $0}' | mail -s "Quota Warning >90%" admin@
建立完整配額體系,配合監控告警,有效防止磁碟資源耗盡導致的服務雪崩。