Linux Quota 備忘
目的: 建立虛擬檔案系統 (Virtual Filesystem) 練習 quota 配置與相關指令
環境:
- SuSE Linux 10.0
- quota-3.13-2
建立虛擬檔案系統
使用記憶體建立 8MB 虛擬檔案系統
mkfs -t ext2 /dev/ram0 8192
ps. 若要建立多個 Ramdisk, 重覆上列指令, 目標為 /dev/ram1, /dev/ram2… 即可
掛載 Virtual Filesystem
mkdir /mnt/ram0
mount -t ext2 -o usrquota,grpquota /dev/ram0 /mnt/ram0
chmod 1777 /mnt/ram0
使用硬碟空間建立 10MB 虛擬檔案系統
dd if=/dev/zero of=/opt/virtual_filesystem.img bs=1024K count=10
mkfs -t ext2 /opt/virtual_filesystem.img
掛載 Virtual Filesystem
mkdir /mnt/loop0
mount -t ext2 -o loop,usrquota,grpquota \
/opt/virtual_filesystem.img /mnt/loop0chmod 1777 /mnt/loop0
ps. 只掛載一個 Virtual Filesystem 時, device name 為 /dev/loop0; 若同時掛載多個 Virtual Filesystem, device name 依序為 /dev/loop1, /dev/loop2…
第一次執行 quotacheck: 建立 quota files
quotacheck -avug
結果: 在 /mnt/loop0 產生 aquota.group 與 aquota.user
設定 quota (for testing)
edquota -u someone
Disk quotas for user someone (uid xxxx): Filesystem blocks soft hard inodes soft hard /dev/loop0 0 0 0 0 3 5
blocks: 1. 1 block 等於 1KB; 1024 blocks 即 1MB 2. 設置為 0 表示 quota 不設限 (unlimited)
inodes: soft=3 inode 數量超過 3 即發出警告, 在期限(以 edquota -t 設定)內需自行將 inodes 降至 3 以下, 否則將不允許再增加 inode hard=5 inode 數量不得超過 5 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/loop0 7days 7days 以上設置亦可使用 setquota 指令完成:
setquota -u someone 0 0 3 5 /dev/loop0
setquota -t 604800 604800 /dev/loop0
ps. 604800 為 7 天的秒數. 一小時=3600秒, 一天=86400秒
啟用/停用 quota 設置
啟用: quotaon -aug
停用: quotaoff -aug
測試一: 產生數個檔案, 直到觸發 inodes:hard 限制
su – someone
cd /mnt/loop0
touch file_1
touch file_2
touch file_3
touch file_4
loop0: warning, user file quota exceeded.
touch file_5
touch file_6
loop0: write failed, user file limit reached.
touch: cannot touch `file_6′: No space left on device
測試二: 觸發 inodes:soft 限制, 並等候 Inode grace period 期限屆滿
edquota -t
Inode grace period → 10secondssu – someone
cd /mnt/loop0
touch a b c d
loop0: warning, user file quota exceeded.… 10 seconds later …
touch e
loop0: write failed, user file quota exceeded too long.
touch: cannot touch `e’: No space left on device
檢視 quota 報告
quota: display user’s disk usage and limits.
quota -vu someonerepquota: prints a summary of the disc usage and quotas for the specified file system
repquota -avug
設定開機自動掛載 Virtual Filesystem, 並啟用 quota
vi /etc/fstab
/opt/virtual_filesystem.img /mnt/loop0 ext2 defaults,loop,usrquota,grpquota 0 0
vi /etc/init.d/boot.local (same as /etc/rc.d/rc.local in Red Hat Linux)
/sbin/quotaon -a
排程 Quota 檢查 / e-mail 通知
vi /etc/warnquota.conf
#註解底下這行
#FAIL = “configure /etc/warnquota.conf before running warnquota”vi /etc/quotatab
#替 Quota Device 寫上註解
/dev/loop0: This is a test.vi /etc/crontab
#排程每日凌晨三點執行 quota 檢查, 若超過 soft limit 或已達 hard limit 即發送 e-mail 通知
0 3 * * * root /usr/sbin/warnquota > /dev/null 2>&1
其他備忘
- quotastats – program to query quota statistics
- rpc.rquotad – remote quota server
在 server 端啟用 quota 並以 NFS 分享 quota filesystem 時, 於 server 端執行 rpc.rquotad 可讓 NFS client 以 quota 指令查詢 quota 狀況
没有评论▼