XFS磁碟配額介紹以及配置

2021-10-03 07:04:31 字數 4700 閱讀 4081

為了避免伺服器**現類似的磁碟空間不足的問題,可以啟用磁碟配額功能,

對使用者指定的磁碟空間,檔案數量進行限制,

防止個別使用者惡意或無意占用大量的磁碟空間

系統中的xfs檔案系統配置管理磁碟配額的工具由xfsprogs軟體包含的xfs_quota配置管理程式提供

檢視是否安裝配置工具,檢視xfs_quota工具所在位置

[root@localhost

~]# rpm -q xfsprogs 檢視是否安裝配置工具

xfsprogs-

4.5.0

-15.el7.x86_64

[root@localhost

~]# rpm -ql xfsprogs | grep xfs_quota

/usr/sbin/xfs_quota

/usr/share/man/man8/xfs_quota.

8.gz

xfs_quota設定的磁碟配額,只在指定的檔案系統內有效,使用者使用未配額的檔案系統時,將不受限制

磁碟容量:限制使用者能夠使用的磁碟資料塊大小,預設單位kb

檔案數量:限制使用者可以建立的檔案個數 quota限制i

軟限制:指定乙個軟性的配額資料值,使用者超過這個資料時,系統給出警告信息,可以打破資料值

硬限制:指定乙個硬性的配額值,禁止使用者超過這個限制

核心

xfs_quota工具外,

前提條件即指定的分割槽必須已經掛載且支援磁碟配額功能

usrquota:支援對使用者的磁碟配額

grpquota:支援對組的磁碟配額

就是掛載的時候使用:-o usrquota grpquota 「mount掛載

實驗前提已經使用fdisk分好區了,童鞋們可以檢視以前的文章

首先建立乙個資料夾,掛載

[root@localhost

~]# mkdir /tmp/a

[root@localhost

~]# mount -o usrquota,grpquota /dev/sdb1 /tmp/a

[root@localhost

~]# mount | grep "/dev/sdb1"檢視掛載的

/dev/sdb1 on /root/a type xfs (rw,relatime,seclabel,attr2,inode

64,usrquota,grpquota)

賦予其他使用者讀寫許可權

[root@localhost

~]# chmod 777

/tmp/a

第二種方法:

若要開機自動掛載,修改/etc/fstab

[root@localhost

~]# vim /etc/fstab

/dev/sdb1 /tmp/a xfs defaults 0

0[root@localhost

~]# mount -a

建立乙個新使用者  alinux

[root@localhost

~]# useradd alinux

[root@localhost

~]# echo "123456"

|passwd --stdin alinux

更改使用者 alinux 的密碼 。

passwd:所有的身份驗證令牌已經成功更新。

限制檔案以及磁碟

[root@localhost

~]# xfs_quota -x -c 'limit -u bsoft=80m bhard=100m isof=80 ihard=100 alinux '

/tmp/a

僅限制磁碟容量時:

[root@localhost

~]# xfs_quota -x -c 'limit -u bsoft=80m bhard=100m alinux '

/tmp/a

僅限制檔案數量時:

[root@localhost

~]# xfs_quota -x -c 'limit -u isoft=80 ihard=100 alinux '

/tmp/a

檢視磁碟容量對於使用者是否受限制

[root@localhost

~]# xfs_quota -c 'quota -uv alinux '

/tmp/a

disk quotas for user alinux (

1001

)filesystem blocks quota limit warn/time mount

ed on/dev/sdb1 0

81920

10240000[

----

----

]/root

檢視檔案數量是否受限制:

/a[root@localhost

~]# xfs_quota -c 'quota -i -uv alinux ' a

disk quotas for user alinux (

1001

)filesystem files quota limit warn/time mounted on

/dev/sdb1 0

8010000[

----

----

]/root/a

[alinux@localhost

~]$ dd if

=/dev/zero of=

/tmp/a/aa bs=

1m count=

81記錄了81

+0 的讀入

記錄了81

+0 的寫出

84934656位元組(

85 mb)已複製,0.289575 秒,293 mb/秒

[alinux@localhost

~]$ dd if

=/dev/zero of=

/tmp/a/aa bs=

1m count=

100記錄了100

+0 的讀入

記錄了100

+0 的寫出

104857600位元組(

105 mb)已複製,0.139826 秒,750 mb/秒

[alinux@localhost

~]$ dd if

=/dev/zero of=

/tmp/a/aa bs=

1m count=

101dd: 寫入"/tmp/a/aa" 出錯: 超出磁碟限額

記錄了101

+0 的讀入

記錄了100

+0 的寫出

104857600位元組(

105 mb)已複製,0.0855834 秒,1.2 gb/秒

[alinux@localhost a]$ touch 

.txt

[alinux@localhost a]$ ls

100.txt 18.txt 26.txt 34.txt 42.txt 50.txt 59.txt 67.txt 75.txt 83.txt 91.txt 9.txt

10.txt 19.txt 27.txt 35.txt 43.txt 51.txt 5.txt 68.txt 76.txt 84.txt 92.txt

11.txt 1.txt 28.txt 36.txt 44.txt 52.txt 60.txt 69.txt 77.txt 85.txt 93.txt

12.txt 20.txt 29.txt 37.txt 45.txt 53.txt 61.txt 6.txt 78.txt 86.txt 94.txt

13.txt 21.txt 2.txt 38.txt 46.txt 54.txt 62.txt 70.txt 79.txt 87.txt 95.txt

14.txt 22.txt 30.txt 39.txt 47.txt 55.txt 63.txt 71.txt 7.txt 88.txt 96.txt

15.txt 23.txt 31.txt 3.txt 48.txt 56.txt 64.txt 72.txt 80.txt 89.txt 97.txt

16.txt 24.txt 32.txt 40.txt 49.txt 57.txt 65.txt 73.txt 81.txt 8.txt 98.txt

17.txt 25.txt 33.txt 41.txt 4.txt 58.txt 66.txt 74.txt 82.txt 90.txt 99.txt

[alinux@localhost a]$ touch

.txt

touch: 無法建立"101.txt"

: 超出磁碟限額

總結,對於使用者alinux來說建立檔案和占用磁碟有限制,說明對於使用者建立磁碟配額成功,不需要建立的時候,可以直接umount /dev/sdb1取消掛載即可

quota磁碟配額(xfs)

由於centos7預設檔案系統格式是xfs,所以我下面以xfs檔案系統為例,下篇文章講ext4配額,其實差不多,只不過多乙個步驟 yum install quota 將磁碟 dev sda3 掛到 data 下 重要引數 defaults,usrquota quotaon dev sdb1 開啟磁碟...

磁碟配額和raid配置

磁碟結構 主引導記錄 mbr master boot record mbr位於硬碟第乙個物理扇區處 mbr中包含硬碟的主引導程式和硬碟分割槽表 分割槽表有4個分割槽記錄區,每個分割槽記錄區佔16個位元組 linux中將硬碟,分割槽等裝置均表示為檔案 磁碟分割槽結構 硬碟中的主分割槽數目只有4個,因此...

linux下配置磁碟配額

在多使用者環境中,每個使用者都可能有大量的檔案存放在檔案系統中。如果對使用者檔案容量不加限制,磁碟空間就有可能被過多占用,造成系統無法正常工作,這也是網路黑客攻擊系統慣用的手段之一。因此,在許多情況下需要限制使用者的磁碟空間容量。linux可以規定使用者或組的磁碟的限額。一旦超出規定的限額,linu...