教学之友,学习之友。

站长教学网

centos下Quota::配置详解

时间:2012-12-04 15:33来源:未知 作者:ken 点击:

要是出现-bash: command not found

首先检查是否了quota  rpm -qa | grep quota
[root@root~]# yum install quota 安装quota

[root@root~]# quotacheck -avug
 

Quota::配置详解  

 
 
1 常用的quota命令介绍
1.1 quota
[root@linux~]# quota [-uvsl] [username]
[root@linux~]# quota [-gvsl] [groupname]
参数:
-u :后面可以接username,表示显示出该使用者的quota限制值 若不接username,表示显示出执行者的quota限制值 
-g :后面可接groupname,表示显示出该群组的quota限制值 
-v :显示每个filesystem的quota值;
-s :可选择以inode或磁盘容量的限制值来显示;
-l :仅显示出目前本机上面的filesystem的quota值 
范例:
范例一:列出目前root自己的quota限制值:
[root@linux~]# quota
范例二:列出edwin这个使用者的磁盘配额
[root@linux~]# quota  -u edwin
注意一下这两个范例,如果您的系统上面尚未有任何的quota支持的filesystem时,使用这两个范例时,不会有任何信息。

 
1.2 quotacheck
[root@linux ~]# quotacheck [-avug] [/mount_point]
参数:
-b Forces quotacheck to make backups of the quota file before writing the new data.
-v quotacheck reports its operation as it progresses. Normally it operates silently.
-d Enable debugging mode. It will result in a lot of information which can be used in debugging the program. The output is very verbose and the scan will be slow.
-u Only user quotas listed in /etc/mtab or on the filesystems specified are to be checked. This is the default action.
-g Only group quotas listed in /etc/mtab or on the filesystems specified are to be checked.
-c Don't read existing quota files. Just perform a new scan and save it to disk. quotacheck also skips scanning of old quota files when they are not found.
-f Forces checking of filesystems with quotas enabled. This is not recommended as the created quota files may be out of sync.
-M This flag forces checking of filesystem in read-write mode if a remount fails. Do this only when you are sure no process will write to a filesystem while scanning.
-m Don't try to remount filesystem read-only. See comment with option -M.
-i Interactive mode. By default quotacheck exits when it finds an error. In interactive mode user is asked for input instead. See option -n.
-n If the quota files become corrupted, it is possible for duplicate entries for a single user or group ID to exist. Normally in this case, quotacheck exits or asks user for input. When this option is set, the first entry found is always used (this option works in interactive mode too).
-F format-name Check quota for specified format (ie. don't perform format auto-detection). This is recommended as detection might not work well on corrupted quota files. Possible format names are: vfsold (version 1 quota), vfsv0 (version 2 quota), rpc (quota over NFS), xfs (quota on XFS filesystem)
-a Check all mounted non-NFS filesystems in /etc/mtab
-R When used together with the -a option, all filesystems except for the root filesystem are checked for quotas.

 
注释:红标的为常用的参数

 
范例:
范例一:对新分区(挂载在/home)启用quota(usrquota)
[root@linux ~]# quotacheck -cmu /home

范例二 :对新分区(挂载在/home)启用quota(usrquota,grpquota)
[root@linux ~]# quotacheck -cmug /home

范例三:将所有的在/etc/mtab内,含有quota支持的partition进行扫描
[root@linux ~]# quotacheck -avug
没有设置quota时候的信息
quotacheck: Can't find filesystem to check or filesystem not mounted with quota option.
设置quota后的显示信息
quotacheck: Scanning /dev/hdb1 [/disk2] done
quotacheck: Checked 3 directories and 4 files
 
范例四:强制扫描已挂载的filesystem
[root@linux ~]# quotacheck -avugm
有些时候,在某些Linux distributions上面,进行quotacheck时,可能会出现如下的错误讯息:
quotacheck: Cannot get quotafile name for /dev/hda3
quotacheck: Cannot get quotafile name for /dev/hda3
果真如此的话,那么你可以如同上面一般,加上-m的参数来『强制』扫描 
也可以手动先建立记录文件,然后再扫描,如下所示:
[root@linux ~]# touch /disk2/aquota.user; touch /disk2/aquota.group
[root@linux ~]# quotacheck -avug
必须要注意的是,我这里是以/disk2作为一个测试的mount point,您的挂载点不一定会和范例一样!站长教学网 eduyo.com

 

 
这个命令主要的目的在扫描某一个磁盘的quota空间,他会针对该partitions进行扫描,并且,由于该磁盘若持续运作时,可能扫描的过程中,文件 可能会增减,造成quota扫描的错误发生,因此,当使用quotacheck时,该磁盘将『自动被设定成为只读扇区(read-only)』;至于扫描 完毕之后,扫瞄所得的磁盘空间结果会写入该扇区最顶端 (例如:在例子中,扫描/disk2这个/dev/hdb1的扇区,如果是初次扫描,那么扫描完毕 之后会产生aquota.user与aquota.group,会放置在/disk2/aquota.user与/disk2/aquota.group 底下!而如果是建立quota后的扫描,那么就会更新这两个文件!)另外,Linux也特别强调quota在使用的时候,需要特别注意在reboot时, 得先将quota关闭才好!
此外,由于新版的Linux distribution在quota的设计上似乎有点小问题,有时候无法完整的进行quotacheck,发生如同上表的情况,解决的方法就是主动手动的建立quotafile即可!例如上面的范例二所显示的 

 
1.3 edquota
[root@linux ~]# edquota [-u username] [-g groupname]
[root@linux ~]# edquota -t <==修改宽限时间
[root@linux ~]# edquota -p username_demo -u username
参数:
-u :后面接账号名称 可以进入quota的编辑画面(vi)去设定username的限制值;
-g :后面接群组名称 可以进入 quota 的编辑画面(vi)去设定groupname的限制值;
-t :可以修改宽限时间(就是超过quota的soft limit值后,还能使用硬盘的宽限期限)
-p :复制范本 那个username_demo为已经存在并且已设定好quota的使用者,意义为将username_demo这个人的quota限制值复制给username

 
范例一:设定dmtsai这个用户的quota限制值
[root@linux ~]# edquota -u edwin
Disk quotas for user edwin (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/hdb1 0 0 0 0 0 0
进入编辑画面后,以vi的相关行为进行编辑喔!
我们可以看到被编辑的用户是edwin,共有七个字段,每个字段的意义我们将在底下的说明继续介绍 而假设我们对于edwin的限制是30MB的话,那么:
Disk quotas for user dmtsai (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/hdb1 0 25000 30000 0 0 0

 

 
范例二:将edwin的quota限制值(30MB)复制给vbird这个用户
[root@linux ~]# edquota -p edwin -u vbird

范例三:修订宽限时间
[root@linux ~]# 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/hdb1 7days 7days
预设的恕限时间是7天!你当然可以修订时间!
这个命令就是在编辑每一个『个人』或者是『群组』的quota数值!通常我们以edquota –u username或者是edquota -g groupname来编辑个人与群组的quota设定值 不过,或许您会觉得一个一个分配似乎很慢的样子!那么您也可以直接copy一个人的设定值给其它 人,就如同上面第二个例子,利用已经建立好的dmtsai来建立vbird1这个人的quota限额!这个指令可是很重要的呦!另外,范例一当中出现的那 七个字段代表的意义我们得要谈一谈啊:
  • filesystem:代表这个quota是针对哪一个partition的意思 以范例一的情况来说,指的是/dev/hdb1啰!也就是/disk2那个目录底下的quota限制值啦!
  • blocks:这个是目前使用者edwin(uid501)在/dev/hdb1这个filesystem(参考上面一个信息),所消耗的磁盘容量,也就是目前的使用掉的空间啦!单位是Kbytes喔!这个信息是quota程序自己计算出来的,所以请不要修改他!
  • soft与hard:这个是目前的edwin使用者在这个filesystem之内的quota限制值!soft代表的是一个『警告』限值,hard则是一个『不可超过的限值』,soft与hard中间的差值则为宽限的数值 而当soft与hard数值 为0的时候,表示『没有限制』的意思!而数值的单位仍是Kbytes!
  • inodes:是目前使用掉inode的状态,也是quota自己计算出来而得到的,所以不要去变更他 一般而言,inode不容易控制,所以您可以不必去限制inode呢!

 

 
1.3 quotaon
[root@linux ~]# quotaon [-avug]
[root@linux ~]# quotaon [-vug] [/mount_point]
参数:
-u :针对用户启动quota(aquota.user)
-g :针对群组启动 quota(aquota.group)
-v :显示启动过程的相关讯息;
-a :根据/etc/mtab内的filesystem设定启动有关的quota,若不加-a的话,则后面就需要加上特定的那个filesystem!
范例:
范例一:启动所有的具有quota的filesystem
[root@linux ~]# quotaon -auvg
/dev/hdb1 [/disk2]: group quotas turned on
/dev/hdb1 [/disk2]: user quotas turned on
范例二:仅启动/disk2里面的user quota设定值:
[root@linux ~]# quotaon -uv /disk2
这个命令是在启动quota的!不过,由于这个指令是启动aquota.group与aquota.user的,所以您就必须要先完成quotacheck的工作了!然后简单的下达quotaon -a即可启动!

 
1.4 quotaoff
[root@linux ~]# quotaoff [-a]
[root@linux ~]# quotaoff [-ug] [/mount_point]
参数:
-a :全部的filesystem的quota都关闭(根据/etc/mtab)
-u :仅针对后面接的那个/mount_point关闭user quota
-g :仅针对后面接的那个/mount_point关闭group quota
范例:
范例一:
[root@linux ~]# quotaoff -a
这个命令就是关闭了quota的限制啦!
 
2 实验:

條件及其目的

 

  • 建立一個partition(/dev/hdb3) 掛載在/data。站长教学网 eduyo.com
  • 建立兩使用者/群組 user/user、 user2/user2。
  • /data 啟用usrquota、grpquota。
  • 在/data 上,使用者user 限制4MB,群組user2 限制10MB。

 


 

1 建立使用者

[root@linux ~]# useradd  user 
[root@linux ~]# useradd  user2
[root@linux ~]# echo 'password' | passwd --stdin user
[root@linux ~]# echo 'password' | passwd --stdin user2

2 /data 啟用 usrquota grpquota
[root@linux ~]# mkdir /data 

[root@linux ~]# vi /etc/fstab
/dev/hdb3 /data ext3 defaults,usrquota,grpquota 0 0 0
 

[root@linux ~]# mount -o remount /data  #重新掛載詞區

[root@linux ~]# quotacheck -cmug /data #此動作為檢查/data 磁區並解建立配額檔

[root@linux ~]# quotaon -a
 

3 設定使用配額

[root@linux ~]# edquota -u user (編輯user 使用者 的quota 值)
Filesystem     blocks     soft     hard     inodes     soft     hard
/dev/sda5               0 4096     4096             0         0            0
 

[root@linux ~]# edquota -g user2 (編輯dsc 群組 的quota 值)
Filesystem     blocks     soft     hard     inodes     soft     hard
/dev/sda5                0 10240 10240            0         0            0
 


 

验证:
[root@linux ~]# su - user
[root@linux ~]# dd if=/dev/zero of=/data/user_test bs=20M count=1
sda5: write failed, user block limit reached.
sda5: write failed, user block limit reached.
dd: writing `/data/user_test': Disk quota exceeded
1+0 records in
0+0 records out
4173824 bytes (4.2 MB) copied, 0.0309744 seconds, 135 MB/s
 

[root@linux ~]# su - user2
[root@linux ~]# dd if=/dev/zero of=/data/dsc_test bs=20M count=1
sda5: write failed, group block limit reached.
sda5: write failed, group block limit reached.
dd: writing `/data/dsc_test': Disk quota exceeded
1+0 records in
0+0 records out
10440704 bytes (10 MB) copied, 0.114073 seconds, 91.5 MB/s

(责任编辑:ken)
TAG标签: CentOS linux quota
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
注册登录:不允许匿名留言,登录后留言无需输入验证码。
栏目列表
最新内容