Chinaunix首页 | 论坛 | 博客
  • 博客访问: 10444288
  • 博文数量: 2905
  • 博客积分: 20098
  • 博客等级: 上将
  • 技术积分: 36298
  • 用 户 组: 普通用户
  • 注册时间: 2009-03-23 05:00
文章存档

2012年(1)

2011年(3)

2009年(2901)

分类: LINUX

2009-06-20 17:32:51

linux下的磁盘配额简介暨 linux下加挂硬盘续
实验环境 VMware 6.5.2 +redhat Enterprise 5 as
clip_image002
以上是内核版本,还有方便起见加挂一块硬盘
这只是我的环境 实验与版本没有关系
首先解释一下 磁盘配额
它是特定用户在指定的分区上使用空间大小的限制
特定用户这里是不包括root的
指定的分区的意思可不是文件夹,
clip_image004
这个是windows 2003 的磁盘配额画面,大家做个比较
磁盘配额能干什么
常见的比如各大网站对我们邮箱的容量限制
在这里有这么几个作用:
容量配额 (限制特定用户在硬盘上的使用大小)
文件个数配额 (限制可以存储的文件个数)
软限制 类似与警告级别 写数据会报警
应限制 达到这个数量后在写数据室写不进的
还有一点 磁盘配额是对你的整个分区起作用的,所以实验环境挂块硬盘方便测试
实验开始
修改自动挂载文件
[root@localhost ~]# df
文件系统 1K-已用 可用 已用% 挂载点
/dev/sda3 7516200 4052356 3075876 57% /
/dev/sda1 101086 11060 84807 12% /boot
tmpfs 127812 0 127812 0% /dev/shm
/dev/sdb1 3850292 73248 3581456 3% /test
[root@localhost ~]# vi /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda2 swap swap defaults 0 0
# Beginning of the block added by the VMware software
.host:/ /mnt/hgfs vmhgfs defaults,ttl=5 0 0
# End of the block added by the VMware software
LABEL=/test /test ext3 defaults,usrquota 1 2
~
在defaults后面添加,usrquota 小心这里是英文状态下的逗号
保存退出
之后我们重新挂载一下
[root@localhost ~]# mount -o remount /test
[root@localhost ~]# quotacheck -cmu /test
创建配额文件
[root@localhost ~]# cd /test
[root@localhost test]# ls
aquota.user lost+found
[root@localhost test]#
但这时你用vi打开它是不行的,会发现全是乱码
[root@localhost test]# vi aquota.user
clip_image006
之后 创建一个普通用户aa
[root@localhost test]# useradd aa
[root@localhost test]# passwd aa
Changing password for user aa.
New UNIX password:
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@localhost test]#
命令成功执行
下一步:进行用户配额配置
[root@localhost test]# edquota -u aa
Disk quotas for user aa (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 0 0 0 0 0
~ 这是针对的分区 软限制 硬限制 软限制 硬限制
~ || 文 件 大 小 || 文 件 个 数 |
~
~
~
我们是用命令的方式进入文件的 他的具体操作就是标准vi操作
表示当前用户已经占用的文件个数,和大小 以k计算 比如现在 我们限制文件大小为10k
软限制为9||||硬限制为10 ,文件个数限制为5,软限制为4硬限制为5
Disk quotas for user aa (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 10 9 10 5 4 5
~
保存退出
[root@localhost test]# quotaon /test
启动磁盘配额
[root@localhost test]# su - aa
[aa@localhost ~]$ cd /test
[aa@localhost test]$ mkdir aa
mkdir: 无法创建目录 “aa”: 权限不够
[aa@localhost test]$
为什么没权限
给一下他
[root@localhost test]# cd ..
[root@localhost /]# ll
总计 142
drwxr-xr-x 2 root root 4096 04-08 18:36 bin
drwxr-xr-x 4 root root 1024 04-08 18:11 boot
drwxr-xr-x 11 root root 3980 04-30 18:33 dev
drwxr-xr-x 101 root root 12288 04-30 18:46 etc
drwxr-xr-x 4 root root 4096 04-30 18:46 home
drwxr-xr-x 14 root root 4096 04-08 18:24 lib
drwx------ 2 root root 16384 04-08 18:00 lost+found
drwxr-xr-x 2 root root 4096 04-30 18:33 media
drwxr-xr-x 2 root root 0 04-30 18:33 misc
drwxr-xr-x 3 root root 4096 04-08 19:26 mnt
drwxr-xr-x 2 root root 0 04-30 18:33 net
drwxr-xr-x 2 root root 4096 2006-10-11 opt
dr-xr-xr-x 134 root root 0 04-30 18:33 proc
drwxr-x--- 20 root root 4096 04-30 18:34 root
drwxr-xr-x 2 root root 12288 04-08 19:26 sbin
drwxr-xr-x 4 root root 0 04-30 18:33 selinux
drwxr-xr-x 2 root root 4096 2006-10-11 srv
drwxr-xr-x 11 root root 0 04-30 18:33 sys
drwxr-xr-x 3 root root 4096 04-30 18:49 test
drwxrwxrwt 15 root root 4096 04-30 19:03 tmp
drwxr-xr-x 14 root root 4096 04-08 18:07 usr
drwxr-xr-x 24 root root 4096 04-08 18:30 var
[root@localhost /]# chmod 777 test
实验环境就给他个最大权限吧
[aa@localhost ~]$ dd if=/dev/zero of=/test/aa
sdb1: write failed, user block limit reached.
dd: 正在写入 “/test/aa”: 超出磁盘限额
9+0 records in
8+0 records out
4096 bytes (4.1 kB) copied, 0.0127423 seconds, 321 kB/s
[aa@localhost ~]$
这里是复制一个文件到test/aa下 他会不停地写入0 字符直至写满为止,,
限额已经生效
[aa@localhost test]$ rm -rf aa
[aa@localhost test]$ ls
aquota.user lost+found
[aa@localhost test]$ touch aa
[aa@localhost test]$ touch bb
[aa@localhost test]$ touch cc
sdb1: write failed, user block limit reached.
touch: 无法触碰 “cc”: 超出磁盘限额
[aa@localhost test]$ touch dd
touch: 无法触碰 “dd”: 超出磁盘限额
[aa@localhost test]$
建到cc的时候已经是第五个了,所以建立失败,建bb的时候由于是软限制,所以还是能建的
最后取消磁盘配额quotaoff /
[root@localhost /]# quotaoff /test
[root@localhost /]#


写在最后,只是简单的涉及磁盘配额,并不进行深入探讨,文中有不对的地方,还望看到的朋友多多指教,

http://yuzeying.blog.51cto.com/644976/154493

阅读(2164) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~