天天看點

mysql使用者配額_使用QUOTA(磁盤配額)來限制使用者空間

虛拟主機中經常要限制使用者空間的大小和檔案的數量。這些限制在linux和FreeBSD中都是用QUOTA來實作的。這裡我說下在FreeBSD下實作的方法;

開啟QUOTA支援

首先需要修改核心加入對quota的支援

machine i386

cpu I686_CPU

#ident GENERIC

ident CNOSvhost

maxusers 0

options QUOTA #就是這行了。

修改好後重新編譯核心。

然後在/etc/rc.conf裡加入:

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裡執行)。

注:任何轉載或摘抄請注明文章出處(中文FreeBSD使用者組 http://www.cnfug.org)