您需要 InnoDB Cluster 中至少三個執行個體,才能使其容許一個執行個體發生故障。新增更多執行個體會提高 InnoDB Cluster 的故障容許度。
群組複寫實作相容性原則,會考量執行個體的版本,而
作業會偵測到這一點,如果發生不相容的情況,則作業會以錯誤終止。請參閱檢查執行個體上的 MySQL 版本和在群組中組合不同的成員版本。Cluster
.addInstance()
使用
函數將執行個體新增至叢集,其中 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
:偏好的狀態還原方法。可能是 auto、clone 或 incremental。預設值為 auto。-
recoveryProgress
:定義還原程序詳細資訊等級的整數值。0:不顯示任何進度資訊。
1:顯示詳細的靜態進度資訊。
2:使用進度列顯示詳細的動態進度資訊。
ipAllowlist
:允許連線至執行個體進行群組複寫的主機清單。localAddress
:字串值,其中包含要使用的群組複寫本機位址,而不是自動產生的位址。exitStateAction
:字串值,指示群組複寫結束狀態動作。memberWeight
:整數值,其中包含容錯移轉時自動主要選舉的百分比權重。autoRejoinTries
:整數值,用於定義執行個體在被逐出後嘗試重新加入叢集的次數。
當新執行個體新增至叢集時,此執行個體的本機位址會自動新增至所有線上叢集執行個體上的group_replication_group_seeds
變數,以便讓它們在需要時使用新的執行個體重新加入群組。
group_replication_group_seeds
中列出的執行個體會根據它們在清單中出現的順序使用。這可確保先使用使用者指定的設定,且為偏好設定。如需詳細資訊,請參閱第 7.5.2 節「自訂 InnoDB Cluster 成員伺服器」。
如果您使用的是 MySQL 8.0.17 或更新版本,則您可以選擇執行個體如何復原其需要與叢集同步的交易。只有當加入的執行個體已復原叢集先前處理的所有交易時,才能將其加入為線上執行個體並開始處理交易。如需詳細資訊,請參閱第 7.4.6 節「將 MySQL Clone 與 InnoDB Cluster 搭配使用」。
您可以設定
的行為方式,讓還原作業在背景中進行,或在 MySQL Shell 中監控不同的進度等級。Cluster
.addInstance()
根據您選擇從叢集中復原執行個體的哪個選項,您會在 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 節「將 MySQL Router 與 AdminAPI、InnoDB Cluster 和 InnoDB ReplicaSet 搭配使用」。