大家可能都知道,当我们在163或者QQ上开通邮箱只有,我们都会获得一定的空间用于存储邮件和资料,还有一些FTP网站,你可以上传自己的文件在上面,以及现在许多的网络硬盘等,这些服务都对用户的硬盘使用量有一定限额,这个就是磁盘配额,为每一个用户分配不同的空间,在Linux里面就是使用quota来实现磁盘配额的。quota在大多数的Linux系统中的配置方法是一样的。
在Linux做quota这个和我装系统时候的分区有很大关系,比如你想在/home下作,最好就把/home作为一个独立分区,因为quota是对整个分区下所有的目录生效的。
Linux磁盘配额配置:
系统平台:RedHat 9.0
[root@xuqiang /]# rpm -qa | grep
quota查看是否安装此套件。
quota-3.09-1
1,编辑fstab,使其支持quota
我们做quota的时候一般是针对某一个分区的,那么该quota分区下所有的目录都要收quota影响的哦,所有我们要修改分区参数,。
这里我们在/home下作quota,
编辑/etc/fstab,添加usrquota和grpquota使此分区支持quota,
[root@xuqiang /]# vi /etc/fstab
LABEL=//ext3defaults1 1
none/dev/ptsdevptsgid=5,mode=6200 0
LABEL=/home/homeext3defaults,usrquota,grpquota
1
2
2,重新启动系统或者直接重新加载分区,使用一下命令:
[root@xuqiang /]# mount -o remount /home重新加载做quota的分区
3,生产用户和组的配额文件
[root@xuqiang /]# quotacheck-avug
quotacheck: Scanning /dev/sda3 [/home] done
quotacheck: Checked 14 directories and 33 files
quotacheck: Old file not found.
-----------------------------------
-a 扫描所有在/etc/mtab内含quota支持的文件系统,注意修改fstab,重新加载系统会自动一修改mtab
文件,
-a建立aquota.user
-g建立群组的目录使用情况文件,aquota.group
-v 显示扫描过程,
-M 强制扫描,当以上参数出现错误的时候,可以用。
---------------------------------------
查看配额分区产生的文件
[root@xuqiang /]# ll /home/
总用量 52
-rw-------1
rootroot71689月 18 16:59 aquota.group
-rw-------1 rootroot71689月 18 16:59 aquota.user
3,启动磁盘配额
[root@xuqiang /]# quotaon -avug
/dev/sda3 [/home]: group quotas turned on
/dev/sda3 [/home]: user quotas turned on
3,添加用户
[root@xuqiang /]# useradd test01
[root@xuqiang /]# useradd test02
[root@xuqiang /]# passwd test01
Changing password for user test01.
New password:
BAD PASSWORD: it's WAY too short
Retype new password:
passwd: all authentication tokens updated successfully.
[root@xuqiang /]# passwd test02
Changing password for user test02.
New password:
BAD PASSWORD: it's WAY too short
Retype new password:
passwd: all authentication tokens updated successfully.
[root@xuqiang /]# ls /home/
aquota.grouptest01
aquota.usertest02
5,为用户设定磁盘配额
[root@xuqiang /]# edquota [ -u username] [-g groupname]
[root@xuqiang /]# edquota –t修改宽限时间
[root@xuqiang /]# edquota –p 复制范本,将某个设定好的用户的quota复制给另外一个用户,
为test01做限额:
[root@xuqiang /]# edquota -u test01
Disk quotas for user test01 (uid 520):
Filesystem
blockssofthardinodessofthard
/dev/sda34410000150001100
/dev/sda3所在分区
test01占据该分区的大小
soft 设置警告大小,到这么多的是系统警告用户
hard 当警告之后还可以使用多少的空间 ,
inodes 对I节点做限制,这个不好控制,建议不做,后面的也是和inode有关的,默认不管,
设置宽限时间,过了这个没有清除到软限制之下的,其他空间将不能使用,
[root@xuqiang /]# edquota –t使用这个参数来设置宽限时间。
Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
FilesystemBlock grace
periodInode grace period
/dev/sda31days7days
[root@xuqiang /]# edquota -p test01 test02将这个限额同样给test02用户,
查询用户的限额情况:
[root@xuqiang /]# quota -vu test01 test02
Disk quotas for user test01 (uid 520):
Filesystemblocksquotalimitgracefilesquotalimitgrace
/dev/sda34410000150001100
Disk quotas for user test02 (uid 521):
Filesystemblocksquotalimitgracefilesquotalimitgrace
/dev/sda312410000150003000
[root@xuqiang /]# repquota –a 显示更详细的,
*** Report for user quotas on device /dev/sda3
Block grace time: 24:00; Inode grace time: 7days
Block
limitsFile limits
Userusedsofthardgraceusedsofthardgrace
----------------------------------------------------------------------
root--76
001200
h01--60001500
test01--4410000150001100
test02--12410000150003000
#522--56
001400
测试:
[root@xuqiang /]# su - test01使用test01用户登录,
[test01@hongtu test01]$ cp -Rv
/etc/.拷贝一个比较大的文件来试试
cp: 正在写入‘./etc/named.conf’: 超出磁盘限额
cp: 无法创建目录‘./etc/vsftpd’: 超出磁盘限额
‘/etc/vsftpd.user_list’ ->
‘./etc/vsftpd.user_list’
cp: 正在写入‘./etc/vsftpd.user_list’: 超出磁盘限额
‘/etc/vsftpd.ftpusers’ ->
‘./etc/vsftpd.ftpusers’
cp: 正在写入‘./etc/vsftpd.ftpusers’: 超出磁盘限额
‘/etc/gshadow-’ -> ‘./etc/gshadow-’
cp: 正在写入‘./etc/gshadow-’: 超出磁盘限额
OK,。C盘配额配置完成哦。