centos6上增加磁碟配額限制

來源:互聯網
上載者:User

centos6上增加磁碟配額限制
建五個使用者,均需要進行磁碟配額限制,每個使用者的配額為 10MB (hard) 以及 8MB (soft)

0
環境
[root@localhost ~]# uname -a
Linux localhost.localdomain 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost ~]# nl /etc/issue
1 CentOS release 6.5 (Final)
2 Kernel \r on an \m

1
建5使用者vbirdN,這個是從鳥哥那借的
[root@hostalonetest ~]# vi au.sh
#!/bin/bash
groupadd vbirdgroup
for username in vbird1 vbird2 vbird3 vbird4 vbird5
do
useradd -G vbirdgroup $username
echo "password" | passwd --stdin $username
done

[root@hostalonetest ~]# sh au.sh
Changing password for user vbird1.
passwd: all authentication tokens updated successfully.
Changing password for user vbird2.
passwd: all authentication tokens updated successfully.
Changing password for user vbird3.
passwd: all authentication tokens updated successfully.
Changing password for user vbird4.
passwd: all authentication tokens updated successfully.
Changing password for user vbird5.
passwd: all authentication tokens updated successfully.

2
掃一眼家目錄
[root@hostalonetest ~]# ll /home/
total 28
drwx------. 4 vbird1 vbird1 4096 Dec 1 15:57 vbird1
drwx------. 4 vbird2 vbird2 4096 Dec 1 15:57 vbird2
drwx------. 4 vbird3 vbird3 4096 Dec 1 15:57 vbird3
drwx------. 4 vbird4 vbird4 4096 Dec 1 15:57 vbird4
drwx------. 4 vbird5 vbird5 4096 Dec 1 15:57 vbird5
drwx------. 4 zxw zxw 4096 Sep 18 18:03 zxw

瞅一下vb1的組和id
[root@hostalonetest ~]# id vbird1
uid=503(vbird1) gid=504(vbird1) groups=504(vbird1),503(vbirdgroup)

3
給剛建的這幾位準備一個用於這幾個使用者都能訪問的目錄/home/vbirdgroup
[root@hostalonetest ~]# mkdir /home/vbirdgroup
[root@hostalonetest ~]# chgrp vbirdgroup /home/vbirdgroup/
[root@hostalonetest ~]# chmod 2770 /home/vbirdgroup/

[root@hostalonetest ~]# ll -d /home/zhaoxiaowei/
drwx---rwx. 5 zhaoxiaowei zhaoxiaowei 4096 Sep 18 14:13 /home/zhaoxiaowei/

設定第四位,它位於三位許可權序列的前面,第四位元字取值是4,2,1,代表意思如下:
4,執行時設定使用者ID,用於授權給基於檔案屬主的進程,而不是給建立此進程的使用者。
2,執行時設定使用者組ID,用於授權給基於檔案所在組的進程,而不是基於建立此進程的使用者。
1,設定粘著位。

4
現在 磁碟配額概要
在/home下進行quota,需要如下:
檔案系統的支援
quota 資料檔案建置
quota 啟動
建立使用者 quota 資訊

5
將 /home 獨立一個分區,因為 quota 僅支援 filesystem 而不支援單一目錄
/home上增加usrquota,grpquota
[root@localhost ~]# nl /etc/fstab

1 #
2 # /etc/fstab
3 # Created by anaconda on Tue Dec 2 18:52:50 2014
4 #
5 # Accessible filesystems, by reference, are maintained under '/dev/disk'
6 # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
7 #
8 UUID=93cd7207-78c4-4a95-be1b-7451772c21ad / ext4 defaults 1 1
9 UUID=9a982f8d-d590-49f2-9cf1-e07a5b8238dd /boot ext4 defaults 1 2
10 UUID=c8939b59-9a73-45fa-bd5a-f016a5aa631e /home ext4 defaults,usrquota,grpquota 1 2
11 UUID=1f3d9eaf-e140-47ab-ae99-fcf1516d2070 swap swap defaults 0 0
12 tmpfs /dev/shm tmpfs defaults 0 0
13 devpts /dev/pts devpts gid=5,mode=620 0 0
14 sysfs /sys sysfs defaults 0 0
15 proc /proc proc defaults 0 0

6
卸載、載入/home,並查看/home項
[root@localhost ~]# umount /home/; mount -a
[root@localhost ~]# mount | grep home
/dev/sda3 on /home type ext4 (rw,usrquota,grpquota)

