磁盤配額quota用途:node
www server限制用戶網頁空間量bash
mail server限制用戶的郵件空間量ide
等測試
使用限制:ui
1.針對整個文件系統或者說整個分區server
2.核心必須支持quotaci
3.只對通常身份有限制,root無限制it
限制方式:io
1.限制inode數量,即建立文件的數量class
2.限制block數量,即管理用戶使用磁盤量的限制(經常使用)
限制值有兩個:
hard:當用戶決不能使用磁盤超過此值
soft:當用戶使用磁盤量低於soft時無問題,當使用磁盤量超過soft未超過hard時,每次登錄系統都會報警,且會給與一個寬限的時間點。
實例:
環境準備,文件系統/dev/sdg 掛載在/test_quota上,額外參數(defaults,usrquota,grpquota)
建立quota記錄文件,quota是分析整個文件系統,將每一個用戶能夠使用的inode和block記錄在文件系統的最頂層文件。而後在該記錄文件中使用每一個帳號去限制全部量。
[root@www ~]# quotacheck -avug #-a根據掃描全部/etc/mtab支持的quota的文件系統,v顯示詳細過程 u針對用戶建立記錄文件 g根據羣組建立記錄文件 quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown. quotacheck: Scanning /dev/sdg [/test_quota] done quotacheck: Cannot stat old user quota file /test_quota/aquota.user: No such file or directory. Usage will not be substracted. quotacheck: Cannot stat old group quota file /test_quota/aquota.group: No such file or directory. Usage will not be substracted. quotacheck: Cannot stat old user quota file /test_quota/aquota.user: No such file or directory. Usage will not be substracted. quotacheck: Cannot stat old group quota file /test_quota/aquota.group: No such file or directory. Usage will not be substracted. quotacheck: Checked 2 directories and 0 files quotacheck: Old file not found. quotacheck: Old file not found. [root@www ~]#
啓動quota服務,使用quotaon命令,選項-avug,關閉quota服務使用quotaoff,選項-a -u -g
[root@www ~]# quotaon -avug /dev/sdg [/test_quota]: group quotas turned on /dev/sdg [/test_quota]: user quotas turned on
編輯賬號和羣組的限制值和寬限時間,使用edquota命令
-u + 用戶,修改用戶的限制值
-g + 羣組,修改羣組的限制值
-t + 時間,修改限制值
-p 複製範本
[root@www ~]# edquota testquota -u Disk quotas for user testquota (uid 665): Filesystem blocks soft hard inodes soft hard /dev/sdg 0 5 10 0 4 10 [root@www ~]# edquota -p testquota -u testquota1 #複製規則給其餘用戶
設置寬限時間,默認7天。
[root@www ~]# edquota testquota -u 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/sdg 7days 7days
查看每一個用戶的限制值
[root@www ~]# quota -uvs testquota testquota1 Disk quotas for user testquota (uid 665): Filesystem blocks quota limit grace files quota limit grace /dev/sdg 0 5 10 0 4 10 Disk quotas for user testquota1 (uid 666): Filesystem blocks quota limit grace files quota limit grace /dev/sdg 0 5 10 0 4 10 [root@www ~]#
測試:
[testquota@www test_quota]$ touch a [testquota@www test_quota]$ touch b [testquota@www test_quota]$ touch c sdg: warning, user file quota exceeded. [testquota@www test_quota]$ touch d [testquota@www test_quota]$ touch f [testquota@www test_quota]$ touch e [testquota@www test_quota]$ touch i [testquota@www test_quota]$ touch w [testquota@www test_quota]$ touch o sdg: write failed, user file limit reached. touch: 沒法建立"o": 超出磁盤限額 [testquota@www test_quota]$