歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Unix知識 >> 關於Unix >> FreeBSD 中使用QUOTA(磁盤配額)

FreeBSD 中使用QUOTA(磁盤配額)

日期:2017/2/28 11:15:45   编辑:關於Unix


虛擬主機中經常要限制用戶空間的大小和文件的數量。這些限制在linux和FreeBSD中都是用QUOTA來實現的。這裡我說下在FreeBSD下實現的方法;
首先你要在內核中加入QUOTA支持。
machine i386
cpu I686_CPU
#ident GENERIC
ident CNOSvhost
maxusers 0
options QUOTA #就是這行了。
修改好後重新編譯內核。
enable_quotas="YES"
check_quotas="YES"
這樣你的系統就起用QUOTA了,你應當通過編輯/etc/fstab的某個文件系統的屬性,加入QUOTA的支持。
下面的fstab文件就設置了在/pub文件系統上起用用戶配額和組配額
# See the fstab(5) manual page for important information on automatic mounts
# of network filesystems before modifying this file.
# Device Mountpoint FStype Options Dump Pass#
/dev/ad0s1b none swap sw 0 0
/dev/ad0s1a / ufs rw 1 1
/dev/ad0s1h /pub ufs rw,userquota,groupquota 2
2
/dev/ad0s1e /tmp ufs rw 2 2
/dev/ad0s1g /usr ufs rw 2 2
/dev/ad0s1f /var ufs rw 2 2
/dev/acd0c /cdrom cd9660 ro,noauto 0 0
proc
/proc procfs rw 0 0
設置完fstab文件後,執行下面的命令打開quota
# quotacheck -av
# repquota -a
基本上前期的工作都已經做完了,剩下的就是編輯用戶的配額了。
# edquota c4st將編輯用戶c4st的配額設定,出現的是一個文本編輯器界面:
Quotas for user c4st:
/pub: kbytes in use: 3438, limits (soft = 100000, hard = 100020)
inodes in use: 25, limits (soft = 25, hard = 26)
我們看到設定共分為兩行。
kbyters in use:3438已經使用了3438kb limits限制(soft=100000軟限制100M,hard=100020硬限制)
soft表示達到此值時警告,hard表示的用戶實際可以使用的大小。
inodes in use: 25, limits (soft = 25, hard = 26)這行為可以擁有的“文件數量”限定,當然例子給出的數值不太實際,上面的設定,
用戶只能創建26個文件。實際應用中,可以根據需要調整inodes的值,比如,你要裝一個基於文本庫的程序,如lb5000(一種webbbs),
一些cgi文章管理等系統,你就要適當的調大inode的hard設定。
常見的quota命令
# edquota -t對quota用戶使用軟限制之前的時間設定,days,hours,minutes或seconds都可以是此設定的單位,值只要是合理就可以。
Time units may be: days, hours, minutes, or seconds
Grace period before enforcing soft limits for users:
/pub: block grace period: 1 day, file grace period: 1 day
# repquota -a報告文件系統關於quota的信息。
Block limits File limits
User used soft hard grace used soft hard grace
wheel -- 2 0 0 - 1 0 0 -
operator -- 128 0 0 - 2 0 0 -
mysql -- 18 0 0 - 9 0 0 -
vhostuser -- 36164 100000 100050 - 342 1000 1005 -
Block limits File limits
User used soft hard grace used soft hard grace
root -- 9136 0 0 - 12 0 0 -
mysql -- 18 0 0 - 9 0 0 -
testmin -- 18 1000 1050 - 9 1000 1005 -
web -- 22152 0 0 - 122 0 0 -
coms_cn -- 1550 0 0 - 177 0 0 -
c4st -+ 3438 100000 100020 - 25 25 26 22:56
# Quota :顯示用戶的磁盤使用情況和上限。
-g 顯示用戶所在組的組配額
-l 不顯示NFS系統上的配額
-u 顯示用戶配額
-q 顯示使用情況超過配額的簡要信息
-v 檢查用戶的quota設置
# edquota -p test c4st c4st1 c4st2.....
將把用戶test的配額設定復制給用戶c4st c4st1 c4st2.....
# quotacheck -a這個命令可以定期執行,用來檢查全部設定是否正常(可以放到crontab裡執行)。
Copyright © Linux教程網 All Rights Reserved