磁盘配额quota

磁盘配额  quota
限制用户或组对磁盘的使用,例如文件服务器,邮件服务器。。。

针对分区
1.让文件系统支持配额
# vim /etc/fstab
LABEL=/1           /    ext3    defaults, usrquota,grpquota         1 1
# mount -o remount /
# mount
/dev/sda2 on / type ext3 (rw, usrquota,grpquota )

2.创建磁盘配额的数据库
quotacheck -acug  //扫描-a所有分区, c创建数据库文件, u用户, g组配额文件
quotacheck: Cannot remount filesystem mounted on / read-only so counted values might not be right.
Please stop all programs writing to filesystem or use -m flag to force checking.
# ls /aquota*
ls: /aquota*: No such file or directory
# quotacheck -acug  -m //强制
# ls /
aquota.group
aquota.user 


3.启动磁盘配额
quotaon -a  //启动所有分区的磁盘配额
#quotaoff -a //关闭磁盘配额 /etc/fstab设置了的

===日常管理===
+++设置配额+++
方法一:edquota
edquota -u alice
Disk quotas for user alice (uid 501):
  Filesystem          blocks        soft       hard      inodes      soft     hard
  /dev/sda2          36          0          0          9        0        0
blocks:  从磁盘的使用量限制,比如限制用户使用100M, 单位是k
inodes: 从创建文件数限制,比如只能建立100个文件
soft: 软限制 block 80M
hard: 硬限制 block 100M

#  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/sda3                     7days                  7days
grace time: 宽限期, 默认7天

示例:
#  edquota -u alice
Disk quotas for user alice (uid 501):
  Filesystem      blocks       soft       hard     inodes     soft     hard
  /dev/sda2         36          0       10240       9        0        20
[root@station230 ~]# su - alice
[alice@station230 ~]$ quota 
Disk quotas for user alice (uid 501): 
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sda2      36       0   10240              20*      0      20  

方法二:  setquota
# setquota -u username block软限制 block硬限制 inode软限制 inode硬限制 分区
setquota -u jack 80000 100000 15 20 /dev/sda2
# quota jack

方法三: 复制
edquota -p alice tom robin user1 user2 user3
将alice的配额方案复制给后面所有用户
查看单个用户的配额:# quota jack
查看所有用户的配额:# repquota -a
                  # repquota -ag    //-g 组


=== 针对组设置配额 ===  *****
对公司的各个部门进行限制
组hr:  block 100M, inodes 200  整个组的成员一共能使用100M,200个文件

示例:限制hr组的成员能在/home目录中:100M 50文件
[root@station230 ~]# groupadd hr
[root@station230 ~]# useradd hr01 -G hr      //这里虽然hr01附加组属于hr,但是hr01自己创建的文件属主、有效组都是hr01,不受hr的限制
[root@station230 ~]# useradd hr02 -G hr
[root@station230 ~]# mkdir /home/hrdir
[root@station230 ~]# chmod 777 /home/hrdir/
# edquota -g hr
Disk quotas for group hr (gid 503):
  Filesystem       blocks       soft       hard     inodes     soft     hard
  /dev/sda2         32          0        100000           8        0        50
# repquota -ag
===============================================================
让新建文件属于hr
[root@station230 alice]# ll -d /home/hrdir/
drwxrwxrwx 2 root root 4096 11-02 16:20 /home/hrdir/
[root@station230 alice]#  chgrp hr  /home/hrdir/
[root@station230 alice]# chmod  g+s  /home/hrdir/       
  //通过 设置sgid 的方式,使 新建的文件的有效组直接继承hr ,这样就会受hr组磁盘配额的限制
[root@station230 alice]# 
[root@station230 alice]# ll -d /home/hrdir/
drwxrw s rwx 2 root  hr  4096 11-02 16:20 /home/hrdir/
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值