磁盘配额 (Quota)

2018-09-11  本文已影响16人  蝉溪一梦

所谓磁盘配额,就是设置某一个文件系统(分区)内的用户可使用空间大小。

用途

实现步骤如下:

  1. 创建3个用户
#!/bin/bash
#program:Create 3 users and specify the user group.
#date:2017-02-27
#author:racher
#email:1576768715@qq.com

groupadd myquotagrp
for username in myquota1 myquota2 myquota3
do
        useradd -g myquotagrp $username
        echo "123.com" | passwd --stdin $username
done

  1. 文件系统支持
    • 检查/home是否是独立的文件系统
    • 用mount查询一哈/hoem的文件系统格式
[root@localhost home]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda5       4.8G  2.0G  2.6G  44% /
tmpfs           372M     0  372M   0% /dev/shm
/dev/sda1       190M   33M  147M  19% /boot
/dev/sda2       4.0G   33M  4.0G   1% /home

[root@localhost home]# mount | grep home
/dev/sda2 on /home type xfs (rw)

  1. 手动加入quota支持
[root@localhost home]# mount -o remount,usrquota,grpquota /home
[root@localhost home]# mount | grep home
/dev/sda2 on /home type xfs (rw,usrquota,grpquota)

  1. 开机自动挂载
    • /etc/fstab
    /dev/sda2                                 /home                   ext4     defaults,usrquota,grpquota 1 2

  1. 生成配置文件
[root@rhel6 test]# quotacheck -avug


[root@rhel6 test]# ls -a -l
total 40
drwxr-xr-x   3 root root  4096 Feb 28 18:25 .
drwxr-xr-x. 30 root root  4096 Feb 26 14:07 ..
-rw-------   1 root root  6144 Feb 28 18:25 aquota.group
-rw-------   1 root root  6144 Feb 28 18:25 aquota.user
drwx------   2 root root 16384 Feb 28 18:18 lost+found

  1. 启动quota
[root@rhel6 test]# quotaon -auvg
/dev/sdb1 [/test]: group quotas turned on
/dev/sdb1 [/test]: user quotas turned on

  1. quota 设置大小

    命令编辑:

    setquota -u jhadmin 100 150 0 0 /home/
    

    内容设置:

    [root@rhel6 test]# edquota -u zz
    
    Disk quotas for user zz (uid 16777256):
      Filesystem                   blocks       soft       hard     inodes     soft     hard
      /dev/sdb1                         0     500000     600000          0        0        0
    
    
  2. 修改宽限时间

[root@rhel6 test]# 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/sdb1                     3days                  7days
~                                                                          
~                                           
  1. 测试
[zz@rhel6 test]$ dd if=/dev/zero of=gkd bs=10M count=100
dd: writing `gkd': Disk quota exceeded
1+0 records in
0+0 records out
0 bytes (0 B) copied, 0.00526488 s, 0.0 kB/s

  1. 查询使用情况
[root@rhel6 /]# quota -uvs zz
Disk quotas for user zz (uid 16777256): 
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdb1    586M*   489M    586M   6days       2       0       0        

  1. 复制zz用户给jhadmin
[root@rhel6 /]# edquota -p zz jhadmin123
[root@rhel6 /]# quota -uvs jhadmin123
Disk quotas for user jhadmin123 (uid 16777267): 
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdb1       0    489M    586M               0       0       0        

  1. 查询所有用户情况
[root@rhel6 /]# repquota -auvs
*** Report for user quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --      20       0       0              2     0     0       
nobody    --       0    489M    586M              0     0     0       
#user1 +-    586M    489M    586M  6days       2     0     0       
#user2 --       0    489M    586M              0     0     0       
#user3 --       0    489M    586M              0     0     0       
#user4 --       0    489M    586M              0     0     0       

上一篇 下一篇

猜你喜欢

热点阅读