歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux管理 >> Linux維護

CentOS 6如何修改磁盤配額限制

為了避免用戶過度的使用磁盤空間,管理員會對磁盤空間進行配額限制,以免影響系統運行,但在有些時候,因為磁盤配額限制設置的不合理,導致磁盤空間不夠用,這時就需要對磁盤配額進行修改,下面小編就給大家介紹下CentOS 6如何修改磁盤配額限制。

CentOS建五個用戶,均需要進行磁盤配額限制,每個用戶的配額為 10MB (hard) 以及 8MB (soft)

環境

[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@linuxidc ~]# 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@linuxidc ~]# 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@linuxidc ~]# 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@linuxidc ~]# id vbird1

uid=503(vbird1) gid=504(vbird1) groups=504(vbird1),503(vbirdgroup)

3、給剛建的這幾個准備一個用於這幾個用戶都能訪問的目錄/home/vbirdgroup

[root@linuxidc ~]# mkdir /home/vbirdgroup

[root@linuxidc ~]# chgrp vbirdgroup /home/vbirdgroup/

[root@linuxidc ~]# chmod 2770 /home/vbirdgroup/

[root@linuxidc ~]# ll -d /home/linuxidc/

drwx---rwx. 5 linuxidc linuxidc 4096 Sep 18 14:13 /home/linuxidc/

設置第四位,它位於三位權限序列的前面,第四位數字取值是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

上面就是CentOS 6修改磁盤配額限制的方法介紹了,本文主要介紹的是CentOS增加磁盤配額限制方面的修改,如果你需要減少磁盤配額限制不可使用本文方法進行修改。

Copyright © Linux教程網 All Rights Reserved