quota 筆記

tonykorn97發表於2008-07-17

1,overview
implemented within the kernel
enabled on a per-filesystem basis
individual policies for groups or users
limit by the number of blicks or indoes
implement both soft and hard limits

initialization
partition mount options:usrquota,grpquota
initialize database:quotacheck[@more@]

2,setting quotas for users
implementation
start or stop quotas:quotaon,quotaoff
edit quotas directly:edquota username

from a shell:
setquota username 4096 5120 40 50 /foo
define prototypical users:
dequota -p user1 user2

3,reporting quota status
reporting
user inspection:quota
quota overviews:repquota
miscellaneous utilities:warnquota


設定步驟
1,mount是加上相關的選項 ,編輯/etc/fstab檔案,在home目錄的分割槽上面設定 usrquota或grpquota,
[root@tonykorn97 ~]# cat /etc/fstab
/dev/vol0/root / ext3 defaults 1 1
/dev/vol0/home /home ext3 usrquota,defaults 1 2

重新mount home分割槽
[root@tonykorn97 ~]# mount -o remount /home
[root@tonykorn97 ~]# mount
/dev/mapper/vol0-root on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/mapper/vol0-home on /home type ext3 (rw,usrquota)


2,建立quota資料庫
[root@tonykorn97 ~]# quotacheck -cugm /home

-c 建立新的
-u 使用者
-g 組

3,啟動quota限制
[root@tonykorn97 ~]# quotaon /home

4,編輯磁碟限額
[root@tonykorn97 ~]# edquota student

具體資訊
Disk quotas for user student (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/mapper/vol0-home 19 20 40 9 20 40

block: 已使用的塊大小,預設為1K
soft: 軟限制塊大小
hard: 硬限制塊大小
inodes:已使用檔案個數限制
soft: 軟限制檔案個數
hard: 硬限制檔案個數

5,執行quota顯示使用者資訊
[root@tonykorn97 ~]# quota student
Disk quotas for user student (uid 500):
Filesystem blocks quota limit grace files quota limit grace
/dev/mapper/vol0-home
19 20 40 9 20 40
[root@tonykorn97 ~]#

6,測試
[root@tonykorn97 ~]# su - student
[student@tonykorn97 ~]$ dd if=/dev/zero of=/home/student/test bs=1k count=10
dm-1: warning, user block quota exceeded.
10+0 records in
10+0 records out
10240 bytes (10 kB) copied, 0.000591459 seconds, 17.3 MB/s
[student@tonykorn97 ~]$ quota student
Disk quotas for user student (uid 500):
Filesystem blocks quota limit grace files quota limit grace
/dev/mapper/vol0-home
30* 20 40 7days 10 20 40
[student@tonykorn97 ~]$ dd if=/dev/zero of=/home/student/test bs=1k count=50
dm-1: warning, user block quota exceeded.
dm-1: write failed, user block limit reached.
dd: 寫入 “/home/student/test”: 超出磁碟限額
20+0 records in
19+0 records out
19456 bytes (19 kB) copied, 0.000943725 seconds, 20.6 MB/s
[student@tonykorn97 ~]$ quota student
Disk quotas for user student (uid 500):
Filesystem blocks quota limit grace files quota limit grace
/dev/mapper/vol0-home
40* 20 40 10 20 40
[student@tonykorn97 ~]$


取消quota限制
1,quotaoff關閉quota限制
[root@tonykorn97 ~]# quotaoff /home

2,刪除quota資料庫
[root@tonykorn97 ~]# edquota student
刪除檔案內容

3,修改/etc/fstab檔案,重新mount


來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/312079/viewspace-1007388/,如需轉載,請註明出處,否則將追究法律責任。