Red Hat Training

A Red Hat training course is available for RHEL 8

11.3. 为逻辑卷启用 dm-cache 缓存

这个过程使用 dm-cache 方法启用逻辑卷中常用数据缓存。

先决条件

  • 您希望使用 dm-cache 加快的逻辑卷存在于系统中。
  • 包含较慢逻辑卷的卷组还包含在快速块设备中未使用的物理卷。

流程

  1. 在快速设备中创建 cachevol 卷:

    # lvcreate --size cachevol-size --name <fastvol> <vg> </dev/fast-pv>

    替换以下值:

    cachevol-size
    cachevol 卷的大小,如 5G
    fastvol
    cachevol 卷的名称
    vg
    卷组名称
    /dev/fast-pv

    快速块设备的路径,如 /dev/sdf

    例 11.1. 创建一个 cachevol

    # lvcreate --size 5G --name fastvol vg /dev/sdf
    Logical volume "fastvol" created.
  2. cachevol 卷附加到主逻辑卷以开始缓存:

    # lvconvert --type cache --cachevol <fastvol> <vg/main-lv>

    替换以下值:

    fastvol
    cachevol 卷的名称
    vg
    卷组名称
    main-lv

    较慢的逻辑卷名称

    例 11.2. 将 cachevol 卷附加到主 LV

    # lvconvert --type cache --cachevol fastvol vg/main-lv
    Erase all existing data on vg/fastvol? [y/n]: y
    Logical volume vg/main-lv is now cached.

验证步骤

  • 验证新创建的逻辑卷是否启用了 dm-cache

    # lvs --all --options +devices <vg>
    
    LV              Pool           Type   Devices
    main-lv         [fastvol_cvol] cache  main-lv_corig(0)
    [fastvol_cvol]                 linear /dev/fast-pv
    [main-lv_corig]                linear /dev/slow-pv

其他资源

  • lvmcache (7) 手册页