centos7 xfs 文件系统配置quota 用户磁盘配额

贵有恒,何必三更起、五更眠、最无益,只怕一日曝、十日寒。这篇文章主要讲述centos7 xfs 文件系统配置quota 用户磁盘配额相关的知识,希望能为你提供帮助。
XFS是扩展性高、高性能的文件系统。也是rhel7/centos7的默认文件系统。
XFS支持metadata journaling,这使其能从crash中更快速的恢复。
它也支持在挂载和活动的状态下进行碎片整理和扩容。
通过延迟分配,XFS 赢得了许多机会来优化写性能。
可通过工具xfsdump和xfsrestore来备份和恢复xfs文件系统,
xfsdump可使用dump级别来完成增量备份,还可通过size,subtree,inode flags来排除文件。
也支持user、group、project配额。
下面将介绍如何创建xfs文件系统,分配配额以及对其扩容:
###############################################################################
将/dev/sdb分区(2G),并启动LVM功能

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 [root@localhost zhongq]#parted /dev/sdbGNU Parted 3.1 Using /dev/sdbWelcome to GNU Parted! Type help to view a list of commands.(parted) mkpart primary 4 2048 (parted) set 1 lvm on (parted) p Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 2147MB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: NumberStartEndSizeFile systemNameFlags 14194kB2048MB2044MBprimarylvm

