RHEL_高级磁盘管理(vdo、stratis)
阅读原文时间:2023年07月12日阅读:2

VDO简介

  • Virtual Data Optimizer 通过数据去重、压缩的方式来优化存储空间。
  • VDO层放置在现有块存储设备上,例如Raid设备、本地磁盘设备。
  • LVM 或文件系统 放置在VDO层之上,也可以将VDO放在LVM层之上
  • VDO工具需要用户手动安装,安装完成后即可使用vdo命令创建、添加、删除、激活、停止等操作

VDO安装

[root@localhost ~]# yum install -y vdo

vdo常用的选项

  1. vdo语法:vdo command

  2. command常用的参数:

    create 创建一个VDO卷及其关联索引使其可用。

    remove 删除一个或多个已停止的VDO卷和相关卷索引。

    modify 修改一个或所有VDO的配置参数卷。更改将在VDO下次运行时生效设备启动;已经运行的设备则不是受到影响。

    list 显示已启动VDO卷的列表。如果,所有指定它同时显示已启动和未启动卷。

    start 启动一个或多个已停止、激活的VDO卷相关的服务。

    status 以YAML格式报告VDO系统和卷状态。但是,这个命令不需要root特权如果没有,信息将是不完整的。

    stop 停止一个或多个正在运行的VDO卷和相关卷服务。

    activate 激活一个或多个VDO卷。激活卷可以使用“开始”命令启动。

    deactivate 使一个或多个VDO卷失效。停用不能通过“start”命令启动卷。停用当前正在运行的卷不会停止它。

    growLogical 增加VDO卷的逻辑大小。卷必须存在并且必须正在运行。

    growPhysical 增加VDO卷的物理大小。卷必须存在并且必须正在运行。

使用vdo示例

目标: 使用为分区的磁盘,创建名为vdoname的vdo卷,并挂载到/vdodir目录下,并且能开机自定挂载

  1. 查看已经存在的未分区的磁盘

    [root@localhost ~]# lsblk /dev/sda
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sda 8:0 0 80G 0 disk

使用磁盘分区创建vdo卷(也可以使用整个未分区的磁盘创建分区,在分区上创建vdo卷;如果使用这种方法,首先要清除磁盘上的签名)

  1. 创建一个磁盘分区

    [root@localhost ~]# fdisk /dev/sda

    Welcome to fdisk (util-linux 2.32.1).
    Changes will remain in memory only, until you decide to write them.
    Be careful before using the write command.

    Command (m for help): n
    Partition type
    p primary (0 primary, 0 extended, 4 free)
    e extended (container for logical partitions)
    Select (default p): p
    Partition number (1-4, default 1): 1
    First sector (2048-167772159, default 2048):
    Last sector, +sectors or +size{K,M,G,T,P} (2048-167772159, default 167772159): +20G

    Created a new partition 1 of type 'Linux' and of size 20 GiB.

    Command (m for help): w
    The partition table has been altered.
    Calling ioctl() to re-read partition table.
    Syncing disks.

  2. 查看该磁盘分区

    [root@localhost ~]# lsblk
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sda 8:0 0 80G 0 disk
    └─sda1 8:1 0 20G 0 part //这是刚刚创建的磁盘分区
    sr0 11:0 1 7.3G 0 rom /mnt
    nvme0n1 259:0 0 80G 0 disk
    ├─nvme0n1p1 259:1 0 1G 0 part /boot
    └─nvme0n1p2 259:2 0 79G 0 part
    ├─rhel-root 253:0 0 50G 0 lvm /
    ├─rhel-swap 253:1 0 2G 0 lvm [SWAP]
    └─rhel-home 253:2 0 27G 0 lvm /home

  3. /dev/sda1上创建vdo卷(注意:创建的分区不需要格式化)

    [root@localhost ~]# vdo create --name=vdoname --device=/dev/sda1 --vdoLogicalSize=8G
    Creating VDO vdoname
    Starting VDO vdoname
    Starting compression on VDO vdoname
    VDO instance 2 volume is ready at /dev/mapper/vdoname

  4. 查看已经创建的vdo

    [root@localhost ~]# vdo list
    vdoname

或者使用lsblk查看

