磁盘配额

用quota来限制某一用户或者某一用户组的最大磁盘配额

[root@localhost ~]# umount /pub
[root@localhost ~]# mount -o usrquota,grpquota /dev/vdb1 /pub/ ##给目录/pub加入quota的支持,usrquota,grpquota分别是用户与用户组的quota文件系统支持参数
[root@localhost ~]# quotaon -ugv /dev/vdb1 ##启动quota的服务

[root@localhost ~]# edquota -u student ##设置student用户的quota限制值
[root@localhost ~]# quotaoff -a ##关闭全部系统的quota(根据/etc/mtab)

sk quotas for user student (uid 1000):
Filesystem    blocks       soft       hard     inodes     soft     hard
/dev/vdb1     102400          0       40000       1        0        0
文件系统(filesystem):说明该限制值是针对哪个文件系统(或pattition);
磁盘容量(blocks):这个数值为quota自己算出来的,单位为KB,勿修改;
soft :磁盘容量(block)的soft限制值,单位为KB
hard:block的hard限制值,单位为KB
文件数量(inodes):这个数值为quota自己算出来的,单位为个数,勿修改;
soft:inodes的soft限制值
hard::inode的hard限制值

具体代码块如下:

给用户设置最大可用内存
第一步,先删除之前建立好的分区
第二,重新建立分区
[root@localhost ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-20971519, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): +100M
Partition 1 of type Linux and of size 100 MiB is set

Command (m for help): wq
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@localhost ~]# partprobe   ##同步分区表
[root@localhost ~]# cat /proc/partitions 
major minor  #blocks  name

 253        0   10485760 vda
 253        1   10484142 vda1
 253       16   10485760 vdb
 253       17     102400 vdb1
[root@localhost ~]# mkfs.xfs /dev/vdb1   ##格式化
meta-data=/dev/vdb1              isize=256    agcount=4, agsize=6400 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=25600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkdir /pub
[root@localhost ~]# chmod 777 /pub
[root@localhost ~]# mount /dev/vdb1 /pub     
[root@localhost ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/vda1       10473900 3151160   7322740  31% /
devtmpfs          927072       0    927072   0% /dev
tmpfs             942660      80    942580   1% /dev/shm
tmpfs             942660   17012    925648   2% /run
tmpfs             942660       0    942660   0% /sys/fs/cgroup
/dev/vdb1          98988    5296     93692   6% /pub
[root@localhost ~]# blkid   ##列出正在使用的设备,
/dev/vda1: UUID="9bf6b9f7-92ad-441b-848e-0257cbb883d1" TYPE="xfs" 
/dev/vdb1: UUID="0059df4d-c979-47ad-85c4-ff69eef3ae6a" TYPE="xfs" 
[root@localhost ~]# su - student
Last login: Sat Apr 22 06:06:47 CST 2017 on pts/0
[student@localhost ~]$ dd if=/dev/zero of=/pub/file bs=1M count=20
20+0 records in
20+0 records out
20971520 bytes (21 MB) copied, 0.00967299 s, 2.2 GB/s
[student@localhost ~]$ dd if=/dev/zero of=/pub/file bs=1M count=100
dd: error writing ‘/pub/file’: Disk quota exceeded  ##超过硬盘大小
21+0 records in
20+0 records out
20971520 bytes (21 MB) copied, 0.0123107 s, 1.7 GB/s
[student@localhost ~]$ dd if=/dev/zero of=/pub/file bs=1M count=200
dd: error writing ‘/pub/file’: Disk quota exceeded  ##超过硬盘大小
21+0 records in
20+0 records out
20971520 bytes (21 MB) copied, 0.0142118 s, 1.5 GB/s
[student@localhost ~]$ exit
logout
[root@localhost ~]# umount /pub
[root@localhost ~]# mount -o usrquota,grpquota /dev/vdb1 /pub/ ##给目录/pub加入quota的支持,usrquota,grpquota分别是用户与用户组的quota文件系统支持参数
[root@localhost ~]# quotaon -ugv /dev/vdb1  ##启动quota的服务
quotaon: Enforcing group quota already on /dev/vdb1
quotaon: Enforcing user quota already on /dev/vdb1

由于代码块里显示不了图片,所以将这条命令单独拉出来
[root@localhost ~]# edquota -u student这里写代码片 ##设置student用户的quota限制值
这里写图片描述
hard改为:4000
这里写图片描述

[root@localhost ~]# ls -l /pub/
total 20480
-rw-rw-r--. 1 student student 20971520 Apr 22 06:12 file
[root@localhost ~]# rm -fr /pub/file
[root@localhost ~]# su - student
Last login: Sat Apr 22 06:12:00 CST 2017 on pts/0
[student@localhost ~]$ dd if=/dev/zero of=/pub/file bs=1M count=20
dd: error writing ‘/pub/file’: Disk quota exceeded    ##超过硬盘大小
4+0 records in
3+0 records out
4096000 bytes (4.1 MB) copied, 0.0270411 s, 151 MB/s
[student@localhost ~]$ dd if=/dev/zero of=/pub/file bs=1M count=10
dd: error writing ‘/pub/file’: Disk quota exceeded   ##超过硬盘大小
4+0 records in
3+0 records out
4096000 bytes (4.1 MB) copied, 0.00244958 s, 1.7 GB/s
[student@localhost ~]$ exit
logout

root@localhost ~]# quotaoff -a    ##关闭全部系统的quota(根据/etc/mtab)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值