[Linux]紅帽高級存儲功能 - Stratis與VDO


Stratis 卷管理文件系統

介紹

image-20220413143920555

紅帽的 Stratis 是新一代的存儲管理解決方案,稱為卷管理文件系統。可以通過它創建文件系統及調整其大小時以動態、透明的方式來管理卷層。

Stratis 以管理物理存儲池的服務形式運行,並透明地為所創建的文件系統創建和管理卷。由於 Stratis 使用現有的存儲驅動程序和工具,因此 Stratis 也支持當前在 lvm、xfs 和設備映射器中使用的所有高級存儲功能。Stratis 文件系統沒有固定大小,也不再預分配未使用的塊空間。

Stratis 使用存儲的元數據來識別所管理的池、卷和文件系統。因此絕不應該對 Stratis 創建的文件系統進行手動重新格式化或重新配置;只應使用 Stratis 工具和命令對它們進行管理。手動配置 Stratis 文件系統可能會導致該元數據丟失,並阻止 Stratis 識別它已創建的文件系統。您可以使用不同組的塊設備來創建多個池。在每個池中,您可以創建一個或多個文件系統。目前每個池最多可以創建 2^24 個文件系統。

img

在內部 Stratis 使用 Backstore 子系統來管理塊設備,並使用 Thinpool 子系統來管理池。Backstore 有一個數據層,負責維護塊設備磁盤上的元數據,以及檢測和糾正數據損壞。緩存層使用高性能塊設備作為數據層之上的緩存。Thinpool 子系統管理與 Stratis 文件系統關聯的精簡部署卷。該子系統使用 dm-tin設備映射器驅動程序取代 LVM 進行虛擬卷大小調整和管理。dm-thin 可以創建虛擬大小比較大,但物理大小比較小的卷, 采用 XFS 格式。當物理大小快要滿時,Stratis 會自動將其擴大。

特點

使用Stratis管理分層存儲,有以下的好處:

  • 自動精簡配置(超額分配)
  • 文件系統快照
  • 基於池的存儲管理
  • 存儲監控

Stratis相關概念:

  • blockdev:塊設備
  • pool:存儲池
  • filesystem:文件系統

對應關系:

  • 1個Pool,最多可以創建2²⁴個文件系統,自動分配大小,當總數據量接近虛擬分配的大小則自動擴容,只要存儲池物理設備充足,理論上無限擴展。

使用

  1. 安裝軟件包
[root@localhost /]# yum install -y stratis-cli stratisd
  1. 啟動服務並設置服務開機自啟
[root@localhost /]# systemctl enable --now stratisd
  1. 添加一塊SATA硬盤,創建存儲池
[root@localhost ~]# stratis pool create pool1 /dev/sdb
  1. 查看可用池列表
[root@localhost ~]# stratis pool list
Name                  Total Physical   Properties                                   UUID
pool1   5 GiB / 37.63 MiB / 4.96 GiB      ~Ca,~Cr   d45d2be9-e1ca-4700-a03f-365eda2eac34
  1. 再次添加一塊硬盤,添加這個塊設備到存儲池
[root@localhost ~]# stratis pool add-data pool1 /dev/sdc
  1. 查看池的塊設備
[root@localhost ~]# stratis blockdev list
Pool Name   Device Node   Physical Size   Tier
pool1       /dev/sdb              5 GiB   Data
pool1       /dev/sdc              5 GiB   Data

[root@localhost ~]# stratis pool list
Name                   Total Physical   Properties                                   UUID
pool1   10 GiB / 41.63 MiB / 9.96 GiB      ~Ca,~Cr   d45d2be9-e1ca-4700-a03f-365eda2eac34
  1. 為池創建動態、靈活的文件系統
[root@localhost ~]# stratis filesystem create pool1 fs1

  1. 查看文件系統
