Linux下磁盤配額
阿新 • • 發佈:2017-10-12
linux 磁盤配額
限定用戶或對組磁盤空間的使用
安裝quote包
[[email protected] ~]# yum install quota
格式化磁盤
[[email protected] ~]# 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
[[email protected] ~]# mkdir /tmp/sdc
[[email protected] ~]# mount -o remount,usrquota,grpquota /tmp/sdc
開機自動掛載 [[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 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 | 詳細顯示指令執行過程,便於排錯或了解程序執行的情形 |
[[email protected] 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
[[email protected] sdc]# setenforce 0 #臨時性關閉SELinux,重啟失效 setenforce: SELinux is disabled
永久關閉SELinux,重啟後生效
[[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
用戶和組賬號配額設置
[[email protected] sdc]# useradd hyx [[email protected] 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 | |
參數 | 說明 |
-u | 設置用戶的quota,這是預設的參數 |
-g | 設置群組的quota |
-p(源用戶名稱) | 將源用戶的quota設置套用至其他用戶或群組 |
-t | 設置寬限期限 |
激活磁盤配額
[[email protected] 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 | 顯示指令執行過程 |
驗證:
[[email protected] hyx]$ dd if=/dev/zero of=test bs=1k count=10 記錄了10+0 的讀入 記錄了10+0 的寫出 10240字節(10 kB)已復制,0.000136044 秒,75.3 MB/秒 [[email protected] hyx]$ ls -lh 總用量 12K -rw-rw-r-- 1 hyx hyx 10K 10月 10 20:20 test [[email protected] hyx]$ rm -rf * [[email protected] 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/秒 [[email protected] hyx]$ ls -lh 總用量 60K -rw-rw-r-- 1 hyx hyx 60K 10月 10 20:20 test [[email protected] hyx]$ rm -rf * [[email protected] 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/秒 [[email protected] hyx]$ ls -lh 總用量 80K -rw-rw-r-- 1 hyx hyx 80K 10月 10 20:20 test
最大不超過80K
[[email protected] sdc]# tune2fs -l /dev/sdc | grep "Block size" Block size: 4096
說明磁盤配額中的blocks,一個block是1K。
本文出自 “PooV的博客” 博客,請務必保留此出處http://xyhms.blog.51cto.com/12505169/1971458
Linux下磁盤配額