Linux Quota的配置實戰

suzhouclark發表於2009-08-06
Linux Quota的配置實戰[@more@]

增加了一個硬碟/dev/hdb1,用於存放使用者資料,掛載在/home/extra下。

1、修改/etc/fstab

/dev/hdb1 /home/extra ext3 defaults,noatime,usrquota,grpquota 1 2

紅色部分為增加的部分,注意逗號之間沒有空格。

2、建立配額檔案

# cd /home/extra

#touch aquota.user
#touch aquota.group
#chmod 600 aquota.user
#chmod 600 aquota.group

Quota使用了新的配額檔案,舊的檔案是quota.user和quota.group

如果用了這兩個舊檔案格式,啟動Quota的時候會出現錯誤:“Quota format not supported in kernel”

可以使用convertquota命令來轉換。

3、重新掛載/dev/hdb1

# mount -o remount /home/extra

4、掃描磁碟,初始化配額表

#quotacheck -uvg /home/extra

5、為使用者設定磁碟配額

# edquota -u test

Disk quotas for user test (uid 517):
Filesystem blocks soft hard inodes soft hard
/dev/hdb1 0 0 0 0 0 0

可以看出該使用者還沒有使用任何硬碟。各個欄位的含義:

blocks:已經使用的磁碟塊(1k bytes)

soft:軟限額大小,如果使用者超出了這個限額,系統會發出警告,如果在設定的時間內還沒有回到該限額以下,系統將拒絕該使用者使用額外的磁碟空間。

hard:硬限額,使用者不允許超出的磁碟限制

inodes:使用者已經使用的inodes數

soft和hard含義同上,不過,這裡是限制使用者建立的檔案/目錄總數。

限定25G, 最大30G,修改為:

Disk quotas for user test (uid 517):
Filesystem blocks soft hard inodes soft hard
/dev/hdb1 0 26214400 31457280 0 0 0

如果要設定整個群組能使用的磁碟限額,可以用下面的命令:

#edquota -g testgrp

6、修改軟限額期限

# edquota -t

Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
Filesystem Block grace period Inode grace period
/dev/hdb1 7days 7days

預設為7天,修改為希望的值,比如3天。

7、複製到其他使用者

可以一個一個的複製:

# edquota -p test test1

也可以使用awk命令來批處理:

edquota -p test `awk -F: '$3 > 499 {print $1}' /etc/passwd`

複製到uid大於499的所有使用者,我的系統上有一個使用者nfsnobody也符合這個條件,手動關閉它的限額。

# edquota -u nfsnobody

soft和hard改為0

8、啟動磁碟配額

# quotaon -av

9、檢視磁碟配額

整體使用情況:

# repquota -a

*** Report for user quotas on device /dev/hdb1
Block grace time: 3days; Inode grace time: 3days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 195616 0 0 4 0 0

檢視使用者的配額情況:

# quota -vu test

Disk quotas for user test (uid 517):
Filesystem blocks quota limit grace files quota limit grace
/dev/hdb1 0 26214400 31457280 0 0 0

10、關閉Quota

#quotaoff -av

11、其他應用

可以對WWW空間、FTP空間、Email空間進行磁碟配額限制。

注意:Quota只能基於磁碟分割槽進行配額管理,不能基於目錄進行配額管理,因此只能把資料存放在有配額限制的分割槽,再用符號連結到實際應用的目錄。

參考文章:

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

相關文章