Linux 用户 Quota 配置 说明
Linux 用户 Quota 配置 说明
一. Linux 配额(Quota)说明
在 Linux 系统中,由于是多人多任务的环境,所以会有多人共同使用一个硬盘空间的情况发生,为了合理使用这些空间,管理员需要控制用户对磁盘空间的使用,这个就是Linux 下的配额管理。
推荐阅读:
- Linux学习笔记:磁盘配额(Quota)与高级文件系统管理
- RHCE培训笔记——磁盘配额
- Linux下磁盘配额(quota)应用与实战教程
- RHEL5.5中创建softRaid10并使用quota限制磁盘配额
- VMware下RedHat 5.4磁盘配额(Quota)
配额管理是对某个磁盘分区进行限制。这里的限制包括2个方面:
1.单个用户对某个目录下空间大小的限制。
2.单个用户对某个目录下文件个数的限制。
1.1 Quota 常用在如下几种情况
1) 针对 WWW server ,例如:每个人的网页空间的容量限制。
2) 针对 mail server,例如:每个人的邮件空间限制。
3) 针对 file server,例如:每个人最大的可用网络硬盘空间。
1.2 Quota 的2个注意事项
(1)仅针对整个 partition:
quota针对『整个 partition』进行限制, 例如:如果/dev/hda5 是挂载在 /dave 目录下,那么在 /dave 目录下的所有目录都会受到限制。
(2)只对一般身份使用者有效:
不是所有在 Linux 上面的账号都可以设定 quota,例如 root 就不能设定quota 。
1.3 Quota 的三种限制类型
(1)soft limit:
这是最低限制容量的意思,用户在宽限期间之内,他的容量可以超过 soft ,但必需要宽限时间之内将磁盘容量降低到 soft 的容量限制之下。
(2)hard limit:
这是『绝对不能超过』的容量。通常hard limit 会比 soft limit 为高,例如网络驱动器空间为 30 MB ,那么 hard limit 就设定为 30MB ,但是为了让使用者有一定的警戒心,所以当使用空间超过 25 MB 时,例如使用者使用了 27 MB 的空间时,那么系统就会警告用户, 让使用者可以在『宽限时间内』将他的档案量降低至 25 MB ( 亦即是 soft limit )之内。也就是说, soft 到 hard 之间的容量其实就是宽限的容量,可以达到针对使用者的『警示』作用。
(3)宽限时间:
宽限时间就是当使用者使用的空间超过了 soft limit ,却还没有到达 hard limit 时,那么在这个『宽限时间』之内,就必需要请用户将使用的磁盘容量降低到 soft limit 之下。而当用户将磁盘容量使用情况超过 soft limit 时,『宽限时间』就会自动被启动,而在用户将容量降低到 softlimit 之下,那么宽限时间就会自动的取消。
1.4 Quota 的安装包
Quota也需要安装,安装包如下:
[root@rhce /]# rpm -q quota
quota-3.17-16.el6.x86_64
[root@rhce /]#
1.5 Quota 相关的命令
与Quota 相关的几个命令如下。
1.5.1 启用quota:quotaon
[root@rhce /]# quotaon
Bad number of arguments.
quotaon: Usage:
quotaon [-guvp] [-F quotaformat] [-x state] -a
quotaon [-guvp] [-F quotaformat] [-x state] filesys ...
-a, --all turn quotas on for all filesystems
-f, --off turn quotas off
-u, --user operate on user quotas
-g, --group operate on group quotas
-p, --print-state print whether quotas are on or off
-x, --xfs-command=cmd perform XFS quota command
-F, --format=formatname operate on specific quota format
-v, --verbose print more messages
-h, --help display this help text and exit
-V, --version display version information andexit
[root@rhce /]#
1.5.2 关闭quota:quotaoff
[root@rhce /]# quotaoff
Bad number of arguments.
quotaoff: Usage:
quotaoff [-guvp] [-F quotaformat] [-x state] -a
quotaoff [-guvp] [-F quotaformat] [-x state] filesys ...
-a, --all turn quotas off for allfilesystems
-f, --off turn quotas off
-u, --user operate on user quotas
-g, --group operate on group quotas
-p, --print-state print whether quotas are on or off
-x, --xfs-command=cmd perform XFS quota command
-F, --format=formatname operate on specific quota format
-v, --verbose print more messages
-h, --help display this help text and exit
-V, --version display version information andexit
1.5.3 配额发送警告:warnquota
[root@rhce /]# warnquota -h
warnquota: Usage:
warnquota [-ugsid] [-F quotaformat] [-c configfile] [-q quotatabfile][-a adminsfile]
-u, --user warn users
-g, --group warn groups
-s, --human-readable send information in more humanfriendly units
-i, --no-autofs avoid autofs mountpoints
-d, --no-details do not send quota informationitself
-F, --format=formatname use quotafiles of specific format
-c, --config=config-file non-default config file
-q, --quota-tab=quotatab-file non-default quotatab
-a, --admins-file=admins-file non-default admins file
-h, --help display this help messageand exit
-v, --version display version informationand exit
Bugs to jack@SUSE.cz
[root@rhce /]#
1.5.4 编辑配额属性:edquota
[root@rhce /]# edquota
edquota: Usage:
edquota [-rm] [-u] [-F formatname] [-p username] [-f filesystem]username ...
edquota [-rm] -g [-F formatname] [-pgroupname] [-f filesystem] groupname ...
edquota [-rm] [-u|g] [-F formatname] [-f filesystem] -t
edquota [-rm] [-u|g] [-F formatname] [-f filesystem] -Tusername|groupname ...
-u, --user edit user data
-g, --group edit group data
-r, --remote edit remote quota (via RPC)
-m, --no-mixed-pathnames trim leading slashes from NFSv4mountpoints
-F, --format=formatname edit quotas of a specific format
-p, --prototype=name copy data from a prototype user/group
--always-resolve alwaystry to resolve name, even if it is
composed only ofdigits
-f, --filesystem=filesystem edit data only on a specific filesystem
-t, --edit-period edit grace period
-T, --edit-times edit grace time of a user/group
-h, --help display this help text andexit
-V, --version display version informationand exit
Bugs to: jack@suse.cz
[root@rhce /]#
1.5.5 显示配额信息:repquota
[root@rhce /]# repquota -h
repquota: Utility for reporting quotas.
Usage:
repquota [-vugsi] [-c|C] [-t|n] [-Fquotaformat] (-a | mntpoint)
-v, --verbose display also users/groups withoutany usage
-u, --user display information aboutusers
-g, --group display information aboutgroups
-s, --human-readable show numbers in human friendly units(MB, GB, ...)
-t, --truncate-names truncate names to 8 characters
-p, --raw-grace print grace time in seconds sinceepoch
-n, --no-names do not translate uid/gid to name
-i, --no-autofs avoid autofs mountpoints
-c, --batch-translation translate big number of ids at once
-C, --no-batch-translation translate ids one by one
-F, --format=formatname report information for specific format
-h, --help display this help message andexit
-V, --version display version information andexit
Bugs to jack@suse.cz
[root@rhce /]#
1.5.6 检查并修复quota 配置文件:quotacheck
#quotacheck –cvug/tmp
[root@rhce ~]# quotacheck -h
Utility for checking and repairing quotafiles.
quotacheck [-gucbfinvdmMR] [-F<quota-format>] filesystem|-a
-u, --user check user files
-g, --group check group files
-c, --create-files create new quota files
-b, --backup create backups of old quota files
-f, --force force check even if quotas areenabled
-i, --interactive interactive mode
-n, --use-first-dquot use the first copy of duplicated structure
-v, --verbose print more information
-d, --debug print even more messages
-m, --no-remount do not remount filesystem read-only
-M, --try-remount try remounting filesystem read-only,
continue even if itfails
-R, --exclude-root exclude root when checking allfilesystems
-F, --format=formatname check quota files of specific format
-a, --all check all filesystems
-h, --help display this message and exit
-V, --version display version information andexit
Bugs to jack@suse.cz
[root@rhce ~]#
[root@rhce ~]# quotacheck -cvug /dave
quotacheck: Your kernel probably supportsjournaled quota but you are not using it. Consider switching to journaled quotato avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/sdc1 [/dave] done
quotacheck: Cannot stat old user quotafile: No such file or directory
quotacheck: Cannot stat old group quotafile: No such file or directory
quotacheck: Cannot stat old user quotafile: No such file or directory
quotacheck: Cannot stat old group quota file:No such file or directory
quotacheck: Checked 3 directories and 2files
quotacheck: Old file not found.
1.5.7 直接设置配额:setquota
[root@rhce ~]# setquota -h
setquota: Usage:
setquota [-u|-g] [-rm] [-F quotaformat] <user|group>
<block-softlimit> <block-hardlimit> <inode-softlimit><inode-hardlimit> -a|<filesystem>...
setquota [-u|-g] [-rm] [-F quotaformat] <-p protouser|protogroup><user|group> -a|<filesystem>...
setquota [-u|-g] [-rm] [-F quotaformat] -b [-c] -a|<filesystem>...
setquota [-u|-g] [-F quotaformat] -t <blockgrace><inodegrace> -a|<filesystem>...
setquota [-u|-g] [-F quotaformat] <user|group> -T<blockgrace> <inodegrace> -a|<filesystem>...
-u, --user set limits for user
-g, --group set limits for group
-a, --all set limits for allfilesystems
--always-resolve always tryto resolve name, even if is
composed only ofdigits
-F, --format=formatname operate on specific quota format
-p, --prototype=protoname copy limits from user/group
-b, --batch read limits from standard input
-c, --continue-batch continue in input processing in case ofan error
-r, --remote set remote quota (via RPC)
-m, --no-mixed-pathnames trim leading slashes from NFSv4mountpoints
-t, --edit-period edit grace period
-T, --edit-times edit grace times for user/group
-h, --help display this help text andexit
-V, --version display version information andexit
Bugs to: jack@suse.cz
[root@rhce ~]#
接下来请看第2页精彩内容:
|
评论暂时关闭