限定用户或对组磁盘空间的使用
安装quote包
[root@localhost ~]# yum install quota
格式化磁盘
[root@localhost ~]# mkfs.ext4 /dev/sdc
mke2fs 1.41.12 (17-May-2010)
/dev/sdc is entire device, not just one partition!
无论如何也要继续? (y,n) y
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
This filesystem will be automatically checked every 28 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
创建目录挂载sdc
[root@localhost ~]# mkdir /tmp/sdc
[root@localhost ~]# mount -o remount,usrquota,grpquota /tmp/sdc
开机自动挂载
[root@localhost ~]# vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Wed Oct 4 22:43:26 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1
UUID=50f0c9fb-8d2a-4d5b-8c49-79fccc445240 /boot ext4 defaults 1 2
/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0
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
/dev/sdc /tmp/sdc ext4 defaults,usrquota,grpquota 0 0
检测磁盘配额并生成配额文件
命令:quotacheck 说明:执行quotacheck指令,扫描挂入系统的分区,并在各分区的文件系统根目录下产生quota.user和quota.group文件 | |
参数 | 说明 |
-c | 创建配额文件 |
-v | 显示指令执行过程 |
-u | 扫描磁盘空间时,计算每个用户识别码所占用的目录和文件数目 |
-g | 扫描磁盘空间时,计算每个群组识别码所占用的目录和文件个数 |
-a | 扫描在/etc/fstab文件里,有加入quota设置的分区 |
-R | 排除根目录所在的分区 |
-d | 详细显示指令执行过程,便于排错或了解程序执行的情形 |
[root@localhost sdc]# ll
总用量 32
-rw------- 1 root root 6144 10月 10 19:12 aquota.group
-rw------- 1 root root 6144 10月 10 19:12 aquota.user
drwx------ 2 root root 16384 10月 10 19:03 lost+found
关闭SELinux
[root@localhost sdc]# setenforce 0 #临时性关闭SELinux,重启失效
setenforce: SELinux is disabled
永久关闭SELinux,重启后生效
[root@localhost sdc]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
用户和组账号配额设置
[root@localhost sdc]# useradd hyx
[root@localhost sdc]# edquota -g hyx
Disk quotas for group hyx (gid 500):
Filesystem blocks soft hard inodes soft hard
/dev/sdc 0 50 80 0 0 0
~
命令:edquota 功能:编辑用户和群组的quota | |
设置用户的quota,这是预设的参数 | |
设置群组的quota | |
-p(源用户名称) | 将源用户的quota设置套用至其他用户或群组 |
-t | 设置宽限期限 |
激活磁盘配额
[root@localhost sdc]# quotaon -ugv /tmp/sdc
/dev/sdc [/tmp/sdc]: group quotas turned on
/dev/sdc [/tmp/sdc]: user quotas turned on
命令:quotaon 格式:quotaon 参数 文件 系统名 功能激活磁盘配额;各分区的文件系统根目录必须有quota.user和quota.group配置文件 | |
开启用户的磁盘空间限制 | |
开启群组的磁盘空间限制 | |
开启在/etc/fstab文件里,有加入quota设置的分区的空间限制 | |
验证:
[hyx@localhost hyx]$ dd if=/dev/zero of=test bs=1k count=10
记录了10+0 的读入
记录了10+0 的写出
10240字节(10 kB)已复制,0.000136044 秒,75.3 MB/秒
[hyx@localhost hyx]$ ls -lh
总用量 12K
-rw-rw-r-- 1 hyx hyx 10K 10月 10 20:20 test
[hyx@localhost hyx]$ rm -rf *
[hyx@localhost hyx]$ dd if=/dev/zero of=test bs=1k count=60
sdc: warning, user block quota exceeded.
sdc: warning, group block quota exceeded.
记录了60+0 的读入
记录了60+0 的写出
61440字节(61 kB)已复制,0.000374338 秒,164 MB/秒
[hyx@localhost hyx]$ ls -lh
总用量 60K
-rw-rw-r-- 1 hyx hyx 60K 10月 10 20:20 test
[hyx@localhost hyx]$ rm -rf *
[hyx@localhost hyx]$ dd if=/dev/zero of=test bs=1k count=90
sdc: write failed, user block limit reached.
dd: 正在写入"test": 超出磁盘限额
记录了81+0 的读入
记录了80+0 的写出
81920字节(82 kB)已复制,0.00050069 秒,164 MB/秒
[hyx@localhost hyx]$ ls -lh
总用量 80K
-rw-rw-r-- 1 hyx hyx 80K 10月 10 20:20 test
[root@localhost sdc]# tune2fs -l /dev/sdc | grep "Block size"
Block size: 4096