linuxlinux设置磁盘配额额可以通过哪两种方法对用户进行限制?

博客访问: 125062
博文数量: 16
博客积分: 1456
博客等级: 上尉
技术积分: 214
注册时间:
IT168企业级官微
微信号:IT168qiye
系统架构师大会
微信号:SACC2013
分类: LINUX
Linux用户磁盘配额的笔记 [转载] /968672.html在LINUX系统发行版本中我们常常使用quota来对用户进行磁盘配额管理。网上的资料比较多和丰富,这里我只进行一些基本的实现步骤说明,以便大家参考!首先我们需要检查当前使用的系统是否支持quota.使用命令:[root@server ]#&grep CONFIG_QUOTA /boot/config-[version]如果结果如下:CONFIG_QUOTA=yCONFIG_QUOTACTL=y两个Y的话,恭喜!你当前的内核支持quota!如果没有上面两个结果的话那必须对内核进行重新编译了。内核编译与本文无关,这里对内核编译就不再做说明了。我使用的是ubuntu8.04 SERVER的发行版本,内核已经支持了quota。好了,我们正式开始磁盘配额设置:一、修改/etc/fstab文件,让需要进行配额的分区激活配额功能。[root@server ]# vi /etc/fstab# /etc/fstab: static file system information.## & & & & & & &....../dev/sdb5 &/var/www &ext3 &grpquota,suid,dev,usrquota,exec &0 &0在位置部分的default后填写usrquota,grpquota,如果配置外加的新设备需要填写grpquota,suid,dev,usrquota,exec参数二、使用quotacheck对设置了磁盘配额的目录进行初始化。因为quotacheck依据/etc/mtab搜索文档系统。我们需要重新加载被设置配额的分区(mount操作部分忽略)。检查的命令如下:[root@server ]# quotacheck -avug在检查过程中屏幕上会提示旧的quota文档无法找到,这个没关系,不影响。检查的参数说明如下:-a : 扫描任何在/etc/mtab中开启quota的文档系统-v : 显示扫描过程-u : 扫描任何user quotas & (usrquota)-g : 扫描任何group quotas &(grpquota)检查完毕后生成quota的信息文档(使用ls命令查看被检查的目录):-rw------- &1 root root 11264 Mar 18 20:56 aquota.group-rw------- &1 root root 12288 Mar 18 20:56 aquota.user三、启动QUOTA:[root@server ]# quotaon –av/dev/hda7 [/mnt/xxx]: group quotas turned on/dev/hda7 [/mnt/xxx]: user quotas turned on命令解释:-a : 开启任何quota设定,根据/etc/mtab设定-v : 当开启quota时显示信息四、编辑用户磁盘限额:这里设定用户quota最大使用容量为20M,当使用到10M时会得到警告需要降低到10M。最多能够创建10个文档,当创建5个文档时会得到警告需要降低到5个文档。命令如下:[root@server ]#&edquota -u [username]显示结果如下:Disk quotas for user xxxxx (uid xxxxxx):Filesystem & & & & blocks & & & soft & & & hard & & inodes & & soft & & hard/dev/hda7 & & & & & & 0 & & & & 10240 & & &20480 & & & &0 & & & &5 & & & &10相关参数说明-u : 编辑user的quota-g : 编辑group的quota-t : 编辑宽限时间-p : 复制quota资料到另一用户上blocks :现在使用者(quota:uid=5011)在/dev/hda7所使用的空间,单位:KB (不要修改)soft :soft limit 磁盘空间限定值 单位:KB (需要设定)hard :hard limit 磁盘空间限定值 单位: KB (需要设定)inodes :现在使用者使用掉的inodes,由于不容易使用inode控制,所以不要修改他。soft :soft limit 文档限制数量 (根据需要修改)hard :hard limit 文档限制数量 (根据需要修改)soft limit :最低限制容量,在宽限期(grace period)之内,使用容量能够超过soft limit,但必须在宽限期之内将使用容量降低到soft limit以下。hard limit :最终限制容量,假如使用者在宽限期内继续写入数据,到达hard limit将无法再写入。宽限时间:使用容量超过soft limit,宽限时间自动启动,使用者将容量降低到soft limit以下,宽限时间自动关闭,假如使用者没有在宽限时间内将容量降低到soft limit,那么他将无法再写入数据,即使使用容量没有到达hard limit五、设定宽限时间[root@server ]# edquota -tGrace period before enforcing soft limits for users:Time units may be: days, hours, minutes, or secondsFilesystem & & & & & & Block grace period & & Inode grace period/dev/hda7 & & & & & & & & & &1days & & & & & & & & 7daysOK,完成啦,检查一下吧:[root@server ]# quota -uv quotaDisk quotas for user xxxx (uid xxxx):Filesystem &blocks & quota & limit & grace & files & quota & limit & grace/dev/hda7 & & & 0 & &1024 & &2048 & & & & & & & 0 & & & 5 & & &10参数说明:-u : 显示user-v : 显示quota值使用-p参数复制quota资料到另一个用户:[root@server xxx]# edquota -p xxxx yyyyyy[root@server xxx]# quota -uv yyyyyyDisk quotas for user yyyyy(uid 0000):Filesystem &blocks & quota & limit & grace & files & quota & limit & grace/dev/hda7 & & & 0 & &1024 & &2048 & & & & & & & 0 & & & 5 & & &10同时复制给多个用户:[root@server xxx]# edquota -p xxxx `awk -F: ’$3 >499 {print $1}’ /etc/passwd`这样就将quota的磁盘配额资料复制给任何uid >499的用户(uid为500以上的用户通常为真实用户)OK,最后加在启动脚本里,系统启动时自动激活quota吧!能够加入到/etc/rc.d/rc.sysinit或/etc/rc.d/rc.local中,在结尾加上一行:/usr/sbin/quotaon –aug还要记得在系统关机/重启脚本(/etc/rc.d/rc[0,6]/)中加入关闭quota的语句:/usr/sbin/quotaoff –aug通常发行版在系统启动/关闭时都会处理quota,在系统启动信息看到相关信息。例如RedHat RHEL4,Mandrake 10.1系统启动/关闭时有这样两行:Turning on user and group quotas for local filesystems: (/etc/rc.d/rc.sysinit)Turning off quotas: & & & (/etc/rc.d/rc0.d/S01halt &/etc/rc.d/rc6.d/S01reboot)查询磁盘配额:root查询任何用户使用情况:[root@server ~]# repquota –a*** Report for user quotas on device /dev/hda7Block grace time: 24:00; Inode grace time: 7daysBlock limits & & & & & & & &File limitsUser &used & &soft & &hard &grace & &used &soft &hard &grace......略quota & & +- & &1032 & &1024 & & & & & 2 & & 5 & &10假如有多个分区为quota,可用repquota -u 挂载点 查询单个分区的使用情况普通用户查询自己使用情况:[quota@server ~]$ quotaDisk quotas for user xxxx (uid xxxx):Filesystem &blocks & quota & limit & grace & files & quota & limit & grace/dev/hda7 & &1032* & 1024 & &2048 & 23:58 & & & 2 & & & 5 & & &10quotcheck :quotcheck用来扫描文档系统的磁盘用量,更新aquota.user,aquota.group保持quota记录档到最新的状态。因此最好在系统启动时执行或通过cron定期执行:每周六早七点执行一次:0 7 * * 6 /sbin/quotacheck -avug下面是一次quota实施记录:[笔记,非转载]OS : RedHat Enterprise Linux 5.0 #1 SMP&CPU: x86_641. 编辑/etc/fstab文件,在home目录上设置磁盘配额[root@xxx-4148282 ~]# vi /etc/fstabLABEL=/ & & & & & & & & / & & & & & & & & & & & ext3 & &defaults & & & &1 1LABEL=/home & & & & & & /home & & & & & & & & & ext3 & &defaults,usrquota,grpquota & & & &1 2LABEL=/boot & & & & & & /boot & & & & & & & & & ext3 & &defaults & & & &1 2tmpfs & & & & & & & & & /dev/shm & & & & & & & &tmpfs & defaults & & & &0 0devpts & & & & & & & & &/dev/pts & & & & & & & &devpts &gid=5,mode=620 &0 0sysfs & & & & & & & & & /sys & & & & & & & & & &sysfs & defaults & & & &0 0proc & & & & & & & & & &/proc & & & & & & & & & proc & &defaults & & & &0 0LABEL=SWAP-sda3 & & & & swap & & & & & & & & & &swap & &defaults & & & &0 0~~~~2. 重新挂载文件系统[root@xxx-4148282 ~]# mount -a3. 初始化设置了磁盘配额的目录/home[root@xxx-4148282 ~]# quotacheck -avugquotacheck: Can't find filesystem to check or filesystem not mounted with quota option.没找到设置quota选项的目录,用mount看看,/home确实没有成功挂载为设置quota[root@xxx-4148282 ~]# mount/dev/sda2 on / type ext3 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)/dev/sda5 on /home type ext3 (rw)/dev/sda1 on /boot type ext3 (rw)tmpfs on /dev/shm type tmpfs (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)查看/home目录当前是不是正被使用:[root@xxx-4148282 ~]# fuser -m /home//home/: & & & & & & & 5455c杀死正在使用/home目录的进程5455[root@xxx-4148282 ~]# kill -9 5455卸载/home目录[root@xxx-4148282 ~]# umount /home重新挂载[root@xxx-4148282 ~]# mount -a[root@xxx-4148282 ~]# mount&/dev/sda2 on / type ext3 (rw)proc on /proc type proc (rw)sysfs on /sys type sysfs (rw)devpts on /dev/pts type devpts (rw,gid=5,mode=620)/dev/sda1 on /boot type ext3 (rw)tmpfs on /dev/shm type tmpfs (rw)none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)/dev/sda5 on /home type ext3 (rw,usrquota,grpquota)/home目录成功重新挂载,且有了quota选项4. 解决了挂载问题,再次初始化设置quota的目录[root@xxx-4148282 ~]# quotacheck -avugquotacheck: Scanning /dev/sda5 [/home]&|quotacheck: Cannot stat old user quota file: ?2???‰é?£??a?–??????–??????quotacheck: Cannot stat old group quota file: ?2???‰é?£??a?–??????–??????quotacheck: Cannot stat old user quota file: ?2???‰é?£??a?–??????–??????quotacheck: Cannot stat old group quota file: ?2???‰é?£??a?–??????–??????donequotacheck: Checked 15 directories and 14 filesquotacheck: Old file not found.quotacheck: Old file not found.[root@xxx-4148282 ~]#&可见/home目录下有了aquota.group和aquota.user两个quota相关的文件[root@xxx-4148282 ~]# ll /home/?
阅读(9586) | 评论(0) | 转发(0) |
相关热门文章
给主人留下些什么吧!~~
请登录后评论。

我要回帖

更多关于 磁盘配额限制 的文章

 

随机推荐