gs_sdr

背景信息

从openGauss 3.1.0版本开始,openGauss提供了gs_sdr工具,在不借助额外存储介质的情况下实现跨region的异地容灾。提供流式容灾搭建,容灾升主,计划内主备切换,容灾解除、容灾状态监控功能、显示帮助信息和显示版本号信息等功能。

前提条件

需以操作系统用户omm执行gs_sdr命令。

语法

  • 容灾搭建

    1. gs_sdr -t start -m [primary|disaster_standby] [-U DR_USERNAME] [-W DR_PASSWORD] [-X XMLFILE] [--json JSONFILE] [--time-out=SECS] [-l LOGFILE]
  • 容灾升主

    1. gs_sdr -t failover [-l LOGFILE]
  • 计划内主备切换

    1. gs_sdr -t switchover -m [primary|disaster_standby] [--time-out=SECS] [-l LOGFILE]
  • 容灾解除

    1. gs_sdr -t stop [-X XMLFILE] [--json JSONFILE] [-l LOGFILE]
  • 容灾状态监控

    1. gs_sdr -t query [-l LOGFILE]

参数说明

gs_sdr参数可以分为如下几类:

  • 通用参数:

    • -t

      gs_sdr命令的类型。

      取值范围:start、failover、switchover、stop、query。

    • -l

      指定日志文件及存放路径。

      默认值:$GAUSSLOG/om/gs_sdr-YYYY-MM-DD_hhmmss.log

    • -?, –help

      显示帮助信息。

    • -V, –version

      显示版本号信息。

  • 搭建容灾参数:

    • -m

      期望该集群在容灾关系中成为的角色

      取值范围:primary(主集群)或disaster_standby(灾备集群)

    • -U

      具有流复制权限的容灾用户名称

    • -W

      容灾用户密码

      gs_sdr - 图1 说明:

      1. 搭建容灾关系前,主集群需创建容灾用户,用于容灾鉴权,主备集群必须使用相同的容灾用户名和密码,一次容灾搭建后,该用户密码不可修改。若需修改容灾用户名与密码,需要解除容灾,使用新的容灾用户重新进行搭建。容灾用户密码中不可包含以下字符“| ;&$<>`‘“{}()[]~*?!\n空白”。
      2. -U、-W 参数如果搭建命令行未带,则在搭建过程中支持交互式输入。
    • -X

      集群安装时的xml,xml中也可以配置容灾信息用于容灾搭建,即在安装xml的基础上扩展三个字段(“localStreamIpmap1”、“remoteStreamIpmap1”、“remotedataPortBase”)

      新增字段的配置方式如下,加粗字体内容为示例。每行信息均有注释进行说明。

      1. <!-- 每台服务器上的节点部署信息 -->
      2. <DEVICELIST>
      3. <DEVICE sn="pekpomdev00038">
      4. <!-- 当前主机上需要部署的主DN个数 -->
      5. <PARAM name="dataNum" value="1"/>
      6. <!-- 主DN的基础端口号 -->
      7. <PARAM name="dataPortBase" value="26000"/>
      8. <!-- 本集群dn分片各节点用于SSH可信通道的IP与流复制的IP映射关系 -->
      9. <PARAM name="localStreamIpmap1" value="(10.244.44.216,172.31.12.58),(10.244.45.120,172.31.0.91)"/>
      10. <!-- 对端集群dn分片各节点用于SSH可信通道的IP与流复制的IP映射关系 -->
      11. <PARAM name="remoteStreamIpmap1" value="(10.244.45.144,172.31.2.200),(10.244.45.40,172.31.0.38),(10.244.46.138,172.31.11.145),(10.244.48.60,172.31.9.37),(10.244.47.240,172.31.11.125)"/>
      12. <!-- 对端集群的主dn端口号 -->
      13. <PARAM name="remotedataPortBase" value="26000"/>
      14. </DEVICE>
    • –json

      带有容灾信息的json文件。

      json文件的配置方式如下,加粗字体内容为示例。

      1. {"remoteClusterConf": {"port": 26000, "shards": [[{"ip": "10.244.45.144", "dataIp": "172.31.2.200"}, {"ip": "10.244.45.40", "dataIp": "172.31.0.38"}, {"ip": "10.244.46.138", "dataIp": "172.31.11.145"}, {"ip": "10.244.48.60", "dataIp": "172.31.9.37"}, {"ip": "10.244.47.240", "dataIp": "172.31.11.125"}]]}, "localClusterConf": {"port": 26000, "shards": [[{"ip": "10.244.44.216", "dataIp": "172.31.12.58"}, {"ip": "10.244.45.120", "dataIp": "172.31.0.91"}]]}}
      2. 参数说明:
      3. # remoteClusterConf:对端集群的dn分片信息。其中port为对端集群主dn的端口,{"ip": "10.244.45.144", "dtaIp": "172.31.2.200"}为对端集群dn分片上各节点用于SSH可信通道的IP与流复制的IP映射关系。
      4. # localClusterConf:本集群的dn分片信息。其中port为本集群主dn的端口,{"ip": "10.244.44.216", "dtaIp": "172.31.12.58"}为本集群dn分片上各节点用于SSH可信通道的IP与流复制的IP映射关系。

      gs_sdr - 图2 说明:

      -X与–json参数支持二选一方式进行配置容灾信息,如果命令行中两个参数全部下发,则以json为准。

    • –time-out=SECS

      指定超时时间,主集群会等待备集群连接的超时时间,超时则判定失败,om脚本自动退出。单位:s。

      取值范围:正整数,建议值1200。

      默认值:1200

  • 容灾升主参数:

  • 容灾解除参数:

    • -X

      集群安装时的xml,需要额外配置容灾信息,即扩展三个字段(“localStreamIpmap1”、“remoteStreamIpmap1”、“remotedataPortBase”)

    • –json

      带有本端及对端容灾信息的json文件。

      gs_sdr - 图3 说明:

      -X、–json的配置方式请参考本节容灾搭建参数配置。

  • 容灾查询参数:

    容灾状态查询结果说明如下:

项目

含义

说明

备注

hadr_cluster_stat

流式容灾中数据库实例状态

normal

标识该数据库实例未参与流式容灾

-

full_backup

主数据库实例数据全量复制中

流式容灾中仅主数据库实例有此状态

archive

主数据库实例日志流式复制中

流式容灾中仅主数据库实例有此状态

backup_fail

主数据库实例数据全量复制失败

流式容灾中仅主数据库实例有此状态

archive_fail

主数据库实例日志流式复制失败

流式容灾中仅主数据库实例有此状态

switchover

计划内主备倒换中

流式容灾中主备数据库实例皆有此状态

restore

灾备数据库实例数据全量恢复中

流式容灾中仅灾备数据库实例有此状态

restore_fail

灾备数据库实例全备恢复失败

流式容灾中仅灾备数据库实例有此状态

recovery

灾备数据库实例日志流式复制中

流式容灾中仅灾备数据库实例有此状态

recovery_fail

灾备数据库实例日志流式复制失败

流式容灾中仅灾备数据库实例有此状态

promote

灾备数据库实例升主中

流式容灾中仅灾备数据库实例有此状态

promote_fail

灾备数据库实例升主失败

流式容灾中仅灾备数据库实例有此状态

hadr_switchover_stat

流式容灾主备数据库实例计划内倒换进度展示

百分比

倒换进度展示

-

hadr_failover_stat

流式容灾灾备数据库实例升主进度展示

百分比

倒换进度展示

-

RTO

此时发生灾难,数据恢复所需要的时长

数据库实例停机,网络异常等导致流式容灾中断

流式容灾中仅主数据库实例可查

非空

数据恢复所需要的时长,单位s

RPO

此时发生灾难,数据库实例丢失的数据时长

数据库实例停机,网络异常等导致流式容灾中断

流式容灾中仅主数据库实例可查

非空

数据库实例可能丢失的数据时长,单位s

示例

  • 主集群搭建容灾关系。

    1. gs_sdr -t start -m primary -X /opt/install_streaming_primary_cluster.xml --time-out=1200 -U 'hadr_user' -W 'opengauss@123'
    2. --------------------------------------------------------------------------------
    3. Streaming disaster recovery start 2b9bc268d8a111ecb679fa163e2f2d28
    4. --------------------------------------------------------------------------------
    5. Start create streaming disaster relationship ...
    6. Got step:[-1] for action:[start].
    7. Start first step of streaming start.
    8. Start common config step of streaming start.
    9. Start generate hadr key files.
    10. Streaming key files already exist.
    11. Finished generate and distribute hadr key files.
    12. Start encrypt hadr user info.
    13. Successfully encrypt hadr user info.
    14. Start save hadr user info into database.
    15. Successfully save hadr user info into database.
    16. Start update pg_hba config.
    17. Successfully update pg_hba config.
    18. Start second step of streaming start.
    19. Successfully check cluster status is: Normal
    20. Successfully check instance status.
    21. Successfully check cm_ctl is available.
    22. Successfully check cluster is not under upgrade opts.
    23. Start checking disaster recovery user.
    24. Successfully check disaster recovery user.
    25. Start prepare secure files.
    26. Start copy hadr user key files.
    27. Successfully copy secure files.
    28. Start fourth step of streaming start.
    29. Starting reload wal_keep_segments value: 16384.
    30. Successfully reload wal_keep_segments value: 16384.
    31. Start fifth step of streaming start.
    32. Successfully set [/omm/CMServer/backup_open][0].
    33. Start sixth step of streaming start.
    34. Start seventh step of streaming start.
    35. Start eighth step of streaming start.
    36. Waiting main standby connection..
    37. Main standby already connected.
    38. Successfully check cluster status is: Normal
    39. Start ninth step of streaming start.
    40. Starting reload wal_keep_segments value: {'6001': '128'}.
    41. Successfully reload wal_keep_segments value: {'6001': '128'}.
    42. Successfully removed step file.
    43. Successfully do streaming disaster recovery start.
  • 备集群搭建容灾关系。

    1. gs_sdr -t start -m disaster_standby -X /opt/install_streaming_standby_cluster.xml --time-out=1200 -U 'hadr_user' -W 'opengauss@123'
    2. --------------------------------------------------------------------------------
    3. Streaming disaster recovery start e34ec1e4d8a111ecb617fa163e77e94a
    4. --------------------------------------------------------------------------------
    5. Start create streaming disaster relationship ...
    6. Got step:[-1] for action:[start].
    7. Start first step of streaming start.
    8. Start common config step of streaming start.
    9. Start update pg_hba config.
    10. Successfully update pg_hba config.
    11. Start second step of streaming start.
    12. Successfully check cluster status is: Normal
    13. Successfully check instance status.
    14. Successfully check cm_ctl is available.
    15. Successfully check cluster is not under upgrade opts.
    16. Start build key files from remote cluster.
    17. Start copy hadr user key files.
    18. Successfully build and distribute key files to all nodes.
    19. Start fourth step of streaming start.
    20. Start fifth step of streaming start.
    21. Successfully set [/omm/CMServer/backup_open][2].
    22. Stopping the cluster by node.
    23. Successfully stopped the cluster by node for streaming cluster.
    24. Start sixth step of streaming start.
    25. Start seventh step of streaming start.
    26. Start eighth step of streaming start.
    27. Starting the cluster.
    28. Successfully started primary instance. Please wait for standby instances.
    29. Waiting cluster normal...
    30. Successfully started standby instances.
    31. Successfully check cluster status is: Normal
    32. Start ninth step of streaming start.
    33. Successfully removed step file.
    34. Successfully do streaming disaster recovery start.
  • 计划内主集群降备。

    1. gs_sdr -t switchover -m disaster_standby
    2. --------------------------------------------------------------------------------
    3. Streaming disaster recovery switchover 6897d15ed8a411ec82acfa163e2f2d28
    4. --------------------------------------------------------------------------------
    5. Start streaming disaster switchover ...
    6. Streaming disaster cluster switchover...
    7. Successfully check cluster status is: Normal
    8. Parse cluster conf from file.
    9. Successfully parse cluster conf from file.
    10. Successfully check cluster is not under upgrade opts.
    11. Got step:[-1] for action:[switchover].
    12. Stopping the cluster.
    13. Successfully stopped the cluster.
    14. Starting the cluster.
    15. Successfully started primary instance. Please wait for standby instances.
    16. Waiting cluster normal...
    17. Successfully started standby instances.
    18. Start checking truncation, please wait...
    19. Stopping the cluster.
    20. Successfully stopped the cluster.
    21. Starting the cluster.
    22. Successfully started primary instance. Please wait for standby instances.
    23. Waiting cluster normal...
    24. Successfully started standby instances.
    25. .
    26. The cluster status is Normal.
    27. Successfully removed step file.
    28. Successfully do streaming disaster recovery switchover.
  • 计划内备集群升主。

    1. gs_sdr -t switchover -m primary
    2. --------------------------------------------------------------------------------
    3. Streaming disaster recovery switchover 20542bbcd8a511ecbbdbfa163e77e94a
    4. --------------------------------------------------------------------------------
    5. Start streaming disaster switchover ...
    6. Streaming disaster cluster switchover...
    7. Waiting for cluster and instances normal...
    8. Successfully check cluster status is: Normal
    9. Parse cluster conf from file.
    10. Successfully parse cluster conf from file.
    11. Successfully check cluster is not under upgrade opts.
    12. Waiting for switchover barrier...
    13. Got step:[-1] for action:[switchover].
    14. Stopping the cluster by node.
    15. Successfully stopped the cluster by node for streaming cluster.
    16. Starting the cluster.
    17. Successfully started primary instance. Please wait for standby instances.
    18. Waiting cluster normal...
    19. Successfully started standby instances.
    20. Successfully check cluster status is: Normal
    21. Successfully removed step file.
    22. Successfully do streaming disaster recovery switchover.
  • 灾备集群容灾升主。

    1. gs_sdr -t failover
    2. --------------------------------------------------------------------------------
    3. Streaming disaster recovery failover 65535214d8a611ecb804fa163e2f2d28
    4. --------------------------------------------------------------------------------
    5. Start streaming disaster failover ...
    6. Got step:[-1] for action:[failover].
    7. Successfully check cluster status is: Normal
    8. Successfully check cluster is not under upgrade opts.
    9. Parse cluster conf from file.
    10. Successfully parse cluster conf from file.
    11. Got step:[-1] for action:[failover].
    12. Starting drop all node replication slots
    13. Finished drop all node replication slots
    14. Stopping the cluster by node.
    15. Successfully stopped the cluster by node for streaming cluster.
    16. Start remove replconninfo for instance:6001
    17. Start remove replconninfo for instance:6002
    18. Start remove replconninfo for instance:6003
    19. Start remove replconninfo for instance:6005
    20. Start remove replconninfo for instance:6004
    21. Successfully removed replconninfo for instance:6001
    22. Successfully removed replconninfo for instance:6004
    23. Successfully removed replconninfo for instance:6003
    24. Successfully removed replconninfo for instance:6002
    25. Successfully removed replconninfo for instance:6005
    26. Start remove pg_hba config.
    27. Finished remove pg_hba config.
    28. Starting the cluster.
    29. Successfully started primary instance. Please wait for standby instances.
    30. Waiting cluster normal...
    31. Successfully started standby instances.
    32. Successfully check cluster status is: Normal
    33. Try to clean hadr user info.
    34. Successfully clean hadr user info from database.
    35. Successfully removed step file.
    36. Successfully do streaming disaster recovery failover.
  • 主集群容灾解除。

    1. gs_sdr -t stop -X /opt/install_streaming_standby_cluster.xml
    2. --------------------------------------------------------------------------------
    3. Streaming disaster recovery stop dae8539ed8a611ecade9fa163e77e94a
    4. --------------------------------------------------------------------------------
    5. Start remove streaming disaster relationship ...
    6. Got step:[-1] for action:[stop].
    7. Start first step of streaming stop.
    8. Start second step of streaming start.
    9. Successfully check cluster status is: Normal
    10. Check cluster type succeed.
    11. Successfully check cluster is not under upgrade opts.
    12. Start third step of streaming stop.
    13. Start remove replconninfo for instance:6001
    14. Start remove replconninfo for instance:6002
    15. Successfully removed replconninfo for instance:6001
    16. Successfully removed replconninfo for instance:6002
    17. Start remove cluster file.
    18. Finished remove cluster file.
    19. Start fourth step of streaming stop.
    20. Start remove pg_hba config.
    21. Finished remove pg_hba config.
    22. Start fifth step of streaming start.
    23. Starting drop all node replication slots
    24. Finished drop all node replication slots
    25. Start sixth step of streaming stop.
    26. Successfully check cluster status is: Normal
    27. Try to clean hadr user info.
    28. Successfully clean hadr user info from database.
    29. Successfully removed step file.
    30. Successfully do streaming disaster recovery stop.
  • 查询容灾状态。

    1. gs_sdr -t query
    2. --------------------------------------------------------------------------------
    3. Streaming disaster recovery query 1201b062d8a411eca83efa163e2f2d28
    4. --------------------------------------------------------------------------------
    5. Start streaming disaster query ...
    6. Successfully check cluster is not under upgrade opts.
    7. Start check archive.
    8. Start check recovery.
    9. Start check RPO & RTO.
    10. Successfully execute streaming disaster recovery query, result:
    11. {'hadr_cluster_stat': 'archive', 'hadr_failover_stat': '', 'hadr_switchover_stat': '', 'RPO': '0', 'RTO': '0'}