Red Hat Training

A Red Hat training course is available for Red Hat Enterprise Linux

16.2. 常见 SSM 任务

以下小节描述了常见的 SSM 任务。

16.2.1. 安装 SSM

要安装 SSM,请使用以下命令:
# yum install system-storage-manager
只有在安装了支持的软件包时,才会启用几个后端:
  • LVM 后端需要 lvm2 软件包。
  • Btrfs 后端需要 btrfs-progs 软件包。
  • Crypt 后端需要 device-mappercryptsetup 软件包。

16.2.2. 显示有关所有删除的设备的信息

使用 list 命令显示所有检测到的设备、池、卷和快照的信息。没有选项的 ssm list 命令会显示以下输出:
# ssm list
----------------------------------------------------------
Device        Free      Used      Total  Pool  Mount point
----------------------------------------------------------
/dev/sda                        2.00 GB        PARTITIONED
/dev/sda1                      47.83 MB        /test
/dev/vda                       15.00 GB        PARTITIONED
/dev/vda1                     500.00 MB        /boot
/dev/vda2  0.00 KB  14.51 GB   14.51 GB  rhel
----------------------------------------------------------
------------------------------------------------
Pool  Type  Devices     Free      Used     Total
------------------------------------------------
rhel  lvm   1        0.00 KB  14.51 GB  14.51 GB
------------------------------------------------
---------------------------------------------------------------------------------
Volume          Pool  Volume size  FS     FS size       Free  Type    Mount point
---------------------------------------------------------------------------------
/dev/rhel/root  rhel     13.53 GB  xfs   13.52 GB    9.64 GB  linear  /
/dev/rhel/swap  rhel   1000.00 MB                             linear
/dev/sda1                47.83 MB  xfs   44.50 MB   44.41 MB  part    /test
/dev/vda1               500.00 MB  xfs  496.67 MB  403.56 MB  part    /boot
---------------------------------------------------------------------------------
通过使用参数来指定应显示的内容,可以进一步缩小此显示范围。可用选项列表可以通过 ssm list --help 命令找到。
注意
根据给定的参数,SSM 可能无法显示所有内容。
  • 运行 devicesdev 参数会省略一些设备。例如,CDROMS 和 DM/MD 设备被有意隐藏,因为它们被列为卷。
  • 有些后端不支持快照,且无法区分快照和常规卷。在其中一个后端上运行 snapshot 参数会导致 SSM 尝试识别卷名称来识别快照。如果 SSM 正则表达式与快照模式不匹配,则不能识别快照。
  • 除了主 Btrfs 卷(文件系统本身)外,任何卸载的 Btrfs 卷都不会显示。

16.2.3. 创建新池、逻辑卷和文件系统

在本节中,使用默认名称创建一个新池,其具有设备 /dev/vdb/dev/vdc、1G 的逻辑卷和 XFS 文件系统。
要创建此场景的命令是 ssm create --fs xfs -s 1G /dev/vdb /dev/vdc。使用以下选项:
  • --fs 选项指定所需的文件系统类型。当前支持的文件系统类型有:
    • ext3
    • ext4
    • xfs
    • btrfs
  • -s 指定逻辑卷的大小。支持以下后缀来定义单元:
    • kk 表示 KB
    • Mm 用于 MB
    • GG 表示千兆字节
    • Tt for TB
    • Pp for PBs
    • ee 用于 exabytes
  • Additionaly 使用 -s 选项,新大小可指定为百分比。查看示例:
    • 总池大小达到 10%
    • 空闲池空间的 10%FREE
    • 10%USED 是已用池空间的 10%
列出的两个设备 /dev/vdb/dev/vdc 是您要创建的两个设备。
# ssm create --fs xfs -s 1G /dev/vdb /dev/vdc
  Physical volume "/dev/vdb" successfully created
  Physical volume "/dev/vdc" successfully created
  Volume group "lvm_pool" successfully created
  Logical volume "lvol001" created
ssm 命令 还有另外两个可能有用的选项。第一个是 -p pool 命令。这将指定要在其上创建卷的池。如果尚不存在,则 SSM 会创建它。在给定示例中省略了,这会导致 SSM 使用默认名称 lvm_pool。但是,要使用特定名称来适应任何现有命名约定,应使用 -p 选项。
第二个有用选项是 -n name 命令。这会命名新创建的逻辑卷。与 -p 一样,需要使用特定名称来适合任何现有命名约定。
以下是使用这两个选项的示例:
# ssm create --fs xfs -p new_pool -n XFS_Volume /dev/vdd
  Volume group "new_pool" successfully created
  Logical volume "XFS_Volume" created
