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
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/diannaorumen/)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、开启限制,生成用户和组限制文件
(本文来源于图老师网站,更多请访问http://m.tulaoshi.com/diannaorumen/)[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增加磁盘配额限制方面的修改,如果你需要减少磁盘配额限制不可使用本文方法进行修改。