linux下的磁盤配額簡介暨 linux下加挂硬碟續
實驗環境 VMware 6.5.2 +redhat Enterprise 5 as
<a href="http://yuzeying.blog.51cto.com/attachment/200904/30/644976_1241090854QR9U.jpg"></a>
以上是核心版本,還有友善起見加挂一塊硬碟
這隻是我的環境 實驗與版本沒有關系
首先解釋一下 磁盤配額
它是特定使用者在指定的分區上使用空間大小的限制
特定使用者這裡是不包括root的
指定的分區的意思可不是檔案夾,
<a href="http://yuzeying.blog.51cto.com/attachment/200904/30/644976_1241090856VMle.jpg"></a>
這個是windows 2003 的磁盤配額畫面,大家做個比較
磁盤配額能幹什麼
常見的比如各大網站對我們郵箱的容量限制
在這裡有這麼幾個作用:
容量配額 (限制特定使用者在硬碟上的使用大小)
檔案個數配額 (限制可以存儲的檔案個數)
軟限制 類似與警告級别 寫資料會報警
應限制 達到這個數量後在寫資料室寫不進的
還有一點 磁盤配額是對你的整個分區起作用的,是以實驗環境挂塊硬碟友善測試
實驗開始
修改自動挂載檔案
[root@localhost ~]# df
檔案系統 1K-塊 已用 可用 已用% 挂載點
/dev/sda3 7516200 4052356 3075876 57% /
/dev/sda1 101086 11060 84807 12% /boot
tmpfs 127812 0 127812 0% /dev/shm
/dev/sdb1 3850292 73248 3581456 3% /test
[root@localhost ~]# vi /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda2 swap swap defaults 0 0
# Beginning of the block added by the VMware software
.host:/ /mnt/hgfs vmhgfs defaults,ttl=5 0 0
# End of the block added by the VMware software
LABEL=/test /test ext3 defaults,usrquota 1 2
~
在defaults後面添加,usrquota 小心這裡是英文狀态下的逗号
儲存退出
之後我們重新挂載一下
[root@localhost ~]# mount -o remount /test
[root@localhost ~]# quotacheck -cmu /test
建立配額檔案
[root@localhost ~]# cd /test
[root@localhost test]# ls
aquota.user lost+found
[root@localhost test]#
但這時你用vi打開它是不行的,會發現全是亂碼
[root@localhost test]# vi aquota.user
<a href="http://yuzeying.blog.51cto.com/attachment/200904/30/644976_1241090866fDqv.jpg"></a>
之後 建立一個普通使用者aa
[root@localhost test]# useradd aa
[root@localhost test]# passwd aa
Changing password for user aa.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
指令成功執行
下一步:進行使用者配額配置
[root@localhost test]# edquota -u aa
Disk quotas for user aa (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 0 0 0 0 0
~ 這是針對的分區 軟限制 硬限制 軟限制 硬限制
~ || 文 件 大 小 || 文 件 個 數 |
我們是用指令的方式進入檔案的 他的具體操作就是标準vi操作
表示目前使用者已經占用的檔案個數,和大小 以k計算 比如現在 我們限制檔案大小為10k
軟限制為9||||硬限制為10 ,檔案個數限制為5,軟限制為4硬限制為5
/dev/sdb1 10 9 10 5 4 5
[root@localhost test]# quotaon /test
啟動磁盤配額
[root@localhost test]# su - aa
[aa@localhost ~]$ cd /test
[aa@localhost test]$ mkdir aa
mkdir: 無法建立目錄 “aa”: 權限不夠
[aa@localhost test]$
為什麼沒權限
給一下他
[root@localhost test]# cd ..
[root@localhost /]# ll
總計 142
drwxr-xr-x 2 root root 4096 04-08 18:36 bin
drwxr-xr-x 4 root root 1024 04-08 18:11 boot
drwxr-xr-x 11 root root 3980 04-30 18:33 dev
drwxr-xr-x 101 root root 12288 04-30 18:46 etc
drwxr-xr-x 4 root root 4096 04-30 18:46 home
drwxr-xr-x 14 root root 4096 04-08 18:24 lib
drwx------ 2 root root 16384 04-08 18:00 lost+found
drwxr-xr-x 2 root root 4096 04-30 18:33 media
drwxr-xr-x 2 root root 0 04-30 18:33 misc
drwxr-xr-x 3 root root 4096 04-08 19:26 mnt
drwxr-xr-x 2 root root 0 04-30 18:33 net
drwxr-xr-x 2 root root 4096 2006-10-11 opt
dr-xr-xr-x 134 root root 0 04-30 18:33 proc
drwxr-x--- 20 root root 4096 04-30 18:34 root
drwxr-xr-x 2 root root 12288 04-08 19:26 sbin
drwxr-xr-x 4 root root 0 04-30 18:33 selinux
drwxr-xr-x 2 root root 4096 2006-10-11 srv
drwxr-xr-x 11 root root 0 04-30 18:33 sys
drwxr-xr-x 3 root root 4096 04-30 18:49 test
drwxrwxrwt 15 root root 4096 04-30 19:03 tmp
drwxr-xr-x 14 root root 4096 04-08 18:07 usr
drwxr-xr-x 24 root root 4096 04-08 18:30 var
[root@localhost /]# chmod 777 test
實驗環境就給他個最大權限吧
[aa@localhost ~]$ dd if=/dev/zero of=/test/aa
sdb1: write failed, user block limit reached.
dd: 正在寫入 “/test/aa”: 超出磁盤限額
9+0 records in
8+0 records out
4096 bytes (4.1 kB) copied, 0.0127423 seconds, 321 kB/s
[aa@localhost ~]$
這裡是複制一個檔案到test/aa下 他會不停地寫入0 字元直至寫滿為止,,
限額已經生效
[aa@localhost test]$ rm -rf aa
[aa@localhost test]$ ls
[aa@localhost test]$ touch aa
[aa@localhost test]$ touch bb
[aa@localhost test]$ touch cc
touch: 無法觸碰 “cc”: 超出磁盤限額
[aa@localhost test]$ touch dd
touch: 無法觸碰 “dd”: 超出磁盤限額
建到cc的時候已經是第五個了,是以建立失敗,建bb的時候由于是軟限制,是以還是能建的
最後取消磁盤配額quotaoff /
[root@localhost /]# quotaoff /test
[root@localhost /]#
寫在最後,隻是簡單的涉及磁盤配額,并不進行深入探讨,文中有不對的地方,還望看到的朋友多多指教,
本文轉自 yuzeying1 51CTO部落格,原文連結:http://blog.51cto.com/yuzeying/154493