7
quotacheck產生配額檔案,結果如下
[root@localhost ~]# qutoacheck -avug
-bash: qutoacheck: command not found
[root@localhost ~]#

8
尋找、安裝 quota
[root@localhost ~]# find / -name qutoacheck
[root@localhost ~]#
[root@localhost ~]# rpm -qa | grep quota
quota-3.17-20.el6.x86_64

安裝
[root@localhost ~]# yum -y install quota-3.17-20.el6.x86_64
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: centos.ustc.edu.cn
* extras: centos.ustc.edu.cn
* updates: centos.ustc.edu.cn
base | 3.7 kB 00:00
base/primary_db | 4.6 MB 00:29
extras | 3.4 kB 00:00
extras/primary_db | 29 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 910 kB 00:05
Setting up Install Process
Nothing to do
[root@localhost ~]#

9
開啟限制,產生使用者和組限制檔案
[root@localhost ~]# quotacheck -avug
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/sda3 [/home] done
quotacheck: Cannot stat old user quota file /home/aquota.user: No such file or directory. Usage will not be substracted.
quotacheck: Cannot stat old group quota file /home/aquota.group: No such file or directory. Usage will not be substracted.
quotacheck: Cannot stat old user quota file /home/aquota.user: No such file or directory. Usage will not be substracted.
quotacheck: Cannot stat old group quota file /home/aquota.group: No such file or directory. Usage will not be substracted.
quotacheck: Checked 33 directories and 18 files
quotacheck: Old file not found.
quotacheck: Old file not found.

[root@localhost ~]# quotaon -avug
/dev/sda3 [/home]: group quotas turned on
/dev/sda3 [/home]: user quotas turned on

10
增加配額限制
[root@localhost ~]# edquota -u vbird1
Disk quotas for user vbird1 (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/sda3 32 8000 10000 8 0 0
單位是KB
[root@localhost ~]# edquota -u vbird2
。。。

[root@localhost ~]# edquota -p vbird1 vbird2 vbird3 vbird4 vbird5

11
查看配額
[root@localhost ~]# repquota -au
*** Report for user quotas on device /dev/sda3
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 24 0 0 3 0 0
zxw -- 32 0 0 8 0 0
vbird1 -- 32 8000 10000 8 0 0
vbird2 -- 32 8000 10000 8 0 0
vbird3 -- 32 8000 10000 8 0 0
vbird4 -- 32 8000 10000 8 0 0
vbird5 -- 32 8000 10000 8 0 0

12
開始測試
[vbird1@localhost ~]$ ll -h
total 7.6M
-rw-rw-r--. 1 vbird1 vbird1 1.7M Dec 2 14:01 cont.txt
-rw-r--r--. 1 root root 49K Dec 2 13:59 install.log
-rw-rw-r--. 1 vbird1 vbird1 5.8M Dec 2 14:02 v.txt
[vbird1@localhost ~]$

vb1寫檔案到達到軟式節流
[vbird1@localhost ~]$ nl cont.txt >> v.txt
sda3: warning, user block quota exceeded.
達到軟式節流,警告
[vbird1@localhost ~]$ ll -h
total 9.5M
-rw-rw-r--. 1 vbird1 vbird1 1.7M Dec 2 14:01 cont.txt
-rw-r--r--. 1 root root 49K Dec 2 13:59 install.log
-rw-rw-r--. 1 vbird1 vbird1 7.7M Dec 2 14:02 v.txt

vb1寫檔案到達到硬限制
[vbird1@localhost ~]$ nl cont.txt >> v.txt
sda3: write failed, user block limit reached.
nl: write error: Disk quota exceeded
達到硬限制,報錯
[vbird1@localhost ~]$
[vbird1@localhost ~]$ ll -h
total 9.8M
-rw-rw-r--. 1 vbird1 vbird1 1.7M Dec 2 14:01 cont.txt
-rw-r--r--. 1 root root 49K Dec 2 13:59 install.log
-rw-rw-r--. 1 vbird1 vbird1 8.1M Dec 2 14:03 v.txt

vb1再寫就不讓寫了
[vbird1@localhost ~]$ nl cont.txt >> v.txt
nl: write error: Disk quota exceeded
[vbird1@localhost ~]$ ll -h
total 9.8M
-rw-rw-r--. 1 vbird1 vbird1 1.7M Dec 2 14:01 cont.txt
-rw-r--r--. 1 root root 49K Dec 2 13:59 install.log
-rw-rw-r--. 1 vbird1 vbird1 8.1M Dec 2 14:03 v.txt

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.