[root@localhost ~]# stratis filesystem list
Pool Name   Name   Used      Created             Device                   UUID            
pool1       fs1    546 MiB   Apr 13 2022 15:22   /dev/stratis/pool1/fs1   b28ec1f4-21ed-4d89-84f5-d8ca91ef12ce

[root@localhost ~]# blkid /dev/stratis/pool1/fs1
/dev/stratis/pool1/fs1: UUID="b28ec1f4-21ed-4d89-84f5-d8ca91ef12ce" TYPE="xfs"
  1. 掛載文件系統

這里的 x-systemd.requires=stratisd.service,是通過 systemd 來確保 stratisd.service(Stratis服務的守護進程)啟動,再掛載這個文件系統,否則電腦將無法開機。

[root@localhost ~]# vim /etc/fstab
...
UUID=b28ec1f4-21ed-4d89-84f5-d8ca91ef12ce /dir1 xfs     defaults,x-systemd.requires=stratisd.service    0 0

[root@localhost ~]# mount -a

[root@localhost ~]# df -hT
Filesystem                                                                                      Type      Size  Used Avail Use% Mounted on
...
/dev/mapper/stratis-1-d45d2be9e1ca4700a03f365eda2eac34-thin-fs-b28ec1f421ed4d8984f5d8ca91ef12ce xfs       1.0T  7.2G 1017G   1% /dir1
  1. 創建文件測試
[root@localhost ~]# echo hello world > /dir1/file1
  1. 創建快照
[root@localhost ~]# stratis filesystem snapshot pool1 fs1 snap1

[root@localhost ~]# stratis filesystem list
Pool Name   Name    Used      Created             Device                     UUID         
pool1       fs1     546 MiB   Apr 13 2022 15:22   /dev/stratis/pool1/fs1     b28ec1f4-21ed-4d89-84f5-d8ca91ef12ce
pool1       snap1   546 MiB   Apr 13 2022 15:31   /dev/stratis/pool1/snap1   6dafb135-a4f8-49a8-a757-0c78cb430fb2

[root@localhost ~]# rm -rf /dir1/file1 

[root@localhost ~]# mount /dev/stratis/pool1/snap1 /dir2

[root@localhost ~]# cat /dir2/file1

VDO 虛擬數據優化器

介紹

LVM只能解決容量的問題,但不具備數據壓縮的能力。

VDO(Virtual Data Optimize):虛擬數據優化器,通過壓縮或刪除存儲設備上的數據來優化空間,VDO層放置在現有塊存儲設備上層,例如RAID設備或本地磁盤的頂部。

特點

  • kvdo:用於控制數據壓縮
  • uds:用於重復數據刪除

vdo不僅能對數據進行壓縮,還能對重復的數據進行優化。

Linux下依賴vdo.service服務,否則是不能使用vdo的

使用

  1. 安裝軟件包(默認已安裝)
[root@localhost ~]# yum install -y vdo
  1. 創建VDO卷
[root@localhost ~]# vdo create --name=vdo1 --device=/dev/sdb --vdoLogicalSize=10G
Creating VDO vdo1
      The VDO volume can address 6 GB in 3 data slabs, each 2 GB.
      It can grow to address at most 16 TB of physical storage in 8192 slabs.
      If a larger maximum size might be needed, use bigger slabs.
Starting VDO vdo1
Starting compression on VDO vdo1
VDO instance 0 volume is ready at /dev/mapper/vdo1
  1. 查看VDO卷的屬性與狀態
[root@localhost ~]# vdo status --name=vdo1
VDO status:
  Date: '2022-04-13 16:34:12+08:00'
  Node: localhost.localdomain
Kernel module:
  Loaded: true
  Name: kvdo
  Version information:
    kvdo version: 6.2.2.117
Configuration:
  File: /etc/vdoconf.yml
  Last modified: '2022-04-13 16:33:40'
