除了從頭建立 ReplicaSet,您也可以使用 dba.createReplicaSet()
的 adoptFromAR
選項來採用現有的複寫設定。系統會掃描複寫設定,如果它與InnoDB ReplicaSet 限制相容,AdminAPI 會建立必要的 metadata。一旦採用複寫設定,您就只能使用 AdminAPI 來管理 InnoDB ReplicaSet。
若要將現有的複寫設定轉換為 InnoDB ReplicaSet,請連線至主要執行個體,也稱為來源。系統會從 MySQL Shell 的連線全域工作階段開始自動掃描並驗證複寫拓撲。在採用期間會檢查所有執行個體的組態,以確保它們與 InnoDB ReplicaSet 的使用方式相容。
所有複寫通道都必須處於活動狀態,且它們的交易集必須透過 GTID 集驗證為一致。
假設執行個體具有相同的狀態或能夠收斂。
所有新的複寫通道都會啟用 SSL。這對於使用 MySQL Shell 8.0.32 採用的複寫群組並非如此。它們的複寫通道仍未加密。
系統會自動掃描並驗證複寫拓撲,從 MySQL Shell 的全域工作階段連線到的執行個體開始。此操作對已採用 ReplicaSet 所做的唯一變更就是建立 metadata 結構描述。現有的複寫通道在採用期間不會變更,但您可以在後續的主要切換操作期間變更它們。
例如,若要將 example1
和 example2
上的 MySQL 伺服器執行個體所組成的複寫拓撲採用至 InnoDB ReplicaSet。
連線至 example1
的主要執行個體並發出
mysql-js> rs = dba.createReplicaSet('testadopt', {'adoptFromAR':1})
A new replicaset with the topology visible from 'example1:3306' will be created.
* Scanning replication topology...
** Scanning state of instance example1:3306
** Scanning state of instance example2:3306
* Discovering async replication topology starting with example1:3306
Discovered topology:
- example1:3306: uuid=00371d66-3c45-11ea-804b-080027337932 read_only=no
- example2:3306: uuid=59e4f26e-3c3c-11ea-8b65-080027337932 read_only=no
- replicates from example1:3306
source="localhost:3310" channel= status=ON receiver=ON applier=ON
* Checking configuration of discovered instances...
This instance reports its own address as example1:3306
example1:3306: Instance configuration is suitable.
This instance reports its own address as example2:3306
example2:3306: Instance configuration is suitable.
* Checking discovered replication topology...
example1:3306 detected as the PRIMARY.
Replication state of example2:3306 is OK.
Validations completed successfully.
* Updating metadata...
ReplicaSet object successfully created for example1:3306.
Use rs.addInstance() to add more asynchronously replicated instances to
this replicaset and rs.status() to check its status.
一旦採用 InnoDB ReplicaSet,您可以使用它,就像使用建立的 ReplicaSet 一樣。
從此時起,您必須僅使用 AdminAPI 管理 InnoDB ReplicaSet。