所谓磁盘配额,就是设置某一个文件系统(分区)内的用户可使用空间大小。
用途
- WWW server 服务器,针对每个人的网页空间容量限制
- Mail server 每个人的邮件空间限制
- file server 每个人的最大可用的网络硬盘空间;本次试验就是为公司搭建一塔文件服务器。
实现步骤如下:
- 创建3个用户
#!/bin/bash
#program:Create 3 users and specify the user group.
#date:2017-02-27
#author:racher
#email:1576768715@qq.com
groupadd myquotagrp
for username in myquota1 myquota2 myquota3
do
useradd -g myquotagrp $username
echo "123.com" | passwd --stdin $username
done
- 文件系统支持
- 检查/home是否是独立的文件系统
- 用mount查询一哈/hoem的文件系统格式
[root@localhost home]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 4.8G 2.0G 2.6G 44% /
tmpfs 372M 0 372M 0% /dev/shm
/dev/sda1 190M 33M 147M 19% /boot
/dev/sda2 4.0G 33M 4.0G 1% /home
[root@localhost home]# mount | grep home
/dev/sda2 on /home type xfs (rw)
- 手动加入quota支持
[root@localhost home]# mount -o remount,usrquota,grpquota /home
[root@localhost home]# mount | grep home
/dev/sda2 on /home type xfs (rw,usrquota,grpquota)
- 开机自动挂载
- /etc/fstab
/dev/sda2 /home ext4 defaults,usrquota,grpquota 1 2
- 生成配置文件
[root@rhel6 test]# quotacheck -avug
[root@rhel6 test]# ls -a -l
total 40
drwxr-xr-x 3 root root 4096 Feb 28 18:25 .
drwxr-xr-x. 30 root root 4096 Feb 26 14:07 ..
-rw------- 1 root root 6144 Feb 28 18:25 aquota.group
-rw------- 1 root root 6144 Feb 28 18:25 aquota.user
drwx------ 2 root root 16384 Feb 28 18:18 lost+found
- 启动quota
[root@rhel6 test]# quotaon -auvg
/dev/sdb1 [/test]: group quotas turned on
/dev/sdb1 [/test]: user quotas turned on
-
quota 设置大小
命令编辑:
setquota -u jhadmin 100 150 0 0 /home/
内容设置:
[root@rhel6 test]# edquota -u zz Disk quotas for user zz (uid 16777256): Filesystem blocks soft hard inodes soft hard /dev/sdb1 0 500000 600000 0 0 0
修改宽限时间
[root@rhel6 test]# 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/sdb1 3days 7days
~
~
- 测试
[zz@rhel6 test]$ dd if=/dev/zero of=gkd bs=10M count=100
dd: writing `gkd': Disk quota exceeded
1+0 records in
0+0 records out
0 bytes (0 B) copied, 0.00526488 s, 0.0 kB/s
- 查询使用情况
[root@rhel6 /]# quota -uvs zz
Disk quotas for user zz (uid 16777256):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 586M* 489M 586M 6days 2 0 0
- 复制zz用户给jhadmin
[root@rhel6 /]# edquota -p zz jhadmin123
[root@rhel6 /]# quota -uvs jhadmin123
Disk quotas for user jhadmin123 (uid 16777267):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 0 489M 586M 0 0 0
- 查询所有用户情况
[root@rhel6 /]# repquota -auvs
*** Report for user quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 20 0 0 2 0 0
nobody -- 0 489M 586M 0 0 0
#user1 +- 586M 489M 586M 6days 2 0 0
#user2 -- 0 489M 586M 0 0 0
#user3 -- 0 489M 586M 0 0 0
#user4 -- 0 489M 586M 0 0 0