SSM 现在创建了两个物理卷、一个池和一个逻辑卷,且只有一个命令。

16.2.4. 检查文件系统的一致性

ssm check 命令检查卷上的文件系统一致性。可以指定多个卷来检查。如果卷中没有文件系统,则会跳过该卷。
要检查卷 lvol001 中的所有设备,请运行命令 ssm check /dev/lvm_pool/lvol001
# ssm check /dev/lvm_pool/lvol001
Checking xfs file system on '/dev/mapper/lvm_pool-lvol001'.
Phase 1 - find and verify superblock...
Phase 2 - using internal log
        - scan filesystem freespace and inode maps...
        - found root inode chunk
Phase 3 - for each AG...
        - scan (but don't clear) agi unlinked lists...
        - process known inodes and perform inode discovery...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
        - agno = 4
        - agno = 5
        - agno = 6
        - 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
        - agno = 4
        - agno = 5
        - agno = 6
No modify flag set, skipping phase 5
Phase 6 - check inode connectivity...
        - traversing filesystem ...
        - traversal finished ...
        - moving disconnected inodes to lost+found ...
Phase 7 - verify link counts...
No modify flag set, skipping filesystem flush and exiting.

16.2.5. 增加卷的大小

ssm resize 命令更改指定卷和文件系统的大小。如果没有文件系统,则仅调整卷本身的大小。
在本例中,我们目前在 /dev/vdb 上有一个逻辑卷,名为 lvol001
# ssm list
-----------------------------------------------------------------
Device          Free       Used      Total  Pool      Mount point
-----------------------------------------------------------------
/dev/vda                          15.00 GB            PARTITIONED
/dev/vda1                        500.00 MB            /boot
/dev/vda2    0.00 KB   14.51 GB   14.51 GB  rhel
/dev/vdb   120.00 MB  900.00 MB    1.00 GB  lvm_pool
/dev/vdc                           1.00 GB
-----------------------------------------------------------------
---------------------------------------------------------
Pool      Type  Devices       Free       Used       Total
---------------------------------------------------------
lvm_pool  lvm   1        120.00 MB  900.00 MB  1020.00 MB
rhel      lvm   1          0.00 KB   14.51 GB    14.51 GB
---------------------------------------------------------
--------------------------------------------------------------------------------------------
Volume                 Pool      Volume size  FS     FS size       Free  Type    Mount point
--------------------------------------------------------------------------------------------
/dev/rhel/root         rhel         13.53 GB  xfs   13.52 GB    9.64 GB  linear  /
/dev/rhel/swap         rhel       1000.00 MB                             linear
/dev/lvm_pool/lvol001  lvm_pool    900.00 MB  xfs  896.67 MB  896.54 MB  linear
/dev/vda1                          500.00 MB  xfs  496.67 MB  403.56 MB  part    /boot
--------------------------------------------------------------------------------------------
逻辑卷需要被另外 500MB 增加。要做到这一点,我们需要在池中添加额外的设备:
~]# ssm resize -s +500M /dev/lvm_pool/lvol001 /dev/vdc
  Physical volume "/dev/vdc" successfully created
  Volume group "lvm_pool" successfully extended
Phase 1 - find and verify superblock...
Phase 2 - using internal log
        - scan filesystem freespace and inode maps...
        - found root inode chunk
Phase 3 - for each AG...
        - scan (but don't 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
No modify flag set, skipping phase 5
Phase 6 - check inode connectivity...
        - traversing filesystem ...
        - traversal finished ...
        - moving disconnected inodes to lost+found ...
Phase 7 - verify link counts...
No modify flag set, skipping filesystem flush and exiting.
  Extending logical volume lvol001 to 1.37 GiB
  Logical volume lvol001 successfully resized
meta-data=/dev/mapper/lvm_pool-lvol001 isize=256    agcount=4, agsize=57600 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=230400, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=853, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 230400 to 358400

SSM 在设备上运行检查,然后根据指定数量扩展卷。这可以通过 ssm list 命令验证。
# ssm list
------------------------------------------------------------------
Device          Free        Used      Total  Pool      Mount point
------------------------------------------------------------------
/dev/vda                           15.00 GB            PARTITIONED
/dev/vda1                         500.00 MB            /boot
/dev/vda2    0.00 KB    14.51 GB   14.51 GB  rhel
/dev/vdb     0.00 KB  1020.00 MB    1.00 GB  lvm_pool
/dev/vdc   640.00 MB   380.00 MB    1.00 GB  lvm_pool
------------------------------------------------------------------
------------------------------------------------------
Pool      Type  Devices       Free      Used     Total
------------------------------------------------------
lvm_pool  lvm   2        640.00 MB   1.37 GB   1.99 GB
rhel      lvm   1          0.00 KB  14.51 GB  14.51 GB
------------------------------------------------------
----------------------------------------------------------------------------------------------
Volume                 Pool      Volume size  FS      FS size        Free  Type    Mount point
----------------------------------------------------------------------------------------------
/dev/rhel/root         rhel         13.53 GB  xfs    13.52 GB     9.64 GB  linear  /
/dev/rhel/swap         rhel       1000.00 MB                               linear
/dev/lvm_pool/lvol001  lvm_pool      1.37 GB  xfs     1.36 GB     1.36 GB  linear
/dev/vda1                          500.00 MB  xfs   496.67 MB   403.56 MB  part    /boot
----------------------------------------------------------------------------------------------
注意
只能缩小 LVM 卷的大小 ; 不支持其他卷类型。这可以通过使用 - 而不是 + 完成。例如:要将 LVM 卷的大小减小到 50M,命令将是:
# ssm resize -s-50M /dev/lvm_pool/lvol002
  Rounding size to boundary between physical extents: 972.00 MiB
  WARNING: Reducing active logical volume to 972.00 MiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lvol002? [y/n]: y
  Reducing logical volume lvol002 to 972.00 MiB
  Logical volume lvol002 successfully resized
如果没有 +-,则该值会取为绝对值。

16.2.6. Snapshot

要为现有卷执行快照,请使用 ssm snapshot 命令。
注意
如果卷所属的后端不支持快照,则此操作会失败。
要为 lvol001 创建快照,请使用以下命令:
# ssm snapshot /dev/lvm_pool/lvol001
  Logical volume "snap20150519T130900" created
要验证这一点,请使用 ssm 列表,并记下额外的快照部分。
# ssm list
----------------------------------------------------------------
Device        Free        Used      Total  Pool      Mount point
----------------------------------------------------------------
/dev/vda                         15.00 GB            PARTITIONED
/dev/vda1                       500.00 MB            /boot
/dev/vda2  0.00 KB    14.51 GB   14.51 GB  rhel
/dev/vdb   0.00 KB  1020.00 MB    1.00 GB  lvm_pool
/dev/vdc                          1.00 GB
----------------------------------------------------------------
--------------------------------------------------------
Pool      Type  Devices     Free        Used       Total
--------------------------------------------------------
lvm_pool  lvm   1        0.00 KB  1020.00 MB  1020.00 MB
rhel      lvm   1        0.00 KB    14.51 GB    14.51 GB
--------------------------------------------------------
----------------------------------------------------------------------------------------------
Volume                 Pool      Volume size  FS      FS size        Free  Type    Mount point
----------------------------------------------------------------------------------------------
/dev/rhel/root         rhel         13.53 GB  xfs    13.52 GB     9.64 GB  linear  /
/dev/rhel/swap         rhel       1000.00 MB                               linear
/dev/lvm_pool/lvol001  lvm_pool    900.00 MB  xfs   896.67 MB   896.54 MB  linear
/dev/vda1                          500.00 MB  xfs   496.67 MB   403.56 MB  part    /boot
----------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------
Snapshot                           Origin   Pool      Volume size     Size  Type
----------------------------------------------------------------------------------
/dev/lvm_pool/snap20150519T130900  lvol001  lvm_pool    120.00 MB  0.00 KB  linear
----------------------------------------------------------------------------------

16.2.7. 删除项

ssm remove 用于删除项目,可以是设备、池或卷。
注意
如果在删除时池使用了设备,它将会失败。这可以通过使用 -f 参数强制使用。
如果卷在删除时挂载,它将会失败。与设备不同,无法使用 -f 参数强制使用它。
要删除 lvm_pool 及其其中的所有内容,请使用以下命令:
# ssm remove lvm_pool
Do you really want to remove volume group "lvm_pool" containing 2 logical volumes? [y/n]: y
Do you really want to remove active logical volume snap20150519T130900? [y/n]: y
  Logical volume "snap20150519T130900" successfully removed
Do you really want to remove active logical volume lvol001? [y/n]: y
  Logical volume "lvol001" successfully removed
  Volume group "lvm_pool" successfully removed