磁碟配額管理案例
需求說明:
linux伺服器管理員新掛載的一塊10gb的磁碟用作檔案存放功能,為了避免有些使用者過多占用磁碟容量,準備實施配額管理,具體規劃如下:
1、掛載一塊新的磁碟(名稱為/dev/sdb),就分乙個分割槽(/dev/sdb1)。
2、新建組students,目前該組只有 tom與 jerry兩個使用者,密碼均為123456;
3、該分割槽設定每個使用者最大限制為 50mb,軟限制為 45mb;
4、考慮到該組使用者在後續會新增,則將students組最大限額設定為 1000 mb,軟限制為900mb;
5、寬限時間設定為 1天。
步驟:1、新建組students,及tom和jerry使用者,並設定密碼
#groupadd students
#useradd -g students tom
#useradd -g students jerry
#passwd tom密碼設定按提示執行
#passwd jerry
2、系統中預設啟用了selinux安全機制,將selinux關閉,才能進行磁碟配額管理
#setenforce 0
3、對掛載的磁碟進行分割槽
#fdisk /dev/sdb
warning: dos-compatible mode is deprecated. it's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
command (m for help): n
command action
e extended
p primary partition (1-4)
ppartition number (1-4):
value out of range.
partition number (1-4): 1
first cylinder (1-1305, default 1):
using default value 1
last cylinder, +cylinders or +size (1-1305, default 1305):
using default value 1305
command (m for help): w
the partition table has been altered!
calling ioctl() to re-read partition table.
syncing disks.
4、格式化該分割槽
# /dev/sdb1
5、建立/test目錄,作為該分割槽的掛載點
#mkdir /test
6、修改/etc/fstab檔案,對該分割槽實現自動掛載,並啟用配額功能。
#vim /etc/fstab
增加一行:
/dev/sdb1 /testext4 defaults,usrquota,grpquota 0 0
說明:引數defaults預設無配額管理;加入usrquota引數,實現基於使用者的磁碟配額;加入grpqouta引數,實現基於組的磁碟配額;如果兩者都需要,全部新增,中間用逗號分隔。
7、重新掛載檔案系統
#mount -o remount /test
8、確認是否掛載成功
# mount |grep sdb1
如下行內容,表示掛載成功:
/dev/sdb1 on /test type ext4 (rw,usrquota,grpquota)
9、掃瞄磁碟,檢測磁碟配額並生成配額檔案
# quotacheck -vug /test
10、檢視掛載點
#ls /test
lost+found
結果說明可以進行組配額和使用者配額管理,是指組配額記錄檔案,是指使用者配額記錄檔案。
11、編輯tom使用者配額
#edquota -u tom
內容設定如下:
disk quotas for user tom (uid 501):
filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 46080 51200 0 0 0
說明:進行配置設定時,只需要修改使用者或組對磁碟使用容量即可。blocks是指以用容量,單位是kb,是修改第3列和第4列中的軟限制容量和硬限制容量,主要修改這兩列;inodes指當前已擁有檔案數量,soft和hard是對檔案數量的限制,一般很少對使用者的檔案數量進行限制,第6列和第7列均設定為0,表示不限制。
12、因jerry使用者與tom使用者的配額一致,可直接複製tom配額
# edquota -p tom jerry
13、設定students組配額
#edquota -g students
內容設定如下:
disk quotas for group students (gid 501):
filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 921600 1024000 0 0 0
說明:配額設定僅對基本組生效,對附加組無效。
14、設定寬限時間
#edquota -t
設定內容如下:
grace period before enforcing soft limits for users:
time units may be: days, hours, minutes, or seconds
filesystemblock grace period inode grace period
/dev/sdb11days7days
15、啟用配額
# quotaon -u** /test
/dev/sdb1 [/test]: group quotas turned on
/dev/sdb1 [/test]: user quotas turned on
啟用成功
16、驗證配額
a、為保證所有使用者都有寫入許可權,將許可權設定如下:
# chmod 777 /test
b、切換到tom使用者
# su - tom
c、寫入資料
$ dd if=/dev/zero of=/test/test1 bs=10m count=6
sdb1: warning, user block quota exceeded.
sdb1: write failed, user block limit reached.
dd: 正在寫入"/test/test1": 超出磁碟限額
記錄了6+0 的讀入
記錄了5+0 的寫出
節(52 mb)已複製,0.224425 秒,234 mb/秒
說明:dd命令進行檔案寫入測試,# if=/dev/zero 表示從"/dev/zero"檔案輸出,of=/test/test1, 表示輸入到"/test/test1"檔案中,即從/dev/zero這個檔案中讀取垃圾資料寫入/test/test1檔案中;# bs=10m 表示一次讀取寫入的大小是10mb,count=6 表示讀取6次。
特別說明:節(52 mb)已複製,是因為採用1000而非1024進行換算,導致括號內的資料不準確。因此配額已生效。
d、查詢配額
$ quota
disk quotas for user tom (uid 501):
filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 51200* 46080 51200 23:55 1 0 0
說明:filesystem:表示本行配置對應的檔案系統(分割槽),即配額的作用範圍;blocks表示使用者當前已經使用的磁碟容量,預設單位為kb,該值由edquota程式自動計算生成;quota指軟限制,limit指硬極限,grace指寬限期倒計時,files指檔案數,後面三項是針對inodes設定才會顯示,0表示無限制。
e、回到root使用者,查詢
#exit
# quota -u tom
disk quotas for user tom (uid 501):
filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 51200* 46080 51200 23:48 1 0 0
# quota -u jerry
disk quotas for user jerry (uid 502): none表示沒有在該分割槽下儲存過檔案
# quota -g students
# repquota /test
17、關閉配額
# quotaoff -u** /test
/dev/sdb1 [/test]: group quotas turned off
/dev/sdb1 [/test]: user quotas turned off
或#quotaoff –a
磁碟管理說課稿
秭歸縣職教中心宋文銀 一 說教材 教材分析 1 地位 本節課採用是電子工業出版社 中等職業教育課本 必修 資訊科技教材。磁碟管理,這節是學習windows作業系統中最基本部分 教學過程中用的是windows xp系統 真正要成為一名電腦小管家這些操作必須熟練。同時作為電腦使用者,這樣才能合理安排和有...
動態磁碟管理
備課序號授課班級課題 13 14計1302 1303 課時上課時間 2實訓動態磁碟的管理 實訓目標 學會基本磁碟的配置,動態磁碟的管理 實訓重難點實訓準備實訓方法 動態磁碟的管理 vm虛擬機器安裝檔案 windows server 2003作業系統分組合作 教學過程 個性化設計 實現步驟 給虛擬機器...
linux磁碟管理 二
磁碟管理 二 jiyongqiang 設定磁碟配額 一 使磁碟支援配額功能 mount o usrquota,grpquota dev sdb1 test 或者設定永久掛載 二 生成配額配置檔案 a 掃瞄系統中所有具有配額功能的磁碟 u 給使用者生成配額配置 g 給組生成配額配置 v 顯示詳細資訊 ...