linux下的磁盘配额简介暨 linux下加挂硬盘续

简介:
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 /]# 


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


本文转自 yuzeying1 51CTO博客,原文链接:http://blog.51cto.com/yuzeying/154493

相关文章
|
2天前
|
存储 监控 Linux
Linux: 检测磁盘坏块 你得会吧!
Linux: 检测磁盘坏块 你得会吧!
42 19
Linux: 检测磁盘坏块 你得会吧!
|
3天前
|
监控 固态存储 Linux
如何判断Linux磁盘是SSD还是HDD?
总的来说,判断磁盘是SSD还是HDD并不复杂,只需要使用正确的命令和方法,就可以轻松得到结果。希望这些信息对你有所帮助,如果你还有其他问题,欢迎随时提问。
43 15
|
1月前
|
Linux
Linux系统ext4磁盘扩容实践指南
这个过程就像是给你的房子建一个新的储物间。你需要先找到空地(创建新的分区),然后建造储物间(格式化为ext4文件系统),最后将储物间添加到你的房子中(将新的分区添加到文件系统中)。完成这些步骤后,你就有了一个更大的储物空间。
160 10
|
3月前
|
Ubuntu Linux 网络安全
Linux磁盘挂接教程
Linux磁盘挂接教程
102 14
|
6月前
|
Unix Linux 对象存储
Linux 磁盘管理
Linux 磁盘管理
76 1
|
6月前
|
大数据 Linux 开发工具
【Linux】命令简介------迅速掌握Linux命令
【Linux】命令简介------迅速掌握Linux命令
|
6月前
|
监控 Linux 测试技术
Linux系统命令与网络,磁盘和日志监控总结
Linux系统命令与网络,磁盘和日志监控总结
129 0
|
6月前
|
监控 Linux 测试技术
Linux系统命令与网络,磁盘和日志监控三
Linux系统命令与网络,磁盘和日志监控三
98 0
Linux让挂载的硬盘永久生效
Linux让挂载的硬盘永久生效
Linux让挂载的硬盘永久生效
下一篇
oss创建bucket