限定用户或对组磁盘空间的使用
安装quote包
[root@localhost ~]# yum install quota
格式化磁盘
[root@localhost ~]# mkfs.ext4 /dev/sdcmke2fs 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 blocks1310720 inodes, 5242880 blocks262144 blocks (5.00%) reserved for the super user第一个数据块=0Maximum filesystem blocks=4294967296160 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock 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 or180 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 1UUID=50f0c9fb-8d2a-4d5b-8c49-79fccc445240 /boot ext4 defaults 1 2/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0tmpfs /dev/shm tmpfs defaults 0 0devpts /dev/pts devpts gid=5,mode=620 0 0sysfs /sys sysfs defaults 0 0proc /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.userdrwx------ 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 hyxDisk quotas for group hyx (gid 500): Filesystem blocks soft hard inodes soft hard /dev/sdc 0 50 80 0 0 0~
命令:edquota 功能:编辑用户和群组的quota | |
参数 | 说明 |
-u | 设置用户的quota,这是预设的参数 |
-g | 设置群组的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配置文件 | |
参数 | 说明 |
-u | 开启用户的磁盘空间限制 |
-g | 开启群组的磁盘空间限制 |
-a | 开启在/etc/fstab文件里,有加入quota设置的分区的空间限制 |
-v | 显示指令执行过程 |
验证:
[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=60sdc: 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=90sdc: 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
最大不超过80K
[root@localhost sdc]# tune2fs -l /dev/sdc | grep "Block size"Block size: 4096
说明磁盘配额中的blocks,一个block是1K。