- マウントオプション
XFS ではマウントオプションに uquota(ユーザ単位)、gquota(グループ単位)を用います。
以下の例では、/boot に uquota を追加しています。
# mount |grep /boot
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
# umount /boot
# mount -o uquota /dev/sda1 /boot
# mount |grep /boot
/dev/sda1 on /boot type xfs (rw,relatime,seclabel,attr2,inode64,usrquota)
恒久的に設定するため fstab に追加
#
# /etc/fstab
# Created by anaconda on Sun Jun 19 08:14:11 2016
#
# 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/centos-root / xfs defaults 0 0
UUID=f613494c-f547-4de1-9bca-c2ec994ac870 /boot xfs defaults,uquota 0 0
/dev/mapper/centos-home /home xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
|
- リミットの設定
リミットの設定は、xfs_quota(8)で行います。
# xfs_quota -[オプション] ファイルシステム
|
リミットの設定はエキスパートモード(高度な設定)が必要なので、-x オプションを使って起動します。xfs_quota は対話モードとなります。
# xfs_quota -x /boot
xfs_quota> state
User quota state on /boot (/dev/sda1)
Accounting: ON
Enforcement: ON
Inode: #77775 (1 blocks, 1 extents)
Group quota state on /boot (/dev/sda1)
Accounting: OFF
Enforcement: OFF
Inode: #0 (0 blocks, 0 extents)
Project quota state on /boot (/dev/sda1)
Accounting: OFF
Enforcement: OFF
Inode: #0 (0 blocks, 0 extents)
Blocks grace time: [7 days 00:00:30]
Inodes grace time: [7 days 00:00:30]
Realtime Blocks grace time: [7 days 00:00:30]
リミットの設定は limit サブコマンドで行い、主な引数は以下の通りです。
引数 | 解説 |
bsoft=nn | ブロック(ディスク容量)のソフトリミット
k,m,gなどの補助単位利用可 |
bhard=nn | ブロックのハードリミット |
isoft=nn | iノード(ファイル数)のソフトリミット |
ihard=nn | ブロックのハードリミット |
以下の例ではソフトリミット、ハードリミットをユーザ student に対し設定しています。
# xfs_quota -x /boot
xfs_quota> limit bsoft=10m bhard=20m isoft=10 ihard=10 student
xfs_quota> quit
- 設定表示
設定したリミットは report サブコマンドで表示できます。
主なオプション
オプション | 解説 |
-h | 補助単位を用い分かり易く表示 |
-b | ブロック単位の設定内容表示 |
-i | iノード単位の設定内容表示 |
-u | ユーザクォータ表示 |
-g | グループクォータ容表示 |
xfs_quota> report -h
User quota on /boot (/dev/sda1)
Blocks
User ID Used Soft Hard Warn/Grace
---------- ---------------------------------
root 138.8M 0 0 00 [------]
xfs_quota> report -hbiu
User quota on /boot (/dev/sda1)
Blocks Inodes
User ID Used Soft Hard Warn/Grace Used Soft Hard Warn/Grace
---------- --------------------------------- ---------------------------------
root 138.8M 0 0 00 [------] 379 0 0 00 [------]
student 0 1M 10M 00 [------] 0 10 20 00 [------]
- 利用状況の表示
quota(1)で現在の使用状況を表示します。このコマンドは ext2/3/4, XFS 共通です。
$ quota
Disk quotas for user student (uid 1000):
Filesystem blocks quota limit grace files quota limit grace
/dev/sda1 2820 10240 20480 13* 10 10 6days
また、xfs_quota の -c オプションを使うと、非対話モードで実行できます。
# xfs_quota -x /boot/ -c "report -hbiu"
User quota on /boot (/dev/sda1)
Blocks Inodes
User ID Used Soft Hard Warn/Grace Used Soft Hard Warn/Grace
---------- --------------------------------- ---------------------------------
root 138.8M 0 0 00 [------] 379 0 0 00 [------]
student 2.8M 10M 20M 00 [------] 13 10 10 00 [-none-]
xfs_quota はハードリミット超過時にエラーメッセージを表示します。
quota のようにソフトリミットでは警告メッセージは表示しません。
警告時にメールを当事者へ発進する warnquota で代用します。
- warnquota のインストール
warnquota のパッケージ名は quota-warnquota です。
# yum install quota-warnquota
読み込んだプラグイン:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.tsukuba.wide.ad.jp
* extras: ftp.tsukuba.wide.ad.jp
* updates: ftp.tsukuba.wide.ad.jp
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ quota-warnquota.x86_64 1:4.01-11.el7_2.1 を インストール
--> 依存性解決を終了しました。
依存性を解決しました
================================================================================
Package アーキテクチャー
バージョン リポジトリー 容量
================================================================================
インストール中:
quota-warnquota x86_64 1:4.01-11.el7_2.1 updates 76 k
トランザクションの要約
================================================================================
インストール 1 パッケージ
総ダウンロード容量: 76 k
インストール容量: 137 k
Is this ok [y/d/N]: y
Downloading packages:
quota-warnquota-4.01-11.el7_2.1.x86_64.rpm ] 0.0 B/s | 760kB 00:01 ETA
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
インストール中 : 1:quota-warnquota-4.01-11.el7_2.1.x86_64##### ] 1/1
検証中 : 1:quota-warnquota-4.01-11.el7_2.1.x86_64 1/1
インストール:
quota-warnquota.x86_64 1:4.01-11.el7_2.1
完了しました!
- warnquota の設定
監視対象となるファイルシステムを quottab に定義します。
/etc/quotatab
#
# This is sample quotatab (/etc/quotatab)
# Here you can specify description of each device for user
#
# Comments begin with hash in the beginning of the line
# Example of description
# /dev/loop0: This is loopback device
# /dev/hda4: Your home directory
/dev/sda1: Boot directory |
- warnquota の実行例
warnquota は実行するたびに利用状況をチェックし、ソフトリミットを超過したユーザに警告メールを発進します。
crontab に仕込んで実行する想定になっています。
# warnquota -s
#
$ mail
Heirloom Mail version 12.5 7/5/10. Type ? for help.
"/var/spool/mail/student": 2 messages 2 new
>N 1 root Sun Jul 10 10:16 18/610 "test"
N 2 root@example.com Sun Jul 10 10:16 29/1036 "NOTE: You are exceedi"
& 2
Message 2:
From root@h006.s144.la.net Sun Jul 10 10:16:35 2016
Return-Path: <root@h006.s144.la.net>
X-Original-To: student
Delivered-To: student@h006.s144.la.net
From: root@example.com
Reply-To: root@example.com
Subject: NOTE: You are exceeding your allocated disk space limits
To: student@h006.s144.la.net
Cc: root@example.com
Content-Type: text/plain; charset=UTF-8
Content-Disposition: inline
Date: Sun, 10 Jul 2016 10:16:35 +0900 (JST)
Status: R
Your disk usage has exceeded the agreed limits on this server
Please delete any unnecessary files on following filesystems:
Boot directory (/dev/sda1)
Block limits File limits
Filesystem used soft hard grace used soft hard grace
/dev/sda1 -+ 4K 1024K 10240K 12 10 20 6days
[--続ける--]
& quit
Held 2 messages in /var/spool/mail/student