VDOs:
  vdo1:
    Acknowledgement threads: 1
    Activate: enabled
    Bio rotation interval: 64
    Bio submission threads: 4
    Block map cache size: 128M
    Block map period: 16380
    Block size: 4096
    CPU-work threads: 2
    Compression: enabled
    Configured write policy: auto
    Deduplication: enabled
    Device mapper status: 0 20971520 vdo /dev/sdb normal - online online 1049638 2621440
    Emulate 512 byte: disabled
    Hash zone threads: 1
    Index checkpoint frequency: 0
    Index memory setting: 0.25
    Index parallel factor: 0
    Index sparse: disabled
    Index status: online
    Logical size: 10G
    Logical threads: 1
    Max discard size: 4K
    Physical size: 10G
    Physical threads: 1
    Slab size: 2G
    Storage device: /dev/sdb
    UUID: VDO-59a6cb34-0ba6-4e3d-81b8-967710ca668f
    VDO statistics: not available
  1. 顯示VDO卷列表
[root@localhost ~]# vdo list
vdo1
  1. 停止和啟動VDO卷
[root@localhost ~]# vdo stop -n vdo1
Stopping VDO vdo1

[root@localhost ~]# vdo start -n vdo1
Starting VDO vdo1
Starting compression on VDO vdo1
VDO instance 1 volume is ready at /dev/mapper/vdo1

  1. 查看VDO卷上是否啟用了壓縮(Compression)和重復數據(Deduplication)刪除功能
[root@localhost ~]# vdo status --name=vdo1 | grep Dedu
    Deduplication: enabled


[root@localhost ~]# vdo status --name=vdo1 | grep Com
    Compression: enabled
  1. 格式化VDO卷
[root@localhost ~]# mkfs.xfs -K /dev/mapper/vdo1
meta-data=/dev/mapper/vdo1       isize=512    agcount=4, agsize=655360 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=2621440, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
  1. 檢查設備事件處理是否完成
[root@localhost ~]# udevadm settle
  1. 創建掛載點,設置開機自動掛載
[root@localhost ~]# mkdir /mnt/vdo1

[root@localhost ~]# blkid | grep vdo1
/dev/mapper/vdo1: UUID="b4373f24-2c29-4893-bce3-fb608025107d" TYPE="xfs"

[root@localhost ~]# vim /etc/fstab
...
UUID=b4373f24-2c29-4893-bce3-fb608025107d /mnt/vdo1 xfs defaults,x-systemd.requires=vdo.service 0 0

[root@localhost ~]# mount /mnt/vdo1/

  1. 查看卷初始信息
[root@localhost /]# vdostats --human-readable
Device                    Size      Used Available Use% Space saving%
/dev/mapper/vdo1         10.0G      4.0G      6.0G  40%           N/A
  1. 准備一個大文件用於測試
[root@localhost /]# dd if=/dev/urandom of=/root/testfile1 bs=1M count=300
300+0 records in
300+0 records out
314572800 bytes (315 MB, 300 MiB) copied, 12.8609 s, 24.5 MB/s

[root@localhost /]# ls -lh /root/testfile1 
-rw-r--r--. 1 root root 300M Apr 13 17:06 /root/testfile1
  1. 把文件復制到VDO卷掛載目錄
[root@localhost /]# cp /root/testfile1 /mnt/vdo1/testfile1.1
[root@localhost /]# vdostats --human-readable
Device                    Size      Used Available Use% Space saving%
/dev/mapper/vdo1         10.0G      4.3G      5.7G  42%            3%
  1. 重復多次操作觀察Used與Saving%的變化
[root@localhost /]# cp /root/testfile1 /mnt/vdo1/testfile1.2
[root@localhost /]# vdostats --human-readable
Device                    Size      Used Available Use% Space saving%
/dev/mapper/vdo1         10.0G      4.3G      5.7G  43%           48%

[root@localhost /]# cp /root/testfile1 /mnt/vdo1/testfile1.3
[root@localhost /]# vdostats --human-readable
Device                    Size      Used Available Use% Space saving%
/dev/mapper/vdo1         10.0G      4.3G      5.7G  43%           65%


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM