GlusterFs教程第13章:GlusterFs存储卷管理(2)


概述

相信上一篇大家学习得意犹未尽,本文接上一篇继续学习GlusterFs存储卷管理哦!

本节介绍如何执行常见的GlusterFS存储卷管理操作,包括以下内容:

  • 更换存储磁盘块

更换存储磁盘块

要替换仅分发卷上的磁盘块,请添加新的磁盘块,然后删除要替换的磁盘块即可。

此操作会触发重新平衡操作,该操作将从已移除的磁盘块中移动数据到其他模块中。

注意:replace-brick 命令替换磁盘块,只能在分布式复制或纯复制存储卷模式的GlusterFS中使用。


删除磁盘块:Server1:/home/gfs/r2_1,并添加Server1:/home/gfs/r2_2的步骤如下:

  • 以下为存储卷初始化配置信息:
Volume Name: r2
Type: Distribute
Volume ID: 25b4e313-7b36-445d-b524-c3daebb91188
Status: Started
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: Server1:/home/gfs/r2_0
Brick2: Server1:/home/gfs/r2_1
  • 以下是已经挂载的文件:
# ls

1  10  2  3  4  5  6  7  8  9
  • 添加新的砖块-Server1:/home/gfs/r2_2:
# gluster volume add-brick r2 Server1:/home/gfs/r2_2

volume add-brick: success
  • 使用以下命令启动remove-brick:
# gluster volume remove-brick r2 Server1:/home/gfs/r2_1 start

volume remove-brick start: success
ID: fba0a488-21a4-42b7-8a41-b27ebaa8e5f4
  • 等待直到磁盘块移除状态指示完成
# gluster volume remove-brick r2 Server1:/home/gfs/r2_1 status

 Node Rebalanced-files          size       scanned      failures       skipped               status   run time in secs
---------      -----------   -----------   -----------   -----------   -----------         ------------     --------------
localhost                5       20Bytes            15             0             0            completed               0.00
  • 现在我们可以安全地删除旧磁盘块,因此提交更改:
# gluster volume remove-brick r2 Server1:/home/gfs/r2_1 commit

Removing brick(s) can result in data loss. Do you want to Continue? (y/n) y
volume remove-brick commit: success
  • 以下是是新的存储卷配置信息:
Volume Name: r2
Type: Distribute
Volume ID: 25b4e313-7b36-445d-b524-c3daebb91188
Status: Started
Number of Bricks: 2
Transport-type: tcp
Bricks:
Brick1: Server1:/home/gfs/r2_0
Brick2: Server1:/home/gfs/r2_2
  • 检查挂载的内容:
# ls
1  10  2  3  4  5  6  7  8  9

在复制/分布式复制卷中替换砖块

此部分将描述如何用存储卷副本2中的卷r2中的磁盘块:Server1:/home/gfs/r2_0替换为:Server1:/home/gfs/r2_5

    Volume Name: r2
    Type: Distributed-Replicate
    Volume ID: 24a0437a-daa0-4044-8acf-7aa82efd76fd
    Status: Started
    Number of Bricks: 2 x 2 = 4
    Transport-type: tcp
    Bricks:
    Brick1: Server1:/home/gfs/r2_0
    Brick2: Server2:/home/gfs/r2_1
    Brick3: Server1:/home/gfs/r2_2
    Brick4: Server2:/home/gfs/r2_3

步骤如下:

  • 确保新的磁盘块Server1:/home/gfs/r2_5中没有数据

  • 检查所有磁盘块的运行状态, 要更换的磁盘块如果没有正常运行也可以

  • 如果没有正常运行的,请将其移除

通过 gluster volume status 命令获取磁盘块的PID

# gluster volume status

Status of volume: r2
Gluster process                        Port    Online    Pid
------------------------------------------------------------------------------
Brick Server1:/home/gfs/r2_0            49152    Y    5342
Brick Server2:/home/gfs/r2_1            49153    Y    5354
Brick Server1:/home/gfs/r2_2            49154    Y    5365
Brick Server2:/home/gfs/r2_3            49155    Y    5376

登录到磁盘块所在的服务器,杀掉这个进程

# kill -15 5342

确认该磁盘块不再运行并且其他磁盘块运行正常

# gluster volume status

