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

相关文章
|
16天前
|
Ubuntu Linux Shell
Linux系统中如何查看磁盘情况
【9月更文挑战第3天】在Linux系统中,有多种方式查看磁盘情况。可通过命令行工具`df`查看文件系统磁盘使用情况,选项`-h`以人类可读格式显示,`-T`显示文件系统类型;`du`命令显示目录或文件磁盘使用情况,`-h`以人类可读格式显示,`-s`仅显示总计;`fdisk -l`列出磁盘和分区信息。此外,图形界面的磁盘管理工具和文件管理器也可用于查看磁盘使用情况。这些方法有助于更好地管理磁盘空间。
|
29天前
|
存储 监控 安全
在Linux中,⼀个EXT3的文件分区,当使用touch test.file命令创建⼀个新文件时报错,报错的信息是提示磁盘已满,但是采用df -h命令查看磁盘大小时,只使用了,60%的磁盘空间,为什么会出现这个情况?
在Linux中,⼀个EXT3的文件分区,当使用touch test.file命令创建⼀个新文件时报错,报错的信息是提示磁盘已满,但是采用df -h命令查看磁盘大小时,只使用了,60%的磁盘空间,为什么会出现这个情况?
|
19天前
|
Linux Docker 容器
Linux的namespace和cgroups简介
本文介绍了Linux的Namespace技术和cgroups,解释了它们如何帮助实现容器的隔离和资源限制。
39 7
Linux的namespace和cgroups简介
|
26天前
|
存储 监控 Linux
|
29天前
|
Prometheus 监控 Ubuntu
在Linux中,如何进行磁盘性能监控?
在Linux中,如何进行磁盘性能监控?
|
29天前
|
存储 监控 Linux
在Linux中,如何管理磁盘配额?
在Linux中,如何管理磁盘配额?
|
29天前
|
监控 Shell Linux
在Linux中,如何使用shell脚本检测磁盘使用率?
在Linux中,如何使用shell脚本检测磁盘使用率?
|
29天前
|
监控 Linux
在Linux中,使用哪⼀个命令可以查看自己文件系统的磁盘空间配额呢?
在Linux中,使用哪⼀个命令可以查看自己文件系统的磁盘空间配额呢?
|
Ubuntu 安全 Unix
Linux 简介与安装|学习笔记
快速学习 Linux 简介与安装
166 0
|
12天前
|
Linux Shell
Linux 中 Tail 命令的 9 个实用示例
Linux 中 Tail 命令的 9 个实用示例
42 6
Linux 中 Tail 命令的 9 个实用示例