Linux 磁盘配额配置<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
本次试验以/dev/sdb为例配置磁盘配额
首先对/dev/sdb进行分区,格式化
fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-261, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261):
Using default value 261
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         261     2096451   83  Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
 mkfs.ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
262144 inodes, 524112 blocks
26205 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912
Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
没开启磁盘配额前的状态如下:
mount /dev/sdb1 /mnt/sdb1
ls /mnt/sdb1
lost+found
[root@test2 ~]# useradd test1
[root@test2 ~]# passwd test1
Changing password for user test1.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@test2 ~]# chown -R test1 /mnt/sdb1
[root@test2 ~]# ll /mnt/sdb1
total 16
drwx------ 2 test1 root 16384 Sep 17 08:55 lost+found
[root@test2 ~]# umount /mnt/sdb1
[root@test2 ~]# mount -o usrquota,grpquota /dev/sdb1 /mnt/sdb1
查看是否启用quota
[root@test2 ~]# cat /etc/mtab
/dev/sda3 / ext3 rw 0 0
proc /proc proc rw 0 0
sysfs /sys sysfs rw 0 0
devpts /dev/pts devpts rw,gid=5,mode=620 0 0
/dev/sda1 /boot ext3 rw 0 0
tmpfs /dev/shm tmpfs rw 0 0
none /proc/sys/fs/binfmt_misc binfmt_misc rw 0 0
/dev/sdb1 /mnt/sdb1 ext3 rw,usrquota,grpquota 0 0
进入单用户模式
Init 1
Quotacheck需要安装quota.i386 1:3.13-1.2.5.el5
[root@test2 ~]# which quotacheck
/sbin/quotacheck
[root@test2 ~]# quotacheck -cvug /dev/sdb1
quotacheck: Scanning /dev/sdb1 [/mnt/sdb1] quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
done
quotacheck: Checked 3 directories and 2 files
quotacheck: Old file not found.
[root@test2 ~]# ls /mnt/sdb1
aquota.group  aquota.user  lost+found
有aquota.user文件说明磁盘配额检测成功;
启用磁盘配额
quotaon /dev/sdb1
Init 3
mkdir /mnt/sdb1/aaa
chown -R test1 /mnt/sdb1/aaa
对用户test1进行配额限制
edquota -u test1
Disk quotas for user test1 (uid 500):
  Filesystem                   blocks       soft       hard     inodes     soft     hard
  /dev/sdb1                        20        500        600          2        4        5
说明如下:blocks下面20代表目前实际大小 soft代表软限制为500k  硬限制为600k
          Inodes下表2代表目前有两个文件 soft代表软限制文件个数为4 硬限制个数为5
