centos7磁盘配额

1. 检查软件包

[root@localhost ~]# rpm -qa | grep xfsprogs
xfsprogs-4.5.0-8.el7.x86_64
确保这个包已经安装,如果没有安装,可以用yum安装
yum -y install xfsprogs

2. 逻辑卷正常挂载使用

   95  ls /dev/vg01/lv01 
   96  mkfs -t xfs /dev/vg01/lv01
   97  ls /disk/
  104  mount -o usrquota,grpquota /dev/vg01/lv01 /disk
  usrquota表示用户的磁盘配额  grpquota表示组磁盘配额

[root@localhost ~]# chmod 777 /disk/

3. 磁盘配额的配置

[root@localhost ~]# useradd zhangsan
[root@localhost ~]# passwd zhangsan
Changing password for user zhangsan.
New password: 
BAD PASSWORD: The password fails the dictionary check - it is too simplistic/systematic
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@localhost ~]# xfs_quota -x -c 'limit -u bsoft=10M bhard=20M isoft=10 ihard=20 zhangsan' /disk
命令参数解释:
- x 专家模式,加入此参数之后,才可以对磁盘配额进行设置或者修改
- c 后边跟上要执行的操作
- limit 表示进行限制
- u  表示对用户进行限制
- g 表示对组进行限制
- bsoft 对空间进行软限制
- bhard 对空间进行硬限制
- isoft 对文件个数进行软限制
- ihard 对文件个数进行硬限制

4. 查看磁盘配额

[root@localhost ~]# xfs_quota -c 'quota -uv zhangsan' /disk
Disk quotas for User zhangsan (1001)
Filesystem              Blocks      Quota      Limit  Warn/Time      Mounted on
/dev/mapper/vg01-lv01
                             0      10240      20480   00 [--------] /disk
命令参数详解:
- u 用户
- v 详细信息
- zhangsan 显示张三用户的限制信息

输出结果列表解释:
- Blocks: 已经写入的大小
- Quota:软限制的大小
- Limit:硬限制的大小

[root@localhost ~]# xfs_quota -c 'quota -i -uv zhangsan' /disk
Disk quotas for User zhangsan (1001)
Filesystem               Files      Quota      Limit  Warn/Time      Mounted on
/dev/mapper/vg01-lv01
                             0         10         20   00 [--------] /disk

5. 验证磁盘配额

[root@localhost ~]# su zhangsan
[zhangsan@localhost root]$ touch /disk/{1..10}.txt
[zhangsan@localhost root]$ touch /disk/11.txt
[zhangsan@localhost root]$ touch /disk/12.txt
[zhangsan@localhost root]$ touch /disk/13.txt
[zhangsan@localhost root]$ touch /disk/14.txt
[zhangsan@localhost root]$ touch /disk/{15..20}.txt
[zhangsan@localhost root]$ touch /disk/21.txt
touch: cannot touch ‘/disk/21.txt’: Disk quota exceeded

[zhangsan@localhost root]$ rm -rf /disk/*
[zhangsan@localhost root]$ dd if=/dev/zero of=/disk/testdb bs=19M count=1
1+0 records in
1+0 records out
19922944 bytes (20 MB) copied, 0.0881978 s, 226 MB/s
[zhangsan@localhost root]$ dd if=/dev/zero of=/disk/test bs=19M count=1
dd: error writing ‘/disk/test’: Disk quota exceeded
1+0 records in
0+0 records out
1048576 bytes (1.0 MB) copied, 0.039857 s, 26.3 MB/s
[zhangsan@localhost root]$ ls /disk/
test  testdb
[zhangsan@localhost root]$ ls -l /disk
total 20480
-rw-rw-r-- 1 zhangsan zhangsan  1048576 Aug 27 11:58 test
-rw-rw-r-- 1 zhangsan zhangsan 19922944 Aug 27 11:57 testdb

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值