Restrict user or use of group disk space
Installing the Quote Package
[email protected] ~]# Yum Install quota
Format disk
[[email protected] ~]# mkfs.ext4 /dev/sdcmke2fs 1.41.12 (17-May-2010)/DEV/SDC is entire device, not just one partition! to continue? (y,n) y file System label = Operating system: Linux block Size =4096 (log=2) chunked size =4096 (log=2) stride=0 blocks, stripe width=0 blocks1310720 inodes, 5242880 blocks262144 blocks (5.00%) reserved for the super user first block of data =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 Writing Inode table : Complete creating journal (32768 blocks): complete writing superblocks and filesystem accounting information: Complete This filesystem will be automatically checked every 28 mounts or180 days, whichever Comes first. use tune2fs -c or -i to override.
Create directory Mount SDC
[Email protected] ~]# MKDIR/TMP/SDC
[Email protected] ~]# Mount-o REMOUNT,USRQUOTA,GRPQUOTA/TMP/SDC
Auto-mount [[Email protected] ~]# 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 &nbsP; sysfs defaults 0 0proc /proc proc defaults 0 0/dev/sdc /tmp/sdc ext4 defaults,usrquota,grpquota 0 0
Detect disk quotas and generate quota files
Command: Quotacheck Description: Executes the quotacheck instruction, scans the partition that is attached to the system, and generates Quota.user and Quota.group files under the file system root of each partition |
Parameters |
Description |
-C |
Create a quota file
|
-V
|
Show instruction execution Process
|
-U
|
Calculate the number of directories and files occupied by each user ID when scanning disk space
|
-G
|
Calculate the number of directories and files occupied by each group ID when scanning disk space
|
-A
|
Scanning in the/etc/fstab file, there are partitions added to the quota settings
|
-R
|
Exclude the partition where the root directory resides
|
-D
|
Detailed instruction execution process for troubleshooting or understanding program execution
|
[[email protected] sdc]# ll total dosage 32-rw-------1 root root 6144 October 19:12 aquota.group-rw-------1 root root 6144 October 10 19:12 aquota.userdrwx------2 root root 16384 October 19:03 lost+found
Turn off SELinux
[Email protected] sdc]# Setenforce 0 #临时性关闭SELinux, restart failure setenforce:selinux is disabled
Permanently close selinux, after reboot takes effect
[[email protected] 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
user and group account quota settings
[[email protected] sdc]# useradd hyx[[email protected] 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~
Command: Edquota Function: Edit user and Group quota |
Parameters
|
Description
|
-U
|
Set the user's quota, which is a preset parameter
|
-G
|
Set the quota of a group
|
-p (source user name)
|
Apply the quota settings of the source user to another user or group
|
-T
|
Set grace period
|
Activate disk quotas
[[email protected] sdc]# quotaon -ugv /tmp/sdc/ dev/sdc [/tmp/sdc]: group quotas turned on/dev/sdc [/tmp/sdc]: user Quotas turned on
Command: Quotaon Format: Quotaon parameter file system name The feature activates disk quotas; The file system root directory for each partition must have Quota.user and Quota.group configuration files |
Parameters |
Description |
-U |
To turn on the user's disk space limit |
-G |
Turn on disk space limits for groups |
-A |
Open in the/etc/fstab file, there is a space limit for the partition that joins the quota setting |
-V |
Show instruction execution Process |
Verify:
[[Email protected] hyx]$ dd if=/dev/zero of=test bs=1k count=10 Records the 10+0 Read 10+0 writes 10240 bytes (10 kb) copied,0.000136044 seconds, 75.3 mb/seconds [[email protected] HYX]$ LS -LH Total dosage 12k-rw-rw-r-- 1 hyx hyx 10k 10 month 10 20:20 test[[email protected] hyx]$ rm -rf *[[email protected] hyx]$ dd if=/dev/zero of=test bs=1k count=60sdc: warning, user block quota exceeded.sdc: warning, group block quota exceeded. Recorded the 60+0 read-in record 60+0 The write-out 61440 bytes (61 KB) have been copied,0.000374338 seconds, 164 mb/seconds [[email protected] hyx]$ ls - LH Total dosage 60k-rw-rw-r-- 1 hyx hyx 60k 10 Month 10 20:20 test[[email Protected] hyx]$ rm -rf *[[email protected] hyx]$ dd if=/dev/zero of=test bs=1k count=90sdc: write failed, user block limit reached.dd: writing "Test": The exceeded disk quota records the read-in record of the 81+0 80+0 81920 bytes (82 kb) copied,0.00050069 seconds, 164 mb/seconds [[email PROTECTED] HYX]$ LS -LH Total dosage 80k-rw-rw-r-- 1 hyx hyx 80k 10 month 10 20:20 test
Maximum not exceeding 80K
[Email protected] sdc]# Tune2fs-l/DEV/SDC | grep "Block Size" block size:4096
Describes the blocks in disk quotas, where a block is 1K.
This article is from the "Poov blog" blog, make sure to keep this source http://xyhms.blog.51cto.com/12505169/1971458
Disk quotas under Linux