###############################################################################
创建PV
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 [root@localhost zhongq]# pvcreate /dev/sdb1Physical volume "/dev/sdb1" successfully created [root@localhost zhongq]# pvdisplay--- Physical volume ---PV Name/dev/sda2VG NamecentosPV Size24.51 GiB / not usable 3.00 MiBAllocatableyes (but full)PE Size4.00 MiBTotal PE6274Free PE0Allocated PE6274PV UUID9hp8U7-IJM6-bwbP-G9Vn-IVuJ-yvE8-AkFjcB "/dev/sdb1" is a new physical volume of "1.90 GiB"--- NEW Physical volume ---PV Name/dev/sdb1VG NamePV Size1.90 GiBAllocatableNOPE Size0Total PE0Free PE0Allocated PE0PV UUIDbu7yIH-1440-BPy1-APG2-FpvX-ejLS-2MIlA8
###############################################################################
将/dev/sdb1分配到名为xfsgroup00的VG
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 [root@localhost zhongq]# vgcreatexfsgroup00 /dev/sdb1 Volume group "xfsgroup00" successfully created[root@localhost zhongq]# vgdisplay --- Volume group ---VG NamecentosSystem IDFormatlvm2Metadata Areas1Metadata Sequence No3VG Accessread/writeVG StatusresizableMAX LV0Cur LV2Open LV2Max PV0Cur PV1Act PV1VG Size24.51 GiBPE Size4.00 MiBTotal PE6274Alloc PE / Size6274 / 24.51 GiBFreePE / Size0 / 0VG UUIDT3Ryyg-R0rn-2i5r-7L5o-AZKG-yFkh-CDzhKm --- Volume group ---VG Namexfsgroup00System IDFormatlvm2Metadata Areas1Metadata Sequence No1VG Accessread/writeVG StatusresizableMAX LV0Cur LV0Open LV0Max PV0Cur PV1Act PV1VG Size1.90 GiBPE Size4.00 MiBTotal PE487Alloc PE / Size0 / 0FreePE / Size487 / 1.90 GiBVG UUIDejuwcc-sVES-MWWB-3Mup-n1wB-Kd0g-u7jm0H
###############################################################################
使用命令lvcreate来创建xfsgroup00组大小为1G的名为xfsdata的LV
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 [root@localhost zhongq]# lvcreate -L 1024M -n xfsdata xfsgroup00WARNING: xfs signature detected on /dev/xfsgroup00/xfsdata at offset 0. Wipe it? [y/n] yWiping xfs signature on /dev/xfsgroup00/xfsdata.Logical volume "xfsdata" created[root@localhost zhongq]# lvdisplay--- Logical volume ---LV Path/dev/centos/swapLV NameswapVG NamecentosLV UUIDEnW3at-KlFG-XGaQ-DOoH-cGPP-8pSf-teSVbhLV Write Accessread/writeLV Creation host, time localhost, 2014-08-18 20:15:25 +0800LV Statusavailable# open2LV Size2.03 GiBCurrent LE520Segments1AllocationinheritRead ahead sectorsauto- currently set to8192Block device253:0 --- Logical volume ---LV Path/dev/centos/rootLV NamerootVG NamecentosLV UUIDzmZGkv-Ln4W-B8AY-oDnD-BEk2-6VWL-L0cZOvLV Write Accessread/writeLV Creation host, time localhost, 2014-08-18 20:15:26 +0800LV Statusavailable# open1LV Size22.48 GiBCurrent LE5754Segments1AllocationinheritRead ahead sectorsauto- currently set to8192Block device253:1 --- Logical volume ---LV Path/dev/xfsgroup00/xfsdataLV NamexfsdataVG Namexfsgroup00LV UUIDO4yvoY-XGcD-0zPm-eilR-3JJP-updU-rRCSlJLV Write Accessread/writeLV Creation host, time localhost.localdomain, 2014-09-23 15:50:19 +0800LV Statusavailable# open0LV Size1.00 GiBCurrent LE256Segments1AllocationinheritRead ahead sectorsauto- currently set to8192Block device253:3
###############################################################################
格式化分区为xfs文件系统。
注意:xfs被创建后,其size将无法缩小,但可以通过xfs_growfs来增大
1 2 3 4 5 6 7 8 9 10 [root@localhost zhongq]# mkfs.xfs /dev/xfsgroup00/xfsdatameta-data=https://www.songbingjia.com/dev/xfsgroup00/xfsdata isize=256agcount=4, agsize=65536 blks=sectsz=512attr=2, projid32bit=1=crc=0data=https://www.songbingjia.com/android/bsize=4096blocks=262144, imaxpct=25=sunit=0swidth=0 blksnaming=version 2bsize=4096ascii-ci=0 ftype=0log=internal logbsize=4096blocks=2560, version=2=sectsz=512sunit=0 blks, lazy-count=1realtime =noneextsz=4096blocks=0, rtextents=0
###############################################################################
挂载xfs系统分区到指定目录,并通过参数uquota,gquota开启文件系统配额。
1 2 3 4 5 [root@localhost zhongq]# mkdir /xfsdata[root@localhost zhongq]# mount -o uquota,gquota /dev/xfsgroup00/xfsdata /xfsdata[root@localhost zhongq]# chmod 777 /xfsdata[root@localhost zhongq]# mount|grep xfsdata/dev/mapper/xfsgroup00-xfsdata on /xfsdata type xfs (rw,relatime,attr2,inode64,usrquota,grpquota)
###############################################################################
使用xfs_quota命令来查看配额信息以及为用户和目录分配配额,并验证配额限制是否生效。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 [root@localhost zhongq]# xfs_quota -x -c report /xfsdataUser quota on /xfsdata (/dev/mapper/xfsgroup00-xfsdata)BlocksUser IDUsedSoftHardWarn/Grace ---------- -------------------------------------------------- root00000 [--------] Group quota on /xfsdata (/dev/mapper/xfsgroup00-xfsdata)BlocksGroup IDUsedSoftHardWarn/Grace ---------- -------------------------------------------------- root00000 [--------] [root@localhost zhongq]# xfs_quota -x -c limit bsoft=100M bhard=120M zhongq /xfsdata[root@localhost zhongq]#xfs_quota -x -c report /xfsdataUser quota on /xfsdata (/dev/mapper/xfsgroup00-xfsdata)BlocksUser IDUsedSoftHardWarn/Grace ---------- -------------------------------------------------- root00000 [--------] zhongq010240012288000 [--------] Group quota on /xfsdata (/dev/mapper/xfsgroup00-xfsdata)BlocksGroup IDUsedSoftHardWarn/Grace ---------- -------------------------------------------------- root00000 [--------] [root@localhost zhongq]# su zhongq[zhongq@localhost ~]$ dd if=/dev/zero of=/xfsdata/zq00 bs=1M count=100100+0 records in 100+0 records out 104857600 bytes (105 MB) copied, 28.9833 s, 3.6 MB/s[zhongq@localhost ~]$ dd if=/dev/zero of=/xfsdata/zq01 bs=1M count=100dd: error writing ‘/xfsdata/zq01’: Disk quota exceeded 21+0 records in 20+0 records out 20971520 bytes (21 MB) copied, 4.18921 s, 5.0 MB/s [zhongq@localhost ~]$ exit [root@localhost zhongq]# xfs_quotaxfs_quota> helpdf [-bir] [-hn] [-f file] -- show free and used counts for blocks and inodeshelp [command] -- help for one or all commandsprint -- list known mount points and projectsquit -- exit the programquota [-bir] [-gpu] [-hnNv] [-f file] [id|name]... -- show usage and limits Use help commandname for extended help.xfs_quota> printFilesystemPathname //dev/mapper/centos-root /boot/dev/sda1 /var/lib/docker/dev/mapper/centos-root /xfsdata/dev/mapper/xfsgroup00-xfsdata (uquota, gquota) xfs_quota> quota -u zhongqDisk quotas for User zhongq (1000)FilesystemBlocksQuotaLimitWarn/TimeMounted on /dev/mapper/xfsgroup00-xfsdata12288010240012288000[6 days]/xfsdata
【centos7 xfs 文件系统配置quota 用户磁盘配额】###############################################################################
先使用命令lvextend将LV扩展为1.5G(初始容量是1G),然后使用命令xfs_growfs来对xfs文件系统扩容(这里以block计数)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 [root@localhost zhongq]# lvextend -L 1.5G /dev/xfsgroup00/xfsdataExtending logical volume xfsdata to 1.50 GiBLogical volume xfsdata successfully resized [root@localhost zhongq]# xfs_growfs /dev/xfsgroup00/xfsdata -D 393216meta-data=https://www.songbingjia.com/dev/mapper/xfsgroup00-xfsdata isize=256agcount=4, agsize=65536 blks=sectsz=512attr=2, projid32bit=1=crc=0data=https://www.songbingjia.com/android/bsize=4096blocks=262144, imaxpct=25=sunit=0swidth=0 blksnaming=version 2bsize=4096ascii-ci=0 ftype=0log=internalbsize=4096blocks=2560, version=2=sectsz=512sunit=0 blks, lazy-count=1realtime =noneextsz=4096blocks=0, rtextents=0 data blocks changed from 262144 to 393216 [root@localhost zhongq]# df -h|grep xfsdata/dev/mapper/xfsgroup00-xfsdata1.5G153M1.4G10% /xfsdata

    推荐阅读