磁盘配额(Quota)
原创fuchunsgj ©著作权
文章标签 磁盘配额(Quota) 文章分类 服务器
©著作权归作者所有:来自51CTO博客作者fuchunsgj的原创作品,请联系作者获取转载授权,否则将追究法律责任
磁盘配额(Quota)
1.Quota 的一般用途
针对 WWW server ,例如:每个人的网页空间的容量限制!
针对 mail server,例如:每个人的邮件空间限制。
针对 file server,例如:每个人最大的可用网络硬盘空间 (教学环境中最常见!)
2.Quota 的使用限制
仅能针对整个 filesystem:
核心必项支持 quota:
Quota 的记录文件:
只对一般身仹使用者有效
3.
容量限制文档案数量限制 (block 戒 inode):
限制 inode 用量:可以管理使用者可以建立的『档案数量』;
限制 block 用量:管理用户磁盘容量的限制,较常见为这种方式。
4.
hard:表示使用者的用量绝对不能过这个限制值:
soft:表示使用者在低于 soft 限值时 (此例中为 400Mbytes),可以正常使用磁盘,但若超过 soft 而低于 hard 的限值,每次用户登入系统时,系统会主动发出磁盘即将爆满的警告讯息, 会给予一个宽限时间 (grace time)。不过,若使用者在宽限时间倒数期间就将容量再次降低亍 soft 限值下限, 则宽限时间会停止。
5.grace time
一般预讴的宽限时间为七天,如果七天内你都不进行任何磁盘管理,那么 soft 限制值会即刻取代 hard 限值而作为 quota 的限制。
Quota 配置实例
1.检查文件系统是否支持----->必须是单独的分区
[root@wangfc ~]# df -TH /home
/dev/mapper/vg0-lv0
ext4 204M 5.8M 187M 4% /home
2.检查文件系统是否支持,VFAT 文件系统不支持 Linux Quota 功能
[root@wangfc ~]# mount | grep home
/dev/mapper/vg0-lv0 on /home type ext4 (rw)
3.手动挂载Quota
[root@wangfc ~]# mount -o remount,usrquota,grpquota /home //
[root@wangfc ~]# mount | grep home
/dev/mapper/vg0-lv0 on /home type ext4 (rw,usrquota,grpquota)
4.开机自动挂载
[root@wangfc ~]# vim /etc/fstab
/dev/mapper/vg0-lv0 /home ext4 defaults,usrquota,grpquota 1 2
----------------------------------------------------------------------------------------------------------------------------------------------------------------
5.建立 quota 记录文件
[root@localhost ~]# quotacheck
Bad number of arguments.
Utility for checking and repairing quota files.
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 are enabled
-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 it fails
-R, --exclude-root exclude root when checking all filesystems
-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 and exit
[root@wangfc ~]# quotacheck -auvg
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: Scanning /dev/mapper/vg0-lv0 [/home] done
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Old group file not found. Usage will not be substracted.
quotacheck: Checked 178 directories and 353 files
quotacheck: Old file not found.
6.产生两个文件
[root@wangfc ~]# ll -d /home/a*
-rw-------. 1 root root 6144 Jul 31 20:45 aquota.group
-rw-------. 1 root root 6144 Jul 31 20:45 aquota.user
7.Quota 启动、 关闭
[root@wangfc ~]# quotaon -auvg
/dev/mapper/vg0-lv0 [/home]: group quotas turned on
/dev/mapper/vg0-lv0 [/home]: user quotas turned on
[root@wangfc ~]# quotaoff -auvg
/dev/mapper/vg0-lv0 [/home]: group quotas turned off
/dev/mapper/vg0-lv0 [/home]: user quotas turned off
8.编辑quota文件
激活磁盘配额
[root@wangfc ~]# quotaon /home
用edquota命令,对特定用户采用配额限制
[root@wangfc ~]# edquota -u test
Disk quotas for user test (uid 506):
Filesystem blocks soft hard inodes soft hard
/dev/mapper/vg0-lv0 18 10 20 9 0 0
7.查看磁盘配额
[root@wangfc ~]# repquota -a
*** Report for user quotas on device /dev/mapper/vg0-lv0
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 13 0 0 2 0 0
test +- 18 10 20 7days 9 0 0
8.测试
[test@wangfc ~]$ dd if=/dev/zero of=file1 bs=1k count=10
dd: writing `file1': Disk quota exceeded
2+0 records in
1+0 records out
1024 bytes (1.0 kB) copied, 0.00025672 s, 4.0 MB/s
[test@wangfc ~]$ dd if=/dev/zero of=file2 bs=1k count=10
dd: opening `file2': Disk quota exceeded
1. 文件系统 (filesystem):说明该限制值是针对哪个文件系统 (partition);
2. 磁盘容量 (blocks):这个数值是 quota 自己算出来的,单位为 Kbytes,请丌要更劢他;
3. soft:磁盘容量 (block) 的 soft 限制值,单位亦为 KB
4. hard:block 的 hard 限制值,单位 KB;
5. 档案数量 (inodes):这是 quota 自己算出来的,单位为个数,请不要更改它;
6. soft:inode 的 soft 限制值;
7. hard:inode 的 hard 限制值;
实验结果如下:
[xxx@localhost ~]$ dd if=/dev/zero of=f1 bs=24M count=1
dd: writing `f1': Disk quota exceeded
1+0 records in
0+0 records out
17776640 bytes (18 MB) copied, 0.560308 s, 31.7 MB/s
[xxx@localhost ~]$ rm *
[xxx@localhost ~]$ touch {1,2,3,4,5}
[xxx@localhost ~]$ ls
1 2 3 4 5
[xxx@localhost ~]$ touch {6,7,8}
touch: cannot touch `8': Disk quota exceeded
[xxx@localhost ~]$ ls
1 2 3 4 5 6 7
8.把XXX账户的配额复制给yyy用户
[root@localhost ~]# edquota -p xxx -u yyy
[root@localhost ~]# edquota -u yyy
Disk quotas for user yyy (uid 502):
Filesystem blocks soft hard inodes soft hard
/dev/sda3 32 10240 17360 8 12 15
上一篇:LVM续
下一篇:磁盘阵列(RAID)

提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
Quota linux磁盘配额
Quota linux磁盘配额
Quota linux磁盘配额