标签:rate 优先 mkf 挂载 设置 cti ESS script 森林
XFS是一种高性能的日志文件系统,
它是由SGI公司设计的,被称为业界最先进的、最具可升级性的文件系统技术。
最初是从unix(irix)移植到linux系统上的。
从centos7开始,xfs成为了默认的文件系统
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
说明:作者:刘宏缔 邮箱: 371125307@qq.com
说明:格式化文件系统前需要创建分区,请参考这一篇
https://www.cnblogs.com/architectforest/p/12642634.html
1,最大单文件大小:500TB
最大分区大小: 1024TB
2,相比较之下,centos6 的ext4:
最大单文件大小:16TB
最大分区大小: 16TB
可见对于大型文件系统的支持,xfs比ext4要好得多
1,查看所属的包
[root@blog ~]# whereis mkfs.xfs mkfs: /usr/sbin/mkfs /usr/sbin/mkfs.cramfs /usr/sbin/mkfs.minix /usr/sbin/mkfs.xfs
/usr/sbin/mkfs.ext2 /usr/sbin/mkfs.ext3 /usr/sbin/mkfs.ext4
/usr/sbin/mkfs.fat /usr/sbin/mkfs.msdos /usr/sbin/mkfs.vfat /usr/share/man/man8/mkfs.8.gz [root@blog ~]# rpm -qf /usr/sbin/mkfs.xfs xfsprogs-4.19.0-2.el8.x86_64
2,找不到mkfs.xfs命令时,可以用yum安装
[root@blog ~]# yum install xfsprogs
1,查看mkfs.xfs的版本
[root@blog ~]# mkfs.xfs -V mkfs.xfs version 5.0.0
2,查看帮助:不指定参数时,会打印帮助信息
[root@blog ~]# mkfs.xfs
1,查看分区的文件系统:
[root@blog ~]# parted --list Model: Virtio Block Device (virtblk) Disk /dev/vdb: 537GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 537GB 537GB primary
可以看到文件系统字段下面为空,表示还没有格式化
2,xfs格式化
#使用 mkfs.xfs 加分区
[root@blog ~]# mkfs.xfs /dev/vdb1 meta-data=/dev/vdb1 isize=512 agcount=4, agsize=32767872 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=1, sparse=1, rmapbt=0 = reflink=1 data = bsize=4096 blocks=131071488, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0, ftype=1 log =internal log bsize=4096 blocks=63999, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
说明:如果当前分区已经有文件系统存在,则需要加-f参数
/* force overwrite */ [-f]
3,再次查看分区:
[root@blog ~]# parted --list Model: Virtio Block Device (virtblk) Disk /dev/vdb: 537GB Sector size (logical/physical): 512B/512B Partition Table: gpt Disk Flags: Number Start End Size File system Name Flags 1 1049kB 537GB 537GB xfs primary
可以看到分区的文件系统已格式化为xfs
4,把格式化好后的分区挂载到/databak这个目录
查看分区的挂载情况
[root@blog ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 7.5G 0 7.5G 0% /dev tmpfs 7.5G 0 7.5G 0% /dev/shm tmpfs 7.5G 480K 7.5G 1% /run tmpfs 7.5G 0 7.5G 0% /sys/fs/cgroup /dev/vda1 100G 14G 87G 14% / tmpfs 1.5G 0 1.5G 0% /run/user/1000
创建目录并挂载
[root@blog ~]# mkdir /databak
#挂载时用mount命令 [root@blog ~]# mount /dev/vdb1 /databak
再次查看挂载情况
[root@blog ~]# df -h Filesystem Size Used Avail Use% Mounted on devtmpfs 7.5G 0 7.5G 0% /dev tmpfs 7.5G 0 7.5G 0% /dev/shm tmpfs 7.5G 480K 7.5G 1% /run tmpfs 7.5G 0 7.5G 0% /sys/fs/cgroup /dev/vda1 100G 14G 87G 14% / tmpfs 1.5G 0 1.5G 0% /run/user/1000 /dev/vdb1 500G 3.6G 497G 1% /databak
可以看到/dev/vdb1挂载到了/databak目录下,说明挂载已成功
5,编辑 /etc/fstab,使机器启动时此文件系统能自动挂载
用blkid得到分区的uuid
[root@blog ~]# blkid /dev/vda1: UUID="e32cfa7a-df48-4031-8fdf-5eec92ee3039" TYPE="xfs" PARTUUID="1863aa79-01" /dev/vdb1: UUID="7b7af437-97ef-4f76-8ea1-bb6498ae0f44" TYPE="xfs" PARTLABEL="primary" PARTUUID="c124c0e4-3626-4abf-a3e5-503c52e31417"
编辑 /etc/fstab
[root@blog ~]# vi /etc/fstab
增加一行,保存后退出:
UUID=7b7af437-97ef-4f76-8ea1-bb6498ae0f44 /databak xfs defaults 0 2
第一列:设备id,centos默认用uuid指定设备,我们也建议采用这种格式
第二列: 挂载点,它需要是一个存在的目录,如果是swap分区时可以直接写swap
第三列: 文件系统类型,需要与格式化时的文件系统类型相同
第四列: 挂载参数:
auto: 系统自动挂载,fstab默认就是这个选项
defaults: 最常见参数,可以满足需要大多数文件系统使用
noauto 开机不自动挂载
nouser 只有超级用户可以挂载
ro 按只读权限挂载
rw 按可读可写权限挂载
user 任何用户都可以挂载
请注意光驱和软驱只有在装有介质时才可以进行挂载,因此它是noauto
第五列:是否允许备份操作
当其值设置为1时,将允许dump备份程序备份;设置为0时,忽略备份操作;
第六列:开机时磁盘的检查顺序
数字越小越优先检查,如果两个分区的数字相同,则同时检查。
当其值为0时,永远不检查。
根”/”分区永远都为1。其它分区从2开始
1,如果发生文件系统报错,需要进行修复
注意修复前要做umount
# xfs_repair 加分区名,是对此分区做xfs文件系统修复
[root@blog ~]# umount /databak [root@blog ~]# xfs_repair /dev/vdb1 Phase 1 - find and verify superblock... Phase 2 - using internal log - zero log... - scan filesystem freespace and inode maps... - found root inode chunk Phase 3 - for each AG... - scan and clear agi unlinked lists... - process known inodes and perform inode discovery... - agno = 0 - agno = 1 - agno = 2 - agno = 3 - process newly discovered inodes... Phase 4 - check for duplicate blocks... - setting up duplicate extent list... - check for inodes claiming duplicate blocks... - agno = 0 - agno = 1 - agno = 2 - agno = 3 Phase 5 - rebuild AG headers and trees... - reset superblock... Phase 6 - check inode connectivity... - resetting contents of realtime bitmap and summary inodes - traversing filesystem ... - traversal finished ... - moving disconnected inodes to lost+found ... Phase 7 - verify and correct link counts... done
2,注意:生产环境中应该系统盘和数据盘分开,则系统盘可以直接重做系统
3,常用的几个参数
# -L是修复xfs文件系统的最后手段,慎重选择,它会清空日志,会丢失用户数据和文件
[root@blog ~]# xfs_repair -L /dev/vdb1
# -n,检查文件系统是否损坏,如果损坏会列出将要执行的操作
即只检查不处理
[root@blog ~]# xfs_repair -n /dev/vdb1
1,备份:
创建一个文件,用来测试备份和恢复是否成功
[root@blog databak]# vi a.txt
内容:abcdefg
# -f 指定备份文件的路径
[root@blog ~]# xfsdump -f /root/databak.xfsdump /databak xfsdump: using file dump (drive_simple) strategy xfsdump: version 3.1.8 (dump format 3.0) - type ^C for status and control ============================= dump label dialog ============================== please enter label for this dump session (timeout in 300 sec) -> databak backup session label entered: "databak backup" --------------------------------- end dialog --------------------------------- xfsdump: level 0 dump of blog:/databak xfsdump: dump date: Mon Apr 6 15:53:46 2020 xfsdump: session id: 08fdf1fd-2056-4010-bb8e-43fbbc053b9f xfsdump: session label: "databak backup" xfsdump: ino map phase 1: constructing initial dump list xfsdump: ino map phase 2: skipping (no pruning necessary) xfsdump: ino map phase 3: skipping (only one dump stream) xfsdump: ino map construction complete xfsdump: estimated dump size: 25216 bytes ============================= media label dialog ============================= please enter label for media in drive 0 (timeout in 300 sec) -> vdb1 media label entered: "vdb1 " --------------------------------- end dialog --------------------------------- xfsdump: creating dump session media file 0 (media 0, file 0) xfsdump: dumping ino map xfsdump: dumping directories xfsdump: dumping non-directory files xfsdump: ending media file xfsdump: media file size 21872 bytes xfsdump: dump size (non-dir files) : 544 bytes xfsdump: dump complete: 26 seconds elapsed xfsdump: Dump Summary: xfsdump: stream 0 /root/databak.xfsdump OK (success) xfsdump: Dump Status: SUCCESS
两个label分别是:this dump session 和 media
我们输入了: databak backup 和 vdb1
2,查看备份文件的情况
#-I : 大写的i,用来显示备份的信息
[root@blog ~]# xfsdump -I file system 0: fs id: 7b7af437-97ef-4f76-8ea1-bb6498ae0f44 session 0: mount point: blog:/databak device: blog:/dev/vdb1 time: Mon Apr 6 15:53:46 2020 session label: "databak backup" session id: 08fdf1fd-2056-4010-bb8e-43fbbc053b9f level: 0 resumed: NO subtree: NO streams: 1 stream 0: pathname: /root/databak.xfsdump start: ino 132 offset 0 end: ino 133 offset 0 interrupted: NO media files: 1 media file 0: mfile index: 0 mfile type: data mfile size: 21872 mfile start: ino 132 offset 0 mfile end: ino 133 offset 0 media label: "vdb1 " media id: 0ff37aa0-a15e-43ed-a0b0-2b432570545f xfsdump: Dump Status: SUCCESS
3,删除文件后再恢复备份:
[root@blog ~]# cd /databak [root@blog databak]# ls a.txt [root@blog databak]# rm a.txt rm: remove regular file ‘a.txt‘? y [root@blog databak]# ls [root@blog databak]#
# -f 指定备份文件的路径
[root@blog databak]# xfsrestore -f /root/databak.xfsdump /databak xfsrestore: using file dump (drive_simple) strategy xfsrestore: version 3.1.8 (dump format 3.0) - type ^C for status and control xfsrestore: searching media for dump xfsrestore: examining media file 0 xfsrestore: dump description: xfsrestore: hostname: blog xfsrestore: mount point: /databak xfsrestore: volume: /dev/vdb1 xfsrestore: session time: Mon Apr 6 15:53:46 2020 xfsrestore: level: 0 xfsrestore: session label: "databak backup" xfsrestore: media label: "databak " xfsrestore: file system id: 7b7af437-97ef-4f76-8ea1-bb6498ae0f44 xfsrestore: session id: 08fdf1fd-2056-4010-bb8e-43fbbc053b9f xfsrestore: media id: 0ff37aa0-a15e-43ed-a0b0-2b432570545f xfsrestore: using online session inventory xfsrestore: searching media for directory dump xfsrestore: reading directories xfsrestore: 1 directories and 1 entries processed xfsrestore: directory post-processing xfsrestore: restoring non-directory files xfsrestore: restore complete: 0 seconds elapsed xfsrestore: Restore Summary: xfsrestore: stream 0 /root/databak.xfsdump OK (success) xfsrestore: Restore Status: SUCCESS
查看被删除的文件是否已恢复
[root@blog databak]# ls a.txt [root@blog databak]# more a.txt abcdefg
[root@blog databak]# cat /etc/redhat-release CentOS Linux release 8.0.1905 (Core)
标签:rate 优先 mkf 挂载 设置 cti ESS script 森林
原文地址:https://www.cnblogs.com/architectforest/p/12642735.html