凍仁幫各個社團開帳號時,除了關閉 ssh 服務之外,還想限制各帳號的磁碟空間,以免被資源被濫用。在鳥哥得知有 quota 可限制空間,可凍仁卻有那麼點不懂,索性跟老闆借了 Novell Suse Linux Enterprise Server 9 管理手冊 一書才搞定。其中 usrquota 為單獨使用者;grpquota 為針對使用者群組設定配額。By the way, quota 除了限制磁碟空間大小之外,還可限制建立檔案的inode(數量)。
實作磁碟配額步驟:
1. 安裝 quota 套件。jonny@ubuntu:~$ sudo apt-get install quota
2. 修改 /etc/fstab 檔案並選擇預設定 Quota 的檔案系統。jonny@ubuntu:~$ sudo vi /etc/fstab
#裝置 掛載點 檔案系統格式 mount選項
/dev/sda7 /home ext3 defaults,usrquota,grpquota
3. 重新掛載檔案系統:加入 usrquota 與 grpquota 後,需重新掛載才有效。jonny@ubuntu:~$ sudo mount -o remount /home
4. 初始化 Quota 資料庫:quota 會藉由 Database(資料庫) 紀錄使用者或群組的使用情況,首先得使用 quotacheck 檢查配額的檔案系統及建立磁碟用量表格。(下方以 home 為例)jonny@ubuntu:~$ sudo qoutacheck -cmug /home
# c:建立 quota 資料庫 | u:檢查使用者配額 | g:檢查群組配額
執行完會產生 aquota.user(使用者 Quota 資料庫)、aquota.qroup(群組 Quota 資料庫)。jonny@ubuntu:~$ /home$ ls -l /home/aquota.*
-rw------- 1 root root 8192 2008-03-26 18:46 /home/aquota.group
-rw------- 1 root root 7168 2008-03-26 18:46 /home/aquota.user
5. 啟動 Quota Deamon:jonny@ubuntu:~$ sudo quotaon -av
6. 編輯使用者或群組 Quota 規則# 設定使用者磁碟配額
jonny@ubuntu:~$ sudo edquota -u UserName
# 設定群組磁碟配額
jonny@ubuntu:~$ sudo edquota -g GroupName
接著會進入 quota 編輯模式.. GNU nano 2.0.6 檔案: /tmp//EdP.aD0puo9
Disk quotas for user spa (uid 1004):
Filesystem blocks soft hard inodes soft hard
/dev/sda7 24 100000 102400 7 0 0
^G 求助 ^O 寫入 ^R 讀檔 ^Y 上頁 ^K 剪下文字 ^C 游標位置
^X 離開 ^J 對齊 ^W 搜尋 ^V 下頁 ^U UnCut Text^T 拼字檢查
第1欄(Filesystem):啟用 quota 的檔案系統名增
第2欄(blocks):使用者已使用的區塊數量
第3欄(soft):非強制性的磁碟空間限制 /* 單位:k */
第4欄(hard):強制性的磁碟空間限制 /* 單位:k */
第5欄(inodes):使用者已使用的檔案數目
第6欄(soft):非強制性的 inode 限制
第7欄(hard):強制性的 inode 限制
★ 套用某個使用者的規則jonny@ubuntu:~$ sudo edquota -p <被參考的使用者> user1,user2 ..
★確認使用者配額jonny@ubuntu:~$ sudo quota UserName
★確認群組配額jonny@ubuntu:~$ sudo quota -g GroupName
★檢視單一目錄磁碟配額報告jonny@ubuntu:~$ sudo repquota /home
★檢視所有配額中的磁碟用量報告jonny@ubuntu:~$ sudo repquota -aug
延伸閱讀:
★【Quota】修改寬限時間(grace time)
資料來源:
★Novell Suse Linux Enterprise Server 9 管理手冊 - ch7.6
★鳥哥 - Linux 磁碟配額 (Quota)
當 user 超過 soft 時,寬限時間就會開始倒數。在寬限時間到期之前 user 還可使用剩下的空間直到 hard。不過要是在時間內沒降到 soft 以下,那麼 user 就無法新增檔案及使用剩下的空間。jonny@ubuntu:~$ edquota -t
接下來進入編輯模式 GNU nano 2.0.6 檔案: /tmp//EdP.ae5PD58
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/sda7 7days 7days
^G 求助 ^O 寫入 ^R 讀檔 ^Y 上頁 ^K 剪下文字 ^C 游標位置
^X 離開 ^J 對齊 ^W 搜尋 ^V 下頁 ^U UnCut Text^T 拼字檢查延伸閱讀:
★【Quota】磁碟配額(Disk Quota)
資料來源:
★Novell Suse Linux Enterprise Server 9 管理手冊 - ch7.6
- Page 1 of 1 ( 2 posts )
- 楚楚「凍仁」的 Ubuntu 筆記
- qouta









