文件首頁
MySQL Shell 8.4
下載本手冊
PDF (US Ltr) - 2.2Mb
PDF (A4) - 2.3Mb


MySQL Shell 8.4  /  ...  /  將執行個體新增至 InnoDB Cluster

7.4.4 將執行個體新增至 InnoDB Cluster

InnoDB Cluster 中至少需要三個執行個體,才能容忍一個執行個體故障。新增更多執行個體可提高 InnoDB Cluster 的容錯能力。

Group Replication 實作會考慮執行個體版本的相容性原則,且 Cluster.addInstance() 作業會偵測到這一點,如果發生不相容的情況,作業會以錯誤終止。請參閱檢查執行個體上的 MySQL 版本在群組中合併不同的成員版本

使用 Cluster.addInstance(instance) 函數將執行個體新增至叢集,其中 instance 是已設定執行個體的連線資訊,請參閱第 7.4.2 節,「設定生產環境執行個體以供 InnoDB Cluster 使用」。例如

mysql-js> cluster.addInstance('icadmin@ic-2:3306')
A new instance will be added to the InnoDB cluster. Depending on the amount of
data on the cluster this might take from a few seconds to several hours.
Please provide the password for 'icadmin@ic-2:3306': ********
Adding instance to the cluster ...
Validating instance at ic-2:3306...
This instance reports its own address as ic-2
Instance configuration is suitable.
The instance 'icadmin@ic-2:3306' was successfully added to the cluster.

addInstance(instance[, options]) 函數的選項字典提供下列屬性

  • label:要新增之執行個體的識別碼。

    標籤必須為非空值,且長度不得超過 256 個字元。它在叢集中必須是唯一的,且只能包含字母數字字元、_ (底線)、. (句點)、- (連字號) 或 : (冒號) 字元。

  • recoveryMethod:狀態復原的慣用方法。可能是自動、clone 或增量。預設值為自動。

  • recoveryProgress:定義復原程序詳細資訊層級的整數值。

    • 0:不顯示任何進度資訊。

    • 1:顯示詳細的靜態進度資訊。

    • 2:使用進度列顯示詳細的動態進度資訊。

  • ipAllowlist:允許連線至執行個體以進行群組複寫的主機清單。

  • localAddress:包含要使用的 Group Replication 本機位址的字串值,而不是自動產生的位址。

  • exitStateAction:指示群組複寫結束狀態動作的字串值。

  • memberWeight:在容錯移轉時,用於自動主要選舉的百分比權重整數值。

  • autoRejoinTries:用於定義執行個體在被驅逐後嘗試重新加入叢集的次數的整數值。

當新的執行個體新增至叢集時,此執行個體的本機位址會自動新增至所有在線上叢集執行個體的group_replication_group_seeds變數,以便讓它們在需要時使用新的執行個體重新加入群組。

注意

group_replication_group_seeds中列出的執行個體會根據其在清單中的顯示順序使用。這可確保先使用使用者指定的設定,再使用慣用設定。請參閱第 7.5.2 節,「自訂 InnoDB Cluster 成員伺服器」以取得更多資訊。

如果您使用 MySQL 8.0.17 或更新版本,您可以選擇執行個體如何復原與叢集同步所需的交易。只有在加入的執行個體復原叢集先前處理的所有交易之後,它才能以線上執行個體加入並開始處理交易。如需更多資訊,請參閱第 7.4.6 節,「搭配 InnoDB Cluster 使用 MySQL Clone」

您可以設定 Cluster.addInstance() 的行為方式,讓復原作業在背景中進行,或在 MySQL Shell 中監控不同層級的進度。

根據您選擇從叢集復原執行個體的方式,您會在 MySQL Shell 中看到不同的輸出。假設您要將執行個體 ic-2 新增至叢集,而 ic-1 是種子或捐贈者。

  • 當您使用 MySQL Clone 從叢集復原執行個體時,輸出看起來像

    Validating instance at ic-2:3306...
    This instance reports its own address as ic-2:3306
    Instance configuration is suitable.
    A new instance will be added to the InnoDB cluster. Depending on the amount of
    data on the cluster this might take from a few seconds to several hours.
    Adding instance to the cluster...
    Monitoring recovery process of the new cluster member. Press ^C to stop monitoring 
    and let it continue in background.
    Clone based state recovery is now in progress.
    NOTE: A server restart is expected to happen as part of the clone process. If the
    server does not support the RESTART command or does not come back after a
    while, you may need to manually start it back.
    * Waiting for clone to finish...
    NOTE: ic-2:3306 is being cloned from ic-1:3306
    ** Stage DROP DATA: Completed
    ** Clone Transfer
    FILE COPY  ############################################################  100%  Completed
    PAGE COPY  ############################################################  100%  Completed
    REDO COPY  ############################################################  100%  Completed
    NOTE: ic-2:3306 is shutting down...
    * Waiting for server restart... ready
    * ic-2:3306 has restarted, waiting for clone to finish...
    ** Stage RESTART: Completed
    * Clone process has finished: 2.18 GB transferred in 7 sec (311.26 MB/s)
    State recovery already finished for 'ic-2:3306'
    The instance 'ic-2:3306' was successfully added to the cluster.

    應觀察有關伺服器重新啟動的警告,您可能必須手動重新啟動執行個體。請參閱RESTART 陳述式

  • 當您使用增量復原從叢集復原執行個體時,輸出看起來像

    Incremental distributed state recovery is now in progress.
    * Waiting for incremental recovery to finish...
    NOTE: 'ic-2:3306' is being recovered from 'ic-1:3306'
    * Distributed recovery has finished

若要取消監控復原階段,請發出 CONTROL+C。這會停止監控,但復原程序會在背景中繼續進行。recoveryProgress 整數選項可與 Cluster.addInstance() 作業搭配使用,以顯示復原階段的進度。

若要驗證已新增執行個體,請使用叢集執行個體的 status() 函數。例如,這是新增第二個執行個體後沙箱叢集的狀態輸出

mysql-js> cluster.status()
{
    "clusterName": "testCluster",
    "defaultReplicaSet": {
        "name": "default",
        "primary": "ic-1:3306",
        "ssl": "REQUIRED",
        "status": "OK_NO_TOLERANCE",
        "statusText": "Cluster is NOT tolerant to any failures.",
        "topology": {
            "ic-1:3306": {
                "address": "ic-1:3306",
                "mode": "R/W",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            },
            "ic-2:3306": {
                "address": "ic-2:3306",
                "mode": "R/O",
                "readReplicas": {},
                "role": "HA",
                "status": "ONLINE"
            }
        }
    },
    "groupInformationSourceMember": "mysql://icadmin@ic-1:3306"
}

您如何繼續取決於執行個體是本機還是遠端於執行 MySQL Shell 的執行個體,以及執行個體是否支援自動保存組態變更,請參閱第 6.2.3 節,「保存設定」。如果執行個體支援自動保存組態變更,您就不需要手動保存設定,可以新增更多執行個體,或繼續下一個步驟。如果執行個體不支援自動保存組態變更,您必須在本機設定執行個體。這對於確保執行個體在離開叢集時能重新加入叢集至關重要。

提示

如果執行個體具有 super_read_only=ON,則您可能需要確認 AdminAPI 可以設定 super_read_only=OFF。請參閱在超級唯讀模式中設定執行個體以取得更多資訊。

部署叢集後,您可以設定 MySQL Router 以提供高可用性,請參閱第 6.10 節,「搭配 AdminAPI、InnoDB Cluster 和 InnoDB ReplicaSet 使用 MySQL Router」