现在的位置: 首页 > 综合 > 正文

磁盘配额操作系统步骤详解

2012年09月15日 ⁄ 综合 ⁄ 共 5218字 ⁄ 字号 评论关闭
以下文档由广东省linux公共服务技术支持中心(GDLC)独家提供---周末班学员实验稿。转载请未注明出处。

磁盘配额的功能:
1、        使用磁盘配额,系统管理员可以对磁盘空间进行管理,对不同用户在文件和磁盘容量上加以限制,这样就能有效的利用磁盘有限的容量。
2、        磁盘配额的两种磁盘管理方式
1)        基于文件inode的磁盘管理。
2)        基于磁盘存储块的磁盘管理。
3、        特点:磁盘配额是在每个用户,每个文件系统的基础上被处理的。
4、        磁盘配额的配置步骤
1)        修改/etc/fstab文件,在对应的分区上加用户配额(usrquota)或组配额(grpquota)。
2)        重新挂载分区,使其配额参数生效。
3)        创建配额数据库文件。aquota.user,aquota.group
4)        设置用户配额。edquota -u username
5)        设置组配额。  edquota -g groupname
6)        激活配额。    quotaon  -a
7)        禁用配额。    quotaoff -a
8)        测试配额。   

4.1、修改/etc/fstab文件,在对应的分区上加用户配额(usrquota)或组配额(grpquota)。
[root@client67 ~]# vi /etc/fstab
[root@client67 ~]# head /etc/fstab
# This file is edited by fstab-sync - see 'man fstab-sync' for details
LABEL=/1       /       ext3    defaults,usrquota,grpquota      1 1
LABEL=/boot1   /boot   ext3    defaults                         1 2
LABEL=/data    /data   ext3    defaults                             1 2
none           /dev/pts   devpts  gid=5,mode=620            0 0
none                /dev/shm    tmpfs   defaults               0 0
none           /proc       proc    defaults       0 0
none           /sys        sysfs   defaults        0 0
LABEL=/u01     /u01        ext3    defaults        1 2
LABEL=SWAP-sda6   swap     swap    defaults        0 0
[root@client67 ~]# mount
/dev/sda5 on / type ext3 (rw)
none on /proc type proc (rw)
none on /sys type sysfs (rw)
none on /dev/pts type devpts (rw,gid=5,mode=620)
usbfs on /proc/bus/usb type usbfs (rw)
/dev/sda1 on /boot type ext3 (rw)
/dev/sda3 on /data type ext3 (rw)
none on /dev/shm type tmpfs (rw)
/dev/sda2 on /u01 type ext3 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/proc on /var/named/chroot/proc type none (rw,bind)
/dev/sda7 on /media/sda7 type ext3 (rw)
4.2、重新挂载分区,使其配额参数生效。
[root@client67 ~]# mount -o remount /
[root@client67 ~]# mount |grep sda5
/dev/sda5 on / type ext3 (rw,usrquota,grpquota)
4.3、创建配额数据库文件。
[root@client67 ~]# quotacheck -mcvugf /
quotacheck: Scanning /dev/sda5 [/] quotacheck: Cannot stat old user quota file: 没有那个文件或目录
quotacheck: Cannot stat old group quota file: 没有那个文件或目录
quotacheck: Cannot stat old user quota file: 没有那个文件或目录
quotacheck: Cannot stat old group quota file: 没有那个文件或目录
done
quotacheck: Checked 15796 directories and 118640 files
quotacheck: Old file not found.
quotacheck: Old file not found.
[root@client67 ~]# ls /
aquota.group  boot  etc     lib         misc  proc  selinux  tftpboot usraquota.user   data  home    lost+found  mnt   root  srv      tmp  var bin         dev   initrd  media       opt   sbin  sys      u01
4.4、设置用户配额,设置xyz的软限额为1000k,硬限额为1500k;文件个数的软限额为5,硬限制为8.
[root@client67 ~]# useradd xyz
[root@client67 ~]# edquota -u xyz
Disk quotas for user xyz (uid 8893):
Filesystem  blocks  soft  hard    files  soft   hard  
/dev/sda5    32   1000    1500    1       5       8
[root@client67 ~]#
4.5、启动配额。
[root@client67 ~]# quotaon /
4.6、查看配额状态。
[root@client67 ~]# quotastats
Kernel quota version: 6.5.1
Number of dquot lookups: 81
Number of dquot drops: 1
Number of dquot reads: 6
Number of dquot writes: 0
Number of quotafile syncs: 20
Number of dquot cache hits: 75
Number of allocated dquots: 6
Number of free dquots: 0
Number of in use dquot entries (user/group): 6
4.7、测试配额。
[root@client67 ~]# su - xyz
[xyz@client67 ~]$ whoami
xyz
4.8、创建1M的测试文件
[xyz@client67 ~]$ dd if=/dev/zero of=file1 bs=1024k count=1
sda5: warning, user block quota exceeded.
读入了 1+0 个块
输出了 1+0 个块
4.9、显示配额状态。通过显示可知,已超过磁盘容量的软限额。
[xyz@client67 ~]$ quota
Disk quotas for user xyz (uid 8893):
Filesystem  blocks  quota  limit  grace  files  quota  limit   grace
/dev/sda5    1032*   1000    1500   7days       1       5       8
4.10、创建测试文件
[xyz@client67 ~]$ touch a b c d e
sda5: warning, user file quota exceeded.
4.9、显示配额状态。通过显示可知,已超过文件个数的软限额。
[xyz@client67 ~]$ quota
Disk quotas for user xyz (uid 8893):
Filesystem  blocks quota limit grace  files   quota   limit   grace
/dev/sda5    1052*   1000    1500   6days     6*     5    8   7days
[xyz@client67 ~]$ touch f g h i
sda5: write failed, user file limit reached.
touch: cannot touch ‘h’: 超出磁盘限额
touch: cannot touch ‘i’: 超出磁盘限额
[xyz@client67 ~]$ quota
Disk quotas for user xyz (uid 8893):
Filesystem  blocks   quota limit grace  files  quota  limit  grace
/dev/sda5    1060*   1000    1500   6days       8*      5       8
[xyz@client67 ~]$ ls
a  b  c  d  e  f  file1  g
[xyz@client67 ~]$ exit
logout
4.10、查看所有用户的配额报表。
[root@client67 ~]# repquota -a
*** Report for user quotas on device /dev/sda5
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User           used    soft    hard  grace    used  soft  hard  grace
---------------------------------------------------------------------
root      -- 3225436       0       0         134168     0     0
daemon    --      20       0       0              3     0     0
lp        --       8       0       0              1     0     0
rpm       --   42940       0       0            111     0     0
netdump   --      16       0       0              2     0     0
rpcuser   --       8       0       0              1     0     0
smmsp     --      16       0       0              2     0     0
apache    --      24       0       0              3     0     0
squid     --      16       0       0              2     0     0
webalizer --      32       0       0              4     0     0
xfs       --       4       0       0              1     0     0
ntp       --      16       0       0              2     0     0
htt       --      28       0       0              4     0     0
quagga    --      40       0       0              5     0     0
amanda    --    1096       0       0             58     0     0
named     --     112       0       0             14     0     0
ldap      --       8       0       0              1     0     0
gdlc      --     104       0       0             13     0     0
hesx      --      12       0       0              2     0     0
test      --      96       0       0             12     0     0
test2     --      96       0       0             12     0     0
xyz       ++    1060    1000    1500  6days      8     5     8  6days
#500      --     476       0       0             14     0     0

[root@client67 ~]#

抱歉!评论已关闭.