设为首页 加入收藏

TOP

磁盘配额quota
2017-10-12 18:05:33 】 浏览:6060
Tags:磁盘 配额 quota

磁盘配额

1 启用磁盘配额

首先创建新的分区 /dev/sd5,并创建文件系统。

[root@local ~]# mkfs.ext4 /dev/sda5

由于xfs 不磁盘配额能成功,这里使用ext4.

然后把/dev/sda5分区挂载到 /home

[root@local ~]# mount /dev/sda5 /home

[root@local ~]# blkid /dev/sda5

/dev/sda5: UUID="8879cf63-99a5-43bb-9bfe-de303afb0799" TYPE="ext4"

修改 /etc/fstab 文件

[root@local ~]# vim /etc/fstab

UUID=dddd23d1-1012-4bac-9717-56b9b469e0c2 / ext4 defaults 1 1

UUID=316d8677-25b8-49af-b4eb-54daa20b6595 /boot ext4 defaults 1 2

UUID=dacd6ddd-d765-4646-b98c-0579f2732749 swap swap defaults 0 0

UUID=8879cf63-99a5-43bb-9bfe-de303afb0799 /home ext4 defaults,usrquota,grpquota 0 0

usrquota为启用磁盘的用户磁盘配额功能,grpquota为启用磁盘的组磁盘配额功能。

[root@centos7 ~]# mount –a /home/

查看挂载是否成功

[root@local ~]# mount

sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime,seclabel)

proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)

[……]

/dev/sda5 on /home type ext4 (rw,relatime,seclabel,quota,usrquota,grpquota,data=ordered)

可以看到/dev/sda5已经正确挂载

2创建配额数据库

[root@centos7 ~]# quotacheck -cug /home

由于/etc/fstab 文件设置了usrquota,grpquota,所以这里必须是 –cug,u对应usrquota,g对应grpquota。

现在查看/home目录,会多出两个文件,说明磁盘配额数据库创建成功。

[root@local ~]# ll /home/

total 36

-rw-------. 1 root root 7168 Apr 25 11:03 aquota.group

-rw-------. 1 root root 7168 Apr 25 11:03 aquota.user

drwx------. 3 centos centos 4096 Apr 16 10:20 centos

drwx------. 2 root root 16384 Apr 25 10:55 lost+found

3 启用数据库

[root@local ~]# quotaon /home/

[root@local ~]#

下来查看一下,可以看到以及启用成功。

[root@local ~]# quotaon -p /home/

group quota on /home (/dev/sda5) is on

user quota on /home (/dev/sda5) is on

4 磁盘配额设置

设置user1 磁盘配额为100M,80M时发出警告

[root@local ~]# edquota user1

Disk quotas for user user1 (uid 1001):

Filesystem blocks soft hard inodes soft hard

/dev/sda5 52 80000 100000 13 0 0

这里的默认单位为block ,1个block为1K。soft为警告值,hard为最大值,

现在来确认一下配置是否成功

[root@local ~]# quota user1    #查看用户user 的磁盘配额
Disk quotas for user user1 (uid 1001):
Filesystem blocks quota limit grace files quota limit grace
/dev/sda5 52 80000 100000 13 0 0

5 测试

(1)创建测试的用户 user1

[root@local ~]# useradd uesr1

切换到user1用户

[root@local ~]# su - user1
Last login: Tue Apr 25 11:08:41 CST 2017 on pts/1

(2)创建文件测试

首先创建一个50M 的文件testquota。

[user1@local ~]$ dd if=/dev/zero of=testquota bs=1M count=50
50+0 records in
50+0 records out
52428800 bytes (52 MB) copied, 0.562963 s, 93.1 MB/s

可以看到一切正常

    再来创建一个35M 的文件testquota2。

[user1@local ~]$ dd if=/dev/zero of=testquota2 bs=1M count=35

sda5: warning, user block quota exceeded.
35+0 records in
35+0 records out
36700160 bytes (37 MB) copied, 0.348267 s, 105 MB/s

由于50M+35M=85M 大于80M

所有看到这次发出警告了,但是操作还是成功了

    下来再创建一个20M的文件testquota3。

[user1@local ~]$ dd if=/dev/zero of=testquota3 bs=1M count=20

sda5: write failed, user block limit reached.
dd: error writing 'testquota3': Disk quota exceeded
13+0 records in
12+0 records out
13217792 bytes (13 MB) copied, 0.165029 s, 80.1 MB/s

由于已经超过最大值100M,所以创建失败了!

测试完成,实验结束!

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇情景linux--如何优雅地退出telnet 下一篇ngix_http_stub_status_module

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目