9.4.2 向ReplicaSet添加实例示例

2024年 3月 13日 69.4k 0

  1. 使用该操作将辅助实例添加到 . 您将 指定 为类似 URI 的连接字符串。您指定的用户必须具有所需的权限,并且在 ReplicaSet 中的所有实例上必须相同。有关更多信息,请参阅 第 9.2 节 “配置 InnoDB ReplicaSet 实例”。 *ReplicaSet*.addInstance(*instance*)ReplicaSet**instance

    例如,要添加实例rs-2、端口号3306和用户 rsadmin,请发出:

    解释 mysql-js> rs.addInstance('rsadmin@rs-2:3306')

    Adding instance to the replicaset...

    * Performing validation checks

    This instance reports its own address as rsadmin@rs-2
    rsadmin@rs-2: Instance configuration is suitable.

    * Checking async replication topology...

    * Checking transaction state of the instance...

    NOTE: The target instance 'rsadmin@rs-2' has not been pre-provisioned (GTID set
    is empty). The Shell is unable to decide whether replication can completely
    recover its state. The safest and most convenient way to provision a new
    instance is through automatic clone provisioning, which will completely
    overwrite the state of 'rsadmin@rs-2' with a physical snapshot from an existing
    replicaset member. To use this method by default, set the 'recoveryMethod'
    option to 'clone'.

    WARNING: It should be safe to rely on replication to incrementally recover the
    state of the new instance if you are sure all updates ever processed in the
    replicaset were done with GTIDs enabled, there are no purged transactions and
    the new instance contains the same GTID set as the replicaset, or a subset of it.
    To use this method by default, set the 'recoveryMethod' option to 'incremental'.
    Please select a recovery method [C]lone/[I]ncremental recovery/[A]bort (default Clone):

  2. 在这种情况下,我们没有指定恢复方法,因此该操作会建议您如何最好地继续进行。在此示例中,我们选择该Clone选项是因为加入 ReplicaSet 的实例上没有任何现有事务。因此,不存在从加入实例中删除数据的风险。有关更多信息,请参阅 InnoDB ReplicaSet 的恢复方法。

    解释 Please select a recovery method [C]lone/[I]ncremental recovery/[A]bort (default Clone): C
    * Updating topology
    Waiting for clone process of the new member to complete. Press ^C to abort the operation.
    * Waiting for clone to finish...
    NOTE: rsadmin@rs-2 is being cloned from rsadmin@rs-1
    ** Stage DROP DATA: Completed
    ** Clone Transfer
    FILE COPY ############################################################ 100% Completed
    PAGE COPY ############################################################ 100% Completed
    REDO COPY ############################################################ 100% Completed
    ** Stage RECOVERY: \
    NOTE: rsadmin@rs-2 is shutting down...

    * Waiting for server restart... ready
    * rsadmin@rs-2 has restarted, waiting for clone to finish...
    * Clone process has finished: 59.63 MB transferred in about 1 second (~1.00 B/s)

    ** Configuring rsadmin@rs-2 to replicate from rsadmin@rs-1
    ** Waiting for new instance to synchronize with PRIMARY...

    The instance 'rsadmin@rs-2' was added to the replicaset and is replicating from rsadmin@rs-1.

  3. 假设该实例对于 InnoDB ReplicaSet 使用有效,则恢复将继续。在这种情况下,新加入的实例使用 MySQL Clone 从主实例复制尚未应用的所有事务,然后作为在线实例加入 ReplicaSet。要验证,请使用以下 *rs*.status() 操作:

    解释 mysql-js> rs.status()
    {
    "replicaSet": {
    "name": "example",
    "primary": "rs-1:3306",
    "status": "AVAILABLE",
    "statusText": "All instances available.",
    "topology": {
    "rs-1:3306": {
    "address": "rs-1:3306",
    "instanceRole": "PRIMARY",
    "mode": "R/W",
    "status": "ONLINE"
    },
    "rs-2:3306": {
    "address": "rs-2:3306",
    "instanceRole": "SECONDARY",
    "mode": "R/O",
    "replication": {
    "applierStatus": "APPLIED_ALL",
    "applierThreadState": "Replica has read all relay log; waiting for more updates",
    "receiverStatus": "ON",
    "receiverThreadState": "Waiting for source to send event",
    "replicationLag": null
    },
    "status": "ONLINE"
    }
    },
    "type": "ASYNC"
    }
    }

    此输出显示现在命名的 ReplicaSet example由两个 MySQL 实例组成,并且主实例是rs-1. 目前, 处有一个辅助实例 rs-2,它是主实例的副本。ReplicaSet上线,意味着主备同步。此时,ReplicaSet 已准备好处理事务。

  4. 要覆盖交互式 MySQL Shell 模式,请选择最合适的恢复方法。使用该 recoveryMethod选项配置实例如何恢复能够加入 ReplicaSet 所需的数据。有关更多信息,请参阅 第 7.4.6 节 “将 MySQL 克隆与 InnoDB Cluster 结合使用”。

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论