zhouxingfu520 发表于 2013-1-28 22:03:15

linux quota配置

 
        linux(centos) quota配置在网络管理的工作中,由于硬盘的资源是有限的,常常需要为多用户的服务器设定用户的linux磁盘配额。这个功能对公用的多用户服务器(免费的或者收费的)来说,更是非常必要的。Quota就是在RedHatlinux下实现linux磁盘配额的工具。quota只支持单独的挂载文件系统  不是某一个目录。
 
1. 挂载目录加入 quota


查看/home目录挂载情况
# df -h /home
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3             2.0G   35M  1.8G   2% /home

# mount | grep home
/dev/sda3 on /home type ext4 (rw)

使用者与群组的 quota 文件系统支持参数:usrquota, grpquota
# mount -o remount,usrquota,grpquota /home

查看 确定加了usrquota,grpquota
#mount | grep home
/dev/sda3 on /home type ext4 (rw,usrquota,grpquota)

编辑 fstab文件让系统启动时挂载quota  
# vi /etc/fstab   重启后生效
LABEL=/home   /home  ext4   defaults,usrquota,grpquota  1 2
重新挂载
# umount /home
# mount -a
# mount | grep home


2. quota安装  生成usrquota, grpquota两个目录

对整个系统含有 usrquota, grpquota 参数的文件系统进行 quotacheck 扫瞄
# quotacheck -avug

-bash: command not found

#yum install quota 安装quota

# quotacheck -avug
自动创建 usrquota, grpquota两个目录
# ll -d /home/
-rw------- 1 root root 8192 Mar  6 11:58 /home/aquota.group
-rw------- 1 root root 9216 Mar  6 11:58 /home/aquota.user

 
这时, 由于某种需要,或者在某种情况,“不得不”运行这个命令:
# quotacheck -avug -mf
参数 -m 意思是:强迫在“读、写”模式下检查硬盘的 quota(有一定的“正在写”的数据丢失可能,应确保没有进程在写这个分区。建议在单用户模式下进行。)。

# quotaon -auvg   启动 quota
/dev/sda3 : group quotas turned on
/dev/sda3 : user quotas turned on


3. quota限制大小设置

myquota1账号加入quota 限制使用 在这里固定每个用户使用的磁盘大小为500M
# useradd myquota1
# edquota -u myquota1
 Filesystem    blocks    soft    hard  inodes  soft  hard
  /dev/sda3         80  500000  600000      10     0     0

复制myquota1用户的信息给 myquota2
# edquota -p myquota1 -u myquota2

# edquota -g myquotagrp 编辑myquotagrp组的总共使用大小
  Filesystem    blocks    soft     hard  inodes  soft  hard
  /dev/sda3        160  10000000  12000000       20     0     0


# edquota -t   修改宽限时间  当使用者文件超过大小时

# quota -uvs myquota1 myquota2 查询使用情况
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sda3      80    495M    595M              10       0       0
Disk quotas for user myquota2 (uid 501):
     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace
      /dev/sda3      80    495M    595M              10       0       0

# quota -gvs myquotagrp  查询myquotagrp组使用情况

  edquota -g myquotagrp
  Filesystem    blocks    soft     hard  inodes  soft  hard
  /dev/sda3        160   1000M     1200M      20     0     0

# repquota -auvs 查询所有用户使用情况

User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
root      --      20       0       0              2     0     0
myquota1  --      32       495M    595M           10     0     0
myquota2  --      32       495M    595M           10     0     0
myquotagrp --      64      1000M   1200M          20     0     0

Statistics:
Total blocks: 7
Data blocks: 1
Entries: 4
Used average: 4.000000



4. quota测试

利用 myquota1 的身份,建置一个 550MB 的大文件,并观察 quota 结果!
# dd if=/dev/zero of=bigfile bs=1M count=550
# repquota -auv
                        Block limits                File limits
User            used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
myquota1  +-  556840  500000  600000 13days      11     0     0

你可以发现 myquota1 的 grace 出现!

再创建另外一个大文件,让总容量超过 600M !
# dd if=/dev/zero of=bigfile2 bs=1M count=600
du -sk
600000  .  文件大小已经查过了设置的大小  操作失败

# warnquota  查看是否有警告信息
 
 
您如果要取消磁盘空间的限制,可用以下命令,请看:
# quotaoff /home (取消磁盘空间限制。)
# quotaon /home (现在启动磁盘空间限制。)
 
页: [1]
查看完整版本: linux quota配置