磁碟配額 - Quota
系統需求
線上資源
建置 Quota 時,最好把要做配額的目錄使用一個分割區 mount 起來,原因是因為 quota 是以一個 file system 為單位,不是以目錄為單位的去做配置。
Quota 能做到的範圍
實做對 /home 做 quota 限制
一、設定 Quota 的前置工作
設定 /etc/fstab,加入 usrquota 和 grpquota,能對使用者和群組做限制
# vi /etc/fstab |
修改完 /etc/fstab 之後,可以重新 mount 或是重新開機來讓新的設定值生效
# mount -o remount /home |
重新 mount 之後,再看看 /home 有沒有使用 usrquota 和 grpquota 等選項
# mount /dev/hda2 on / type ext3 (rw) none on /proc type proc (rw) usbdevfs on /proc/bus/usb type usbdevfs (rw) /dev/hda1 on /boot type ext3 (rw) none on /dev/pts type devpts (rw,gid=5,mode=620) /dev/hda5 on /home type ext3 (rw,usrquota,grpquota) none on /dev/shm type tmpfs (rw) /dev/md0 on /raiddata type ext3 (rw) |
現在已經設定好 /etc/fstab 了,就可以來初始化 quota。
# quotacheck -cug /home |
接著就到 /home 下看看有沒有多了兩個檔案 aquota.group 和 aquota.user
# ls -l /home total 27 -rw------- 1 root root 7168 Nov 21 20:14 aquota.group -rw------- 1 root root 7168 Nov 21 20:14 aquota.user drwx------ 2 root root 12288 Nov 18 02:16 lost+found |
看到以上有 aquota.group 和 aquota.user 之後,就可以把 quota 開起來了。
# quotaon -ug /home |
廣 告 |
二、設定 Quota
Quota 設定時,可時用下列語法
針對 user
## 針對 steven 做限制 # edquota -u steven |
針對 group
# edquota -g mis |
知道如何進入設定畫面時,先了解每個欄位的意思,先讓我們在看看設定畫面長什麼樣子:
# edquota -u steven ________________________________________________________________ Disk quotas for user steven (uid 500): Filesystem blocks soft hard inodes soft hard /dev/hda5 12 0 0 12 0 0 :_______________________________________________________________ |
Filesystem:steven 在 /dev/hda5 的限制
blocks:steven 在 /dev/hda5 已使用的容量 (KB),此項目無法更改
soft:軟性限制,若超過的大小可充許暫時使用,使用單位為 KB
hard:硬性限制,若超過軟性限制,無論如何並無法超過硬性大小限制,使用單位為 KB
inodes:steven 在 /dev/hda5 己使用的檔案(目錄及檔案)數,此項目無法更改
soft:軟性限制,若超過的單位可充許暫時使用
hard:硬性限制,若超過軟性限制,無論如何並無法超過硬性單位限制
了解了以上欄位的資訊之後,現在來實做,讓 steven 可以有 8 MB 的大小空間,但無法超過 10 MB,共且只能產生 50 個檔案,最多不可超過 60 個。
# edquota -u steven ________________________________________________________________ Disk quotas for user steven (uid 500): Filesystem blocks soft hard inodes soft hard /dev/hda5 12 8192 10240 12 50 60 :_______________________________________________________________ |
以上再存起來,就可以立既生效了。如果要設定 group 的話,也是一樣的方法。
三、測試
現在切到 steven 的身份,再建立一個檔案大小為 11MB 的物件,看是否允許建立。
目前的使用狀況
[steven@rhel steven]$ quota Disk quotas for user steven (uid 500): Filesystem blocks quota limit grace files quota limit grace /dev/hda5 12 8192 10240 12 50 60 |
建立一個 7 MB 的空檔案,再試看看
[steven@rhel steven]$ dd if=/dev/zero of=test bs=1M
count=7 7+0 records in 7+0 records out [steven@rhel steven]$ quota Disk quotas for user steven (uid 500): Filesystem blocks quota limit grace files quota limit grace /dev/hda5 7209 8192 10240 13 50 60 |
上表可以清楚發現 steven 使用的 block 數變大了,現在在來新增一個 4 MB 的檔案。
[steven@rhel steven]$ dd if=/dev/zero of=test2 bs=1M
count=4 ide0(3,5): warning, user block quota exceeded. ide0(3,5): write failed, user block limit reached. ide0(3,5): write failed, user block limit reached. dd: writing `test2': Disk quota exceeded 3+0 records in 2+0 records out |
看到了嗎,quota 在叫了呢告訴你已超過了容量。那我們再來看看到底是用了多少。
[steven@rhel steven]$ quota Disk quotas for user steven (uid 500): Filesystem blocks quota limit grace files quota limit grace /dev/hda5 10238* 8192 10240 6days 14 50 60 |
上面可以看到, steven 已使用了 10238 KB 的容量了,再來,可以很清楚的看到在 grace 欄多了個 6 days 的值,這表示必需在 6 天之內把容量整埋到 8 MB 以下,否則超過的部份就會砍掉,那麼致於 quota 會怎麼砍呢?小弟也不了解。
Quota 重新開機後,會自動判別,因此不需要開啟或關閉什麼特定的 service。
N / A