RedHat Enterprise Linux AS5 Quota的配置实战

来源:互联网 发布:网络黑客高手qq群2016 编辑:程序博客网 时间:2024/06/05 02:15

试着在RHEL AS5上配置了Quota,记录如下:

 

增加了一个硬盘/dev/hdb1,用于存放用户数据,挂载在/home/extra下。

1、修改/etc/fstab 

   /dev/hdb1  /home/extra             ext3    defaults,noatime,usrquota,grpquota         1 2

 

红色部分为增加的部分,注意逗号之间没有空格。

 

2、建立配额文件

    # cd /home/extra

    #touch aquota.user
    #touch aquota.group
    #chmod 600 aquota.user
    #chmod 600 aquota.group

Quota使用了新的配额文件,旧的文件是quota.user和quota.group

如果用了这两个旧文件格式,启动Quota的时候会出现错误:“Quota format not supported in kernel”

可以使用convertquota命令来转换。

 

 

3、重新挂载/dev/hdb1

   # mount -o remount /home/extra

 

4、扫描磁盘,初始化配额表

  #quotacheck -uvg /home/extra

Note: Ubuntu下不需要创建aquota.user和aquota.group,使用quotacheck -cug /home/extra会自动生成。

 

5、为用户设定磁盘配额

  # edquota -u test

   Disk quotas for user test (uid 517):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/hdb1                 0          0          0          0        0        0

 

可以看出该用户还没有使用任何硬盘。各个字段的含义:

blocks:已经使用的磁盘块(1k bytes)

soft:软限额大小,如果用户超出了这个限额,系统会发出警告,如果在设定的时间内还没有回到该限额以下,系统将拒绝该用户使用额外的磁盘空间。

hard:硬限额,用户不允许超出的磁盘限制

inodes:用户已经使用的inodes数

soft和hard含义同上,不过,这里是限制用户创建的文件/目录总数。

 

限定25G, 最大30G,修改为:

Disk quotas for user test (uid 517):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/hdb1                 0          26214400         31457280          0        0        0

 

如果要设定整个群组能使用的磁盘限额,可以用下面的命令:

#edquota -g testgrp

 

6、修改软限额期限

# edquota -t

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/hdb1                             7days                  7days

 

默认为7天,修改为希望的值,比如3天。

 

7、复制到其他用户

可以一个一个的复制:

# edquota -p test test1

也可以使用awk命令来批处理:

edquota -p test `awk -F: '$3 > 499 {print $1}' /etc/passwd`

复制到uid大于499的所有用户,我的系统上有一个用户nfsnobody也符合这个条件,手动关闭它的限额。

# edquota -u nfsnobody

soft和hard改为0

 

8、启动磁盘配额

# quotaon -av

设置开机自动启动:

# vi /etc/rc.d/rc.local

/sbin/quotaon -av

 

9、查看磁盘配额

整体使用情况:

# repquota -a

*** Report for user quotas on device /dev/hdb1
Block grace time: 3days; Inode grace time: 3days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --  195616       0       0              4     0     0 

查看用户的配额情况:

# quota -vu test

Disk quotas for user test (uid 517):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
/dev/hdb1                  0  26214400 31457280               0       0       0 

 

10、关闭Quota

#quotaoff -av

 

11、其他应用

可以对WWW空间、FTP空间、Email空间进行磁盘配额限制。

注意:Quota只能基于磁盘分区进行配额管理,不能基于目录进行配额管理,因此只能把数据存放在有配额限制的分区,再用符号链接到实际应用的目录。

 

参考文章:

http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch28_:_Managing_Disk_Usage_with_Quotas

http://man.chinaunix.net/linux/how/Quota.html

http://linux.chinaunix.net/techdoc/system/2008/09/15/1032372.shtml

 

原创粉丝点击