Status of volume: r2
Gluster process                        Port    Online    Pid
------------------------------------------------------------------------------
Brick Server1:/home/gfs/r2_0            N/A      N    5342 <<---- brick is not running, others are running fine.
Brick Server2:/home/gfs/r2_1            49153    Y    5354
Brick Server1:/home/gfs/r2_2            49154    Y    5365
Brick Server2:/home/gfs/r2_3            49155    Y    5376
  • 我们使用gluster存储卷的备份路径(在此示例中: /mnt/r2 )设置元数据,以便将数据同步到新的磁盘块(在这种情况下,它是从Server1:/home/gfs/r2_1到Server1:/home/gfs/r2_5)

在安装点上创建一个不存在的目录。 然后删除该目录,通过执行setfattr命令对元数据更改日志执行相同的操作。 此操作标记了挂起的变更日志,该日志将告诉自我修复damon/mount模块,从/home/gfs/r2_1到/home/gfs/r2_5执行自我修复的操作。

mkdir /mnt/r2/<name-of-nonexistent-dir>
rmdir /mnt/r2/<name-of-nonexistent-dir>
setfattr -n trusted.non-existent-key -v abc /mnt/r2
setfattr -x trusted.non-existent-key  /mnt/r2

检查要替换的磁盘块副本上是否存在挂起的xattrs:

getfattr -d -m. -e hex /home/gfs/r2_1
# file: home/gfs/r2_1
security.selinux=0x756e636f6e66696e65645f753a6f626a6563745f723a66696c655f743a733000
trusted.afr.r2-client-0=0x000000000000000300000002 <<---- xattrs are marked from source brick Server2:/home/gfs/r2_1
trusted.afr.r2-client-1=0x000000000000000000000000
trusted.gfid=0x00000000000000000000000000000001
trusted.glusterfs.dht=0x0000000100000000000000007ffffffe
trusted.glusterfs.volume-id=0xde822e25ebd049ea83bfaa3c4be2b440

批量恢复信息将显示'/'需要恢复。(根据工作量,可能会有更多的目录。但是'/'必须存在)

    # gluster volume heal r2 info
    Brick Server1:/home/gfs/r2_0
    Status: Transport endpoint is not connected

    Brick Server2:/home/gfs/r2_1
    /
    Number of entries: 1

    Brick Server1:/home/gfs/r2_2
    Number of entries: 0

    Brick Server2:/home/gfs/r2_3
    Number of entries: 0

commit force 选项替换存储块。 请注意,不支持replace-brick命令的其他操作

执行 replace-brick 命令

# gluster volume replace-brick r2 Server1:/home/gfs/r2_0 Server1:/home/gfs/r2_5 commit force
volume replace-brick: success: replace-brick commit successful

检查新的磁盘块是否在线

# gluster volume status
Status of volume: r2
Gluster process                        Port    Online    Pid
------------------------------------------------------------------------------
Brick Server1:/home/gfs/r2_5            49156    Y    5731 <<<---- new brick is online
Brick Server2:/home/gfs/r2_1            49153    Y    5354
Brick Server1:/home/gfs/r2_2            49154    Y    5365
Brick Server2:/home/gfs/r2_3            49155    Y    5376

用户可以使用以下命令查看自我修复的进度:gluster volume heal [volname] info , 一旦自我修复完成,更改日志将被删除。

# getfattr -d -m. -e hex /home/gfs/r2_1
getfattr: Removing leading '/' from absolute path names
# file: home/gfs/r2_1
security.selinux=0x756e636f6e66696e65645f753a6f626a6563745f723a66696c655f743a733000
trusted.afr.r2-client-0=0x000000000000000000000000 <<---- Pending changelogs are cleared.
trusted.afr.r2-client-1=0x000000000000000000000000
trusted.gfid=0x00000000000000000000000000000001
trusted.glusterfs.dht=0x0000000100000000000000007ffffffe
trusted.glusterfs.volume-id=0xde822e25ebd049ea83bfaa3c4be2b440

# gluster volume heal <VOLNAME> info 将显示自我修复已经完成

# gluster volume heal r2 info
Brick Server1:/home/gfs/r2_5
Number of entries: 0

Brick Server2:/home/gfs/r2_1
Number of entries: 0

Brick Server1:/home/gfs/r2_2
Number of entries: 0

Brick Server2:/home/gfs/r2_3
Number of entries: 0

致读者

更多GlusterFs存储卷管理操作精彩内容,见下一章节!