歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> 使用QUOTA(磁盤配額)來限制用戶空間

使用QUOTA(磁盤配額)來限制用戶空間

日期:2017/2/27 9:45:37   编辑:更多Linux
虛擬主機中經常要限制用戶空間的大小和文件的數量。這些限制在Linux和FreeBSD中都是用QUOTA來實現的。這裡我說下在FreeBSD下實現的方法;開啟QUOTA支持首先需要修改內核加入對quota的支持 machine i386cpu I686_CPU#ident GENERICident CNOSvhostmaxusers 0options 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 secondsGrace 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裡執行)。




原文鏈接:http://cnfug.org/journal/systems/2004/000020.Html



Copyright © Linux教程網 All Rights Reserved