一、quota实例:
1、创建用户与群组
vim addaccount.sh
#!/bin/bash
#
groupadd myquotagrp
for username in myquota1 myquota2 myquota3 myquota4 myquota5
do
useradd -g myquotagrp $username
echo "password" | passwd --stdin $username
done
2、创建磁盘并格式化(VFAT除外)
fdisk /dev/sdb------>sdb5#自行创建,这里默认sdb5
mkfs.ext4 /dev/sdb5
e2label /dev/sdb5 quota
(1)vim /etc/fstab #编辑 fstab文件让系统启动时挂载quota
添加LABEL=quota /mnt/quota ext4 defaults,usrquota,grpquota 1 2
(2)mount /dev/sdb5 /mnt/quota
mount -o remount,usrquota,grpquota /mnt/quota #注意quota参数
mount -a
df -h 查看挂载信息
mount | grep /mnt/quota
13:/dev/sdb5 on /mnt/quota type ext4 (rw,usrquota,grpquota)
cat /etc/mtab 这个档案,系统会同步更新
3、建立quota记录文件
#对整个系统含有 usrquota, grpquota 参数的文件系统进行 quotacheck 扫瞄
[root@localhost quota]# quotacheck -avug
-bash: command not found
[root@localhost quota]# yum install quota 安装quota
quotacheck -avug #自动生成记录文件
错误信息
Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/sdb5 [/quota] done
quotacheck: Cannot stat old user quota file /quota/aquota.user: No such file or directory. Usage will not be substracted.等等
此时在/mnt/quota/中查看是否存在记录文件(当然此时不会有的)
这是由于SElinux 的原因
setenfource 0
查看getenfource
Permissive
再次执行quotacheck -avug
[root@localhost quota]# quotacheck -avug
quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Quota for users is enabled on mountpoint /quota so quotacheck might damage the file.
Please turn quotas off or use -f to force checking.
[root@localhost quota]# ls
aquota.group aquota.user lost+found
4、quota启动、关闭与限制值设定
(1)开启quota
[root@localhost quota]# quotaon -avug
这里【quotaon -avug】的指令几乎只在第一次启动时才需要进行,因为在下次启动时/etc/rc.d/rc.sysinit这个初始化脚本就会自动的下达这个命令了!未来都不需要自行启动quota。
(2)编辑账号、群组的限值与宽限时间
edquota -u myquota1 #自行设置
Disk quotas for user myquota1 (uid 4027):
Filesystem blocks soft hard inodes soft hard
/dev/sdb5 101378 100000 110000 1 0 0
这里7个字段分别为:
1、文件系统 2、磁盘容量 3、磁盘容量的soft限制值单位KB 4、block的hard限制值,单位KB
5、档案数量,单位为个数,请不要更动 6、inode的soft限制值 7、inode的hard限制值
当soft/hard为0时,表示没有限制值的意思
[root@localhost quota]# edquota -p myquota1 -u myquota2
[root@localhost quota]# edquota -p myquota1 -u myquota3
[root@localhost quota]# edquota -p myquota1 -u myquota4
[root@localhost quota]# edquota -p myquota1 -u myquota5
[root@localhost quota]# edquota -g myquotagrp
Disk quotas for group myquotagrp (gid 4027):
Filesystem blocks soft hard inodes soft hard
/dev/sdb5 101379 400000 500000 2 0 0
[root@localhost quota]# 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/sdb5 14days 14days
5、quota限制值的报表
[root@localhost quota]# quota -uvs myquota1 myquota2
[root@localhost quota]# quota -gvs myquotagrp
[root@localhost quota]# repquota -ugvs
*** Report for user quotas on device /dev/sdb5
Block grace time: 14days; Inode grace time: 14days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 13 0 0 2 0 0
myquota1 +- 101378 100000 108M 13days 1 0 0
myquota2 -- 0 100000 108M 0 0 0
myquota3 -- 0 100000 108M 0 0 0
myquota4 -- 0 100000 108M 0 0 0
myquota5 -- 0 100000 108M 0 0 0
Statistics:
Total blocks: 7
Data blocks: 1
Entries: 6
Used average: 6.000000
6、quota的测试与管理
[root@localhost ~]# su - myquota1
[myquota1@localhost ~]$ cd /mnt/quota/
[myquota1@localhost quota]$ dd if=/dev/zero of=bigfile1 bs=1M count=100
[root@localhost ~]# repquota -au
*** Report for user quotas on device /dev/sdb5
Block grace time: 14days; Inode grace time: 14days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 13 0 0 2 0 0
myquota1 +- 101378 100000 110000 13days 1 0 0
###########编辑一下档案进行限额操作且可不同的限额针对不同的使用者##########
[root@localhost ~]# vim /etc/warnquota.conf
You have mail in /var/spool/mail/root
[root@localhost ~]# vim /etc/cron.daily/
cups makewhatis.cron prelink rhsmd
logrotate mlocate.cron readahead.cron tmpwatch
[root@localhost ~]# vim /etc/cron.daily/warmquota /usr/sbin/warnquota
######################################################################
某些地方可能不够详细,还请自行在论坛、博客deng查找命令、理论等相关信息
######################################################################
转载于:https://blog.51cto.com/11036133/1729863