Linux 磁盘管理 六(Raid、LVM、Quota)

()、磁盘配额

1、建立磁盘配额

1-1、修改挂载参数

 

[root@localhost ~]# mount -o usrquota,grpquota /dev/LVMonRaid/LogicLV1 /mnt/lv1

如果要永久修改挂在参数,就要修改/etc/fstab文件

 

[root@localhost ~]# vi /etc/fstab 

LABEL=/                 /                ext3    defaults        1 1

tmpfs                   /dev/s           tmpfs   defaults        0 0

devpts                  /dev/pts         devpts  gid=5,mode=620  0 0

sysfs                   /sys              sysfs   defaults        0 0

proc                    /proc            proc    defaults        0 0

LABEL=SWAP-sda2         swap            swap    defaults        0 0

/dev/LVMonRaid/LogicLV1 /mnt/lv1           ext3    defaults,usrquota,grpquota 1 2

   

1-2、初始化磁盘配额库

 

[root@localhost ~]# quotacheck -ucg /dev/LVMonRaid/LogicLV1

 

    1-3、检查磁盘配额库是否建立成功

 

 [root@localhost ~]# ls /mnt/lv1

aquota.group  aquota.user  lost+found

挂载点有aquota.groupaquota.user两个文件,说明磁盘初始化完成。

 

2、磁盘配额的启用与停用

2-1、查询LV上磁盘配额启用情况

 

[root@localhost ~]# quotaon -p /mnt/lv1

group quota on /mnt/lv1 (/dev/mapper/LVMonRaid-LogicLV1) is off

user quota on /mnt/lv1 (/dev/mapper/LVMonRaid-LogicLV1) is off

 

2-2、启用LV上的磁盘配额

 

[root@localhost ~]# quotaon /mnt/lv1

[root@localhost ~]# quotaon -p /mnt/lv1

group quota on /mnt/lv1 (/dev/mapper/LVMonRaid-LogicLV1) is on

user quota on /mnt/lv1 (/dev/mapper/LVMonRaid-LogicLV1) is on

 

    2-3、停用LV上的磁盘配额

 

[root@localhost ~]# quotaoff /mnt/lv1

[root@localhost ~]# quotaon -p /mnt/lv1

group quota on /mnt/lv1 (/dev/mapper/LVMonRaid-LogicLV1) is off

user quota on /mnt/lv1 (/dev/mapper/LVMonRaid-LogicLV1) is off

 

3、设置磁盘配额

3-1、使用edquota设置磁盘配额,分别设置区域配额和索引节点配额。

        3-1-1、设置磁盘配额

 

[root@localhost ~]# edquota -ug user1 /mnt/lv1

 

Disk quotas for group user1 (gid 500):

  Filesystem                              blocks       soft       hard     inodes     soft     hard

  /dev/mapper/LVMonRaid-LogicLV1          0           4000      5000          0     4       5

 

        3-1-2、更改/mnt/lv1的权限为777,更换user1用户向该文件夹保存文件

 

[root@localhost ~]# chmod 777 /mnt/lv1

[root@localhost ~]# su - user1

[user1@localhost ~]$ ll

总计 4

-rw-r--r-- 1 root root 1007 08-23 22:25 test.txt

[user1@localhost ~]$ for i in 1 2 3 4 5 ;do cp test.txt /mnt/lv1/test${i}.txt;done

[user1@localhost ~]$ for i in 6 ;do cp test.txt /mnt/lv1/test${i}.txt;done       

dm-0: warning, user file quota exceeded.

 

    3-2、使用setquota设置磁盘配额

        3-2-1、设置磁盘配额

 

[root@localhost ~]# setquota user2 4000 5000 4 5 /mnt/lv1

 

        3-2-2、更换user2用户向/mnt/lv1保存文件

 

[root@localhost ~]# su - user2

[user2@localhost ~]$ ll

总计 4

-rw-r--r-- 1 user2 user2 1007 08-23 22:55 test.txt

[user2@localhost ~]$ for i in 1 2 3 4 ; do cp test.txt /mnt/lv1/test${i}.txt ; done

[user2@localhost ~]$ for i in 5 ; do cp test.txt /mnt/lv1/test${i}.txt ; done  

dm-0: warning, user file quota exceeded.

 

4、管理磁盘配额

    4-1、查看磁盘配额状况

 

[root@localhost lv1]# quota user2

Disk quotas for user user2 (uid 501):

     Filesystem  blocks   quota         limit    grace   files       quota   limit   grace

/dev/mapper/LVMonRaid-LogicLV1          20    4000    5000      5*      4       5       

 

    4-2、产生磁盘配额表

 

[root@localhost lv1]# repquota -a

*** Report for user quotas on device /dev/mapper/LVMonRaid-LogicLV1

Block grace time: 7days; Inode grace time: 7days

                        Block limits                File limits

User          used    soft    hard  grace        used  soft  hard  grace

-------------------------------------------------------------------------------------------------------------------

root      --   34092       0       0              4     0     0      

user2     -+      20    4000    5000              5     4     5  6days

 

 

4-3、修改期限

 

[root@localhost ~]# 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/mapper/LVMonRaid-LogicLV1                  7days                  7days

 

5、使用脚本为系统用户设置磁盘配额

 

[root@localhost ~]# vi quota.sh

 

#!/bin/bash

for user in $(cat /etc/passwd | awk -F : '{if ($3>=500) {print $1}}')

do

  setquota ${user} 4000 5000 4 5 /mnt/lv1

done

~               

[root@localhost ~]# repquota -a

*** Report for user quotas on device /dev/mapper/LVMonRaid-LogicLV1

Block grace time: 7days; Inode grace time: 7days

                        Block limits                File limits

User            used    soft    hard  grace    used  soft  hard  grace

----------------------------------------------------------------------

root      --   34092       0       0              4     0     0      

user1     --      16    4000    5000              4     4     5      

user2     -+      20    4000    5000              5     4     5  6days

 

 

你可能感兴趣的:(linux,raid,lvm,quota,磁盘管理)