测试如下:
[root@test2 ~]# su test1
[test1@test2 root]$ quota
Disk quotas for user test1 (uid 500):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdb1      24     500     600         3     5       6
测试文件个数限制:限制为6,可以创建3个,第四个会报错
[test1@test2 root]$ cd /mnt/sdb1/aaa
[test1@test2 aaa]$ ls
[test1@test2 aaa]$ touch 111
[test1@test2 aaa]$ quota
Disk quotas for user test1 (uid 500):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdb1      24     500     600               4       5       6
[test1@test2 aaa]$ touch 222
[test1@test2 aaa]$ quota
Disk quotas for user test1 (uid 500):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdb1      24     500     600               5       5       6
[test1@test2 aaa]$ touch 333
sdb1: warning, user file quota exceeded.
[test1@test2 aaa]$ ll
total 0
-rw-rw-r-- 1 test1 test1 0 Sep 17 11:05 111
-rw-rw-r-- 1 test1 test1 0 Sep 17 11:05 222
-rw-rw-r-- 1 test1 test1 0 Sep 17 11:06 333
[test1@test2 aaa]$ quota
Disk quotas for user test1 (uid 500):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdb1      24     500     600               6*      5       6
[test1@test2 aaa]$ touch 444
sdb1: write failed, user file limit reached.
touch: cannot touch `444': Disk quota exceeded
[test1@test2 aaa]$ ll
total 0
-rw-rw-r-- 1 test1 test1 0 Sep 17 11:05 111
-rw-rw-r-- 1 test1 test1 0 Sep 17 11:05 222
-rw-rw-r-- 1 test1 test1 0 Sep 17 11:06 333
测试用户使用空间限制:500k警告 大于600不允许再创建
先创建一个大小400k的文件,名字为aaa1,创建成功;
[test1@test2 aaa]$ dd if=/dev/zero of=aaa1 bs=1k count=400
400+0 records in
400+0 records out
409600 bytes (410 kB) copied, 0.0142511 seconds, 28.7 MB/s
[test1@test2 aaa]$ quota
Disk quotas for user test1 (uid 500):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdb1     428     500     600               4       5       6
再创建一个大小100k的文件,名字为aaa2,创建成功,但警告
[test1@test2 aaa]$ dd if=/dev/zero of=aaa2 bs=1k count=100
sdb1: warning, user block quota exceeded.
100+0 records in
100+0 records out
102400 bytes (102 kB) copied, 0.00265624 seconds, 38.6 MB/s
[test1@test2 aaa]$ quota
Disk quotas for user test1 (uid 500):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sdb1     532*    500     600   7days       5       5       6
再创建一个大小100k的文件,名字为aaa3,可以创建,但只会使用剩余空间;
[test1@test2 aaa]$ dd if=/dev/zero of=aaa3 bs=1k count=100
sdb1: warning, user file quota exceeded.
sdb1: write failed, user block limit reached.
dd: writing `aaa3': Disk quota exceeded
65+0 records in
64+0 records out
65536 bytes (66 kB) copied, 0.00413993 seconds, 15.8 MB/s
[test1@test2 aaa]$ ls -lh
total 576K
-rw-rw-r-- 1 test1 test1 400K Sep 17 11:11 aaa1
-rw-rw-r-- 1 test1 test1 100K Sep 17 11:13 aaa2
-rw-rw-r-- 1 test1 test1  64K Sep 17 11:15 aaa3
此时已经达到了硬限制,再创建会提示失败
[test1@test2 aaa]$ dd if=/dev/zero of=aaa4 bs=1k count=100
sdb1: write failed, user file limit reached.
dd: opening `aaa4': Disk quota exceeded
[test1@test2 aaa]$ ls -lh
total 576K
-rw-rw-r-- 1 test1 test1 400K Sep 17 11:11 aaa1
-rw-rw-r-- 1 test1 test1 100K Sep 17 11:13 aaa2
-rw-rw-r-- 1 test1 test1  64K Sep 17 11:15 aaa3
Edquota -t  更改默认过期天数,默认天数为7天
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                     7days                  7days
使磁盘配额开机启动,操作如下:
[root@test2 ~]# cat /etc/fstab
LABEL=/                 /                       ext3    defaults        1 1
LABEL=/boot             /boot                   ext3    defaults        1 2
tmpfs                   /dev/shm                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/sdb1               /mnt/sdb1               ext3    defaults,usrquota,grpquota      1 1
备注:
如果每个用户都要这么麻烦的设置的话,那这种重复的体力劳动实在有点令人不寒而栗,而且也太浪费时间了。幸好edquota还有个-p参数(prototype)可以对已有的用户设置进行拷贝。例如,我们想对Jack、Tom、Chen三个用户使用和lanf一样的限额配置,可以使用如下的命令:
edquota -p lanf -u Jack Tom Chen
这样一来,这三个用户就被赋予了和lanf一样的磁盘配额。
对组的配额,除了edquota命令中对应-u参数的改为-g参数,例如下面对webterm1组的操作:
edquota -g webterm1

实际上,以上的限制只是对用户设定的硬限制在起作用。如果需要使软限制也起作用的话,还需要对用户的软限制设定宽限期——缺省的,软限制的宽限期是无穷大——这可以使用edquota命令的-t选项来实现。运行下面的命令:
edquota -t
edquota将打开缺省编辑器显示如下内容:
Time units may be:days,hours,minutes,or seconds
Grace period before enforcing soft limits for users:
/dev/sda5:block grace period:0 days,file grace period:0 days
可以使用天、小时、分、秒为单位来设定宽限期。例如,在下面这个例子中,磁盘空间限制的宽限期为两天,而文件数量限制的宽限期只有6个小时。
Time units may be:days,hours,minutes,or seconds
Grace period before enforcing soft limits for users:
/dev/sda5:block grace period:2 days,file grace period:6 hours

  b.通过setquota工具加入:

  比如加入用户bye2000的磁盘配额,执行以下命令:

setquota –u / 2000 2500 100 110 bye2000

  以下是setquota命令用法的简单描述:

setquota [ -u|-g ] 装载点 软块数 硬块数 软文件数 硬文件数 用户名/组名

◆查看用户磁盘使用情况
要查明某一个用户使用了多少磁盘空间,例如lanf,可以使用如下的命令:
quota -u lanf
显示:
Disk quotas for user lanf(uid 503):
Filesystem blocks quota limit grace file quota limit grace
/dev/sda5 3 102400 409800 1 12800 51200 
同样,可以使用quota -g groupname命令来参看某个组的磁盘使用情况。
注意: 1、如果该用户没有配置磁盘限额的话,输出显示如下:
Disk quotas for user hujm (uid 503): none
2、如果不带任何参数运行quota的话,查看的是你自己的配额使用情况。

转载于:https://blog.51cto.com/zc1103/202629

linux_磁盘配额相关推荐

  1. 磁盘管理来安装linux,Linux_在CentOS系统中安装quota来管理磁盘配额,在网络管理的工作中,由于硬 - phpStudy...

    在CentOS系统中安装quota来管理磁盘配额 在网络管理的工作中,由于硬盘的资源是有限的,常常需要为多用户的服务器设定用户的linux磁盘配额.这个功能对公用的多用户服务器(免费的或者收费的)来说 ...

  2. linux磁盘配额管理

    linux-用户磁盘配额 磁盘配额就是管理员可以为用户所能使用的磁盘空间进行配额限制,每一用户只能使用最大配额范围内的磁盘空间 磁盘配额可以限制指定账户能够使用的磁盘空间,这样可以避免因某个用户的过度 ...

  3. linux磁盘管理系列一:磁盘配额管理

    磁盘管理系列 linux磁盘管理系列一:磁盘配额管理   http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_040_quota.html l ...

  4. Linux 下磁盘配额(RHEL5)

    Linux 下磁盘配额 1.#vim /etc/fstab 2.保存退出 3.#/rebootor #mount -o remount  /home 4.#mount |grep  /home     ...

  5. 认识Linux的磁盘配额(转载)

    认识Linux的磁盘配额(转载) 对于管理Windows系统的网络管理员来说,配置磁盘配额是一件比较容易的事情,那么,如何在Linux下配置磁盘配额,在配置磁盘配额时需要注意哪些问题,可能有些读者朋友 ...

  6. Ubuntu系统给磁盘配额(Quota)

    需求:给U盘进行磁盘配额,不同用户不同的使用容量 第一步:安装quota命令 sudo apt-get install quota 第二步:为U盘进行分区,全部容量分为一个分区 sudo fdisk ...

  7. LVM逻辑卷轴管理和磁盘配额实验

    动态卷轴管理和磁盘配额实验 首先先在虚拟机中开启两个硬盘,我在rh6-2中新添加了两个硬盘,分别为sdbc和sdbd: 按照如上方法,再添加1个硬盘. 则添加的磁盘如下所示: 第一步:分区 接下来对s ...

  8. Linux之LVM与磁盘配额(quota)详解

    什么是LVM? LVM(Logical Volume Manager)逻辑卷管理,是一种将一个或多个硬盘的分区在逻辑上集合,相当于一个大硬盘来使用,当硬盘的空间不够使用的时候,可以继续将其它的硬盘的 ...

  9. Linux磁盘配额(一)

    Linux系统的磁盘配额功能用于限制用户所使用诉磁盘空间,并且在用户使用了过多的磁盘空间或分区的空闲空间过少时,系统管理员会接到警告. Linux磁盘配额可以针对单独用户进行配置,也可以针对用户组进行 ...

最新文章

  1. Nature:依靠锰的氧化实现细菌的化能自养生长
  2. 【采用】智能反欺诈算法概览及典型应用案例
  3. 关于Uncaught SyntaxError: Unexpected identifier
  4. java五子棋悔棋代码_小猿圈前端编写JS五子棋游戏
  5. bzoj1532: [POI2005]Kos-Dicing
  6. 英语笔记:词组句子:0712
  7. java 观察者模式_设计模式-Java-观察者模式-RxJava
  8. java实现视频加密_JAVA实现视频加密
  9. GIS + 现代农业”,将会擦出怎样的火花?——智慧农业专题论坛侧记
  10. 万能采集网站php源码,PHP采集系统UZCMS万能最新版
  11. CS224d-Day 2:TensorFlow 入门
  12. 从零开始开发一个全栈Web应用实录
  13. 【前端学习笔记—canvas标签和使用canvas画哆啦A梦案例】
  14. webapp通过点击调用高德地图或百度地图导航
  15. C++ Boost库:简介和第一个示例程序
  16. 前端开发:JS中join()方法的使用总结
  17. 编写高质量代码改善C#程序的157个建议——建议64:为循环增加Tester-Doer模式而不是将try-catch置于循环内...
  18. 数据库系统概论 关系代数:专门的关系运算
  19. huggingface.transformers速成笔记:Pipeline推理和AutoClass
  20. W25Q128---读写

热门文章

  1. Maven settings.xml配置详解
  2. Java三大主流开源工作流引擎技术分析
  3. WPF中的容器控件——GridSplit
  4. 启动Oracle 10g
  5. 在C#中如何在客户端接收信件
  6. 《为了你我愿意热爱整个世界》
  7. checkbox管理
  8. PostgreSQL on XFS 性能优化 - 1
  9. RabbitMQ启动参数具体含义
  10. ASP+Access中文乱码的解决方法,ASP中文乱码,asp乱码问题