[root@localhost ~]# lsblk /dev/sda
NAME        MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda           8:0    0  80G  0 disk
└─sda1        8:1    0  20G  0 part
  └─vdoname 253:3    0   8G  0 vdo
  1. 格式化vdo卷,格式化类型xfs

    [root@localhost ~]# mkfs.xfs /dev/mapper/vdoname
    meta-data=/dev/mapper/vdoname isize=512 agcount=4, agsize=524288 blks
    = sectsz=4096 attr=2, projid32bit=1
    = crc=1 finobt=1, sparse=1, rmapbt=0
    = reflink=1
    data = bsize=4096 blocks=2097152, 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

  2. 查看已经创建的vdo卷的属性

    [root@localhost ~]# vdostats --si
    Device Size Used Available Use% Space saving%
    /dev/mapper/vdoname 21.5G 4.3G 17.2G 20% 99%

或者使用blkid查看

[root@localhost ~]# blkid /dev/mapper/vdoname
/dev/mapper/vdoname: UUID="e7bf09bb-1203-4eef-8837-cd802ef11ded" TYPE="xfs"
  1. 挂载vdo卷,挂载目录/vdodir

    [root@localhost ~]# mkdir /vdodir
    [root@localhost ~]# mount /dev/mapper/vdoname /vdodir/
    [root@localhost ~]# df -h
    Filesystem Size Used Avail Use% Mounted on
    devtmpfs 886M 0 886M 0% /dev
    tmpfs 903M 0 903M 0% /dev/shm
    tmpfs 903M 8.6M 894M 1% /run
    tmpfs 903M 0 903M 0% /sys/fs/cgroup
    /dev/mapper/rhel-root 50G 2.2G 48G 5% /
    /dev/mapper/rhel-home 27G 225M 27G 1% /home
    /dev/nvme0n1p1 1014M 171M 844M 17% /boot
    tmpfs 181M 0 181M 0% /run/user/0
    /dev/sr0 7.4G 7.4G 0 100% /mnt
    /dev/mapper/vdoname 8.0G 90M 8.0G 2% /vdodir //已经挂载成功

  2. 查看挂载后的vdo卷的信息

    [root@localhost ~]# vdostats --si
    Device Size Used Available Use% Space saving%
    /dev/mapper/vdoname 21.5G 4.3G 17.2G 20% 98%
    [root@localhost ~]# lsblk /dev/mapper/vdoname
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    vdoname 253:3 0 8G 0 vdo /vdodir

  3. 开机自动挂载vdo

    [root@localhost ~]# echo "/dev/mapper/vdoname /vdodir xfs defaults 0 0" >> /etc/fstab
    [root@localhost ~]# cat /etc/fstab
    #

    /etc/fstab

    Created by anaconda on Wed Aug 26 03:25:38 2020

    #

    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.

    #

    After editing this file, run 'systemctl daemon-reload' to update systemd

    units generated from this file.

    #
    /dev/mapper/rhel-root / xfs defaults 0 0
    UUID=234365dc-2262-452e-9cbb-a6acfde04385 /boot xfs defaults 0 0
    /dev/mapper/rhel-home /home xfs defaults 0 0
    /dev/mapper/rhel-swap swap swap defaults 0 0
    /dev/mapper/vdoname /vdodir xfs defaults 0 0

  4. 删除一个vdo

    [root@localhost ~]# umount /vdodir/ //如果已经挂载,需要先卸载
    [root@localhost ~]# vdo remove --name=vdoname
    Removing VDO vdoname
    Stopping VDO vdoname
    [root@localhost ~]# vdo list

或者使用lsblk查看

[root@localhost ~]# lsblk /dev/sda
NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda      8:0    0  80G  0 disk
└─sda1   8:1    0  20G  0 part

Stratis简介

  • RHEL8.0本地存储管理工具
  • 通过Stratis可以便捷的使用精简配置(Thin Provisioning)、快照(Snapshots)、基于池(Pool-based)的管理和监控等高级存储功能
  • Stratis 基于xfs文件系统格式,创建filesystem后不需要格式化;例如:在pool池中创建file文件系统,则file文件系统的类型已经是xfs格式,不需要在去格式化
  • 守护进程:stratisd

安装Stratisd服务

[root@localhost ~]# yum install -y stratisd stratis-cli
[root@localhost ~]# systemctl enable --now stratisd

