歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux系統中對磁盤配額(Quota),軟陣列(RAID)的實現

Linux系統中對磁盤配額(Quota),軟陣列(RAID)的實現

日期:2017/2/28 14:37:09   编辑:Linux教程

Linux系統中對磁盤配額(Quota),軟陣列(RAID)的實現

1.創建測試的用戶和修改掛載的參數
[root@localhost ~]# useradd user1 --新建兩個用戶
[root@localhost ~]# useradd user2
[root@localhost ~]# mount -o remount,usrquota,grpquota /mnt/sdb --重新掛載,加參數
[root@localhost ~]# mount -l --查看掛載選項
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sdb1 on /mnt/sdb type ext4 (rw,usrquota,grpquota)
[root@localhost ~]# quotacheck -avug -mf --生成兩個quota文件
quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/sdb1 [/mnt/sdb] done
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Checked 2 directories and 0 files
quotacheck: Old file not found.
quotacheck: Old file not found.
[root@localhost ~]# ll /mnt/sdb --查看生成的兩個文件
total 26
-rw-------. 1 root root 6144 Jan 9 17:59 aquota.group
-rw-------. 1 root root 6144 Jan 9 17:59 aquota.user
drwx------. 2 root root 12288 Jan 9 17:55 lost+found
[root@localhost ~]# quotaon -avug --開啟quota功能
/dev/sdb1 [/mnt/sdb]: group quotas turned on
/dev/sdb1 [/mnt/sdb]: user quotas turned on
[root@localhost ~]# edquota -u user1
Disk quotas for user user1 (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 10 20 0 0 0
[root@localhost ~]# edquota -u user2
Disk quotas for user user2 (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 5 10 0 0 0

[root@localhost ~]# useradd user1 --新建兩個用戶
[root@localhost ~]# useradd user2
[root@localhost ~]# mount -o remount,usrquota,grpquota /mnt/sdb --重新掛載,加參數
[root@localhost ~]# mount -l --查看掛載選項
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
/dev/sdb1 on /mnt/sdb type ext4 (rw,usrquota,grpquota)
[root@localhost ~]# quotacheck -avug -mf --生成兩個quota文件
quotacheck: Your kernel probably supports journaled quota but you are not using it. Consider switching to journaled quota to avoid running quotacheck after an unclean shutdown.
quotacheck: Scanning /dev/sdb1 [/mnt/sdb] done
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Cannot stat old user quota file: No such file or directory
quotacheck: Cannot stat old group quota file: No such file or directory
quotacheck: Checked 2 directories and 0 files
quotacheck: Old file not found.
quotacheck: Old file not found.
[root@localhost ~]# ll /mnt/sdb --查看生成的兩個文件
total 26
-rw-------. 1 root root 6144 Jan 9 17:59 aquota.group
-rw-------. 1 root root 6144 Jan 9 17:59 aquota.user
drwx------. 2 root root 12288 Jan 9 17:55 lost+found
[root@localhost ~]# quotaon -avug --開啟quota功能
/dev/sdb1 [/mnt/sdb]: group quotas turned on
/dev/sdb1 [/mnt/sdb]: user quotas turned on
[root@localhost ~]# edquota -u user1 --用戶user1使用/mnt/sdb目錄不要起過20M
Disk quotas for user user1 (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 10000 20000 0 0 0
[root@localhost ~]# edquota -u user2 --用戶user2對sdb目錄不要超過10M,大於5M超出指定時間刪除
Disk quotas for user user2 (uid 501):
Filesystem blocks soft hard inodes soft hard
/dev/sdb1 0 5000 10000 0 0 0

2.驗證配額
[root@localhost ~]# su - user1
[user1@localhost ~]$ cd /mnt/sdb
[user1@localhost sdb]$ dd if=/dev/zero of=12 bs=1M count=5 --創建5M的文件沒有警告信息,正常
5+0 records in
5+0 records out
5242880 bytes (5.2 MB) copied, 0.0525754 s, 99.7 MB/s
[user1@localhost sdb]$ ll -h 12
-rw-rw-r--. 1 user1 user1 5.0M Jan 9 18:16 12
[user1@localhost sdb]$ dd if=/dev/zero of=123 bs=1M count=21 --創建12M的文件有警告信息,表示失敗
sdb1: warning, user block quota exceeded.
sdb1: write failed, user block limit reached.
dd: writing `123': Disk quota exceeded
20+0 records in
19+0 records out
20475904 bytes (20 MB) copied, 0.20094 s, 102 MB/s
[user1@localhost sdb]$ ll -h 123
-rw-rw-r--. 1 user1 user1 0 Jan 9 18:17 123
[user1@localhost sdb]$ exit
logout
[root@localhost ~]# su - user2 --用戶user2測試
[user2@localhost ~]$ cd /mnt/sdb
[user2@localhost sdb]$ dd if=/dev/zero of=23 bs=1M count=8 --寫入8M文件成功
sdb1: warning, user block quota exceeded.
8+0 records in
8+0 records out
8388608 bytes (8.4 MB) copied, 0.0923618 s, 90.8 MB/s
[user2@localhost sdb]$ ll -h 23 --查看文件大小
-rw-rw-r--. 1 user2 user2 8.0M Jan 9 18:23 23
[user2@localhost sdb]$
[user2@localhost sdb]$ dd if=/dev/zero of=23 bs=1M count=11 --寫入11M文件失敗
sdb1: warning, user block quota exceeded.
sdb1: write failed, user block limit reached.
dd: writing `23': Disk quota exceeded
10+0 records in
9+0 records out
10235904 bytes (10 MB) copied, 0.106298 s, 96.3 MB/s
[user2@localhost sdb]$

3.查看quota配置,修改警告時間,取消quota
[root@localhost ~]# quota -vu user1 user2 --查找指定的用戶quota信息
Disk quotas for user user1 (uid 500):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 0 10000 20000 0 0 0
Disk quotas for user user2 (uid 501):
Filesystem blocks quota limit grace files quota limit grace
/dev/sdb1 8193* 5000 10000 6days 1 0 0
[root@localhost ~]# repquota -av --所有用戶和quota信息
*** Report for user quotas on device /dev/sdb1
Block grace time: 7days; Inode grace time: 7days
Block limits File limits
User used soft hard grace used soft hard grace
----------------------------------------------------------------------
root -- 13 0 0 2 0 0
user1 -- 0 10000 20000 0 0 0
user2 +- 8193 5000 10000 6days 1 0 0
Statistics:
Total blocks: 7
Data blocks: 1
Entries: 3
Used average: 3.000000
[root@localhost ~]# edquota -t --修改文件警告天數(Block 天數 Inode 天數)
Grace period before enforcing soft limits for users:
Time units may be: days, hours, minutes, or seconds
Filesystem Block grace period Inode grace period
/dev/sdb1 7days 7days
[root@localhost ~]# vim /etc/warnquota.conf --查看警告信息
[root@localhost ~]# quotaoff /mnt/sdb --關閉quota功能

推薦閱讀

Linux學習筆記:磁盤配額(Quota)與高級文件系統管理 http://www.linuxidc.com/Linux/2013-02/79558.htm

RHCE培訓筆記——磁盤配額 http://www.linuxidc.com/Linux/2013-03/81237.htm

Linux下磁盤配額(quota)應用與實戰教程 http://www.linuxidc.com/Linux/2012-12/75900.htm

RHEL5.5中創建softRaid10並使用quota限制磁盤配額 http://www.linuxidc.com/Linux/2012-11/75147.htm

VMware下RedHat 5.4磁盤配額(Quota) http://www.linuxidc.com/Linux/2012-09/70937.htm

Copyright © Linux教程網 All Rights Reserved