使用Stratis的整体操作流程

  1. 选择完好的块设备(磁盘或者分区)
  2. 创建pool
  3. pool中创建文件系统(filesystem

使用Stratis创建pool示例

  1. 创建完好的磁盘分区

    [root@localhost ~]# lsblk /dev/sda
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sda 8:0 0 80G 0 disk
    └─sda1 8:1 0 20G 0 part

  2. 创建pool前查看块设备是否存在签名认证,如果有则必须先清除块设备上的签名认证,才能继续使用

    [root@localhost ~]# fdisk -l /dev/sda
    Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 sectors
    Units: sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disklabel type: dos
    Disk identifier: 0x4b000bc8

Disklabel部分就是块设备的签名认证,需要清除该签名认证

[root@localhost ~]# wipefs -a /dev/sda
/dev/sda: 2 bytes were erased at offset 0x000001fe (dos): 55 aa
/dev/sda: calling ioctl to re-read partition table: Success

清除后,再次查看块设备的签名信息

[root@localhost ~]# fdisk -l /dev/sda
Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
  1. 创建pool池,一般是要求1G以上大小的块设备,才能创建pool

    [root@localhost ~]# stratis pool create pool-one /dev/sda1 //pool-one是pool的名称;/dev/sda1是拿来使用的块设备
    [root@localhost ~]# stratis pool list
    Name Total Physical Size Total Physical Used
    pool-one 20 GiB 52 MiB

  2. 向已经存在的pool池中添加块设备

    [root@localhost ~]# lsblk /dev/sda2
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sda2 8:2 0 20G 0 part
    [root@localhost ~]# stratis pool add-data pool-one /dev/sda2
    [root@localhost ~]# stratis pool list
    Name Total Physical Size Total Physical Used
    pool-one 40 GiB 72 MiB //容量比原来扩大了

  3. 同时将两块块设备添加到同一个pool池中

    [root@localhost ~]# lsblk /dev/sda3 /dev/sda4
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sda3 8:3 0 10G 0 part
    sda4 8:4 0 20G 0 part
    [root@localhost ~]# stratis pool create pool-two /dev/sda3 /dev/sda4
    [root@localhost ~]# stratis pool list
    Name Total Physical Size Total Physical Used
    pool-one 40 GiB 72 MiB
    pool-two 30 GiB 56 MiB

  4. 查看pool-one池和pool-two池中所使用的块设备

    [root@localhost ~]# stratis blockdev list pool-one
    Pool Name Device Node Physical Size State Tier
    pool-one /dev/sda1 20 GiB InUse Data
    pool-one /dev/sda2 20 GiB InUse Data
    [root@localhost ~]# stratis blockdev list pool-two
    Pool Name Device Node Physical Size State Tier
    pool-two /dev/sda3 10 GiB InUse Data
    pool-two /dev/sda4 20 GiB InUse Data

  5. 查看pool-one池和pool-two池中块设备的信息

    [root@localhost ~]# lsblk /dev/sda
    NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    sda 8:0 0 80G 0 disk
    ├─sda1 8:1 0 20G 0 part
    │ └─stratis-1-private-2a5d0ca4266540b889057f37816c7423-physical-originsub 253:3 0 40G 0 stratis
    │ ├─stratis-1-private-2a5d0ca4266540b889057f37816c7423-flex-thinmeta 253:4 0 32M 0 stratis
    │ │ └─stratis-1-private-2a5d0ca4266540b889057f37816c7423-thinpool-pool 253:7 0 40G 0 stratis
    │ ├─stratis-1-private-2a5d0ca4266540b889057f37816c7423-flex-thindata 253:5 0 40G 0 stratis
    │ │ └─stratis-1-private-2a5d0ca4266540b889057f37816c7423-thinpool-pool 253:7 0 40G 0 stratis
    │ └─stratis-1-private-2a5d0ca4266540b889057f37816c7423-flex-mdv 253:6 0 16M 0 stratis
    ├─sda2 8:2 0 20G 0 part
    │ └─stratis-1-private-2a5d0ca4266540b889057f37816c7423-physical-originsub 253:3 0 40G 0 stratis
    │ ├─stratis-1-private-2a5d0ca4266540b889057f37816c7423-flex-thinmeta 253:4 0 32M 0 stratis
    │ │ └─stratis-1-private-2a5d0ca4266540b889057f37816c7423-thinpool-pool 253:7 0 40G 0 stratis
    │ ├─stratis-1-private-2a5d0ca4266540b889057f37816c7423-flex-thindata 253:5 0 40G 0 stratis
    │ │ └─stratis-1-private-2a5d0ca4266540b889057f37816c7423-thinpool-pool 253:7 0 40G 0 stratis
    │ └─stratis-1-private-2a5d0ca4266540b889057f37816c7423-flex-mdv 253:6 0 16M 0 stratis
    ├─sda3 8:3 0 10G 0 part
    │ └─stratis-1-private-31db6de0edb64a3f8721a33f55922b69-physical-originsub 253:8 0 30G 0 stratis
    │ ├─stratis-1-private-31db6de0edb64a3f8721a33f55922b69-flex-thinmeta 253:9 0 16M 0 stratis
    │ │ └─stratis-1-private-31db6de0edb64a3f8721a33f55922b69-thinpool-pool 253:12 0 30G 0 stratis
    │ ├─stratis-1-private-31db6de0edb64a3f8721a33f55922b69-flex-thindata 253:10 0 30G 0 stratis
    │ │ └─stratis-1-private-31db6de0edb64a3f8721a33f55922b69-thinpool-pool 253:12 0 30G 0 stratis
    │ └─stratis-1-private-31db6de0edb64a3f8721a33f55922b69-flex-mdv 253:11 0 16M 0 stratis
    └─sda4 8:4 0 20G 0 part
    └─stratis-1-private-31db6de0edb64a3f8721a33f55922b69-physical-originsub 253:8 0 30G 0 stratis
    ├─stratis-1-private-31db6de0edb64a3f8721a33f55922b69-flex-thinmeta 253:9 0 16M 0 stratis
    │ └─stratis-1-private-31db6de0edb64a3f8721a33f55922b69-thinpool-pool 253:12 0 30G 0 stratis
    ├─stratis-1-private-31db6de0edb64a3f8721a33f55922b69-flex-thindata 253:10 0 30G 0 stratis
    │ └─stratis-1-private-31db6de0edb64a3f8721a33f55922b69-thinpool-pool 253:12 0 30G 0 stratis
    └─stratis-1-private-31db6de0edb64a3f8721a33f55922b69-flex-mdv 253:11 0 16M 0 stratis

使用Stratis创建filesystem示例

  1. pool-one池中创建filesystem(一次只能创建一个filesystem

    [root@localhost ~]# stratis filesystem create pool-one file-one //pool-one是pool的名称;file-one是filesystem的名称
    [root@localhost ~]# stratis filesystem list //列出已经拥有的filesystem
    Pool Name Name Used Created Device UUID
    pool-one file-one 546 MiB Sep 20 2020 20:33 /stratis/pool-one/file-one deeb42ce571542cab33afcbfece6dd0a

  2. 查看指定pool池中拥有的filesystem

    [root@localhost ~]# stratis filesystem list pool-one
    Pool Name Name Used Created Device UUID
    pool-one file-one 546 MiB Sep 20 2020 20:33 /stratis/pool-one/file-one deeb42ce571542cab33afcbfece6dd0a

  3. 挂载filesystem,挂载点:/fsdir

    [root@localhost ~]# mkdir /fsdir
    [root@localhost ~]# mount /stratis/pool-one/file-one /fsdir/
    [root@localhost ~]# df -h
    Filesystem Size Used Avail Use% Mounted on
    devtmpfs 886M 0 886M 0% /dev
    tmpfs 903M 0 903M 0% /dev/shm
    tmpfs 903M 8.7M 894M 1% /run
    tmpfs 903M 0 903M 0% /sys/fs/cgroup
    /dev/mapper/rhel-root 50G 1.7G 49G 4% /
    /dev/nvme0n1p1 1014M 173M 842M 17% /boot
    /dev/mapper/rhel-home 27G 225M 27G 1% /home
    tmpfs 181M 0 181M 0% /run/user/0
    /dev/sr0 7.4G 7.4G 0 100% /mnt
    /dev/mapper/stratis-1-2a5d0ca4266540b889057f37816c7423-thin-fs-deeb42ce571542cab33afcbfece6dd0a 1.0T 7.2G 1017G 1% /fsdir

  4. 写入到/etc/fstab配置文件中,建议使用UUID,因为使用name的话,每次更新name,都要对配置文件进行刷新

    [root@localhost ~]# blkid /stratis/pool-one/file-one
    /stratis/pool-one/file-one: UUID="deeb42ce-5715-42ca-b33a-fcbfece6dd0a" TYPE="xfs"
    [root@localhost ~]# echo "UUID=deeb42ce-5715-42ca-b33a-fcbfece6dd0a /fsdir xfs defaults 0 0" >> /etc/fstab
    [root@localhost ~]# tail -3 /etc/fstab
    /dev/mapper/rhel-home /home xfs defaults 0 0
    /dev/mapper/rhel-swap swap swap defaults 0 0
    UUID=deeb42ce-5715-42ca-b33a-fcbfece6dd0a /fsdir xfs defaults 0 0

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章