問題出現的前因:
因為重新安裝了MySQL Router,然後打算重新連線上目標叢集進行MySQL Router的初始化引導,結果報錯了!
[root@linux666 system]# mysqlrouter --bootstrap icadmin@linux03:3306 --user root Please enter MySQL password for icadmin: # Bootstrapping system MySQL Router instance... Error: It appears that a router instance named 'system' has been previously configured in this host. If that instance no longer exists, use the --force option to overwrite it. [root@linux666 system]#
按提示新增 --force 選項後,雖然能初始化完成,但啟動mysqlrouter後,很快MySQL Router所監聽的一系列埠就會斷開,mysqlrouter自動退出!
[root@linux666 system]# mysqlrouter --bootstrap icadmin@linux03:3306 --user root --force
上面那個報錯很容易讓人誤解,以為上次解除安裝MySQL Router是在本機哪個地方還有沒刪除乾淨的配置,其實就算你重灌系統只要你主機名(hostname)沒換,連線相同的叢集還是會報出這個問題來!那麼從這裡就可以很肯的得知道,這個問題的檢測是在叢集那邊的,也就是叢集上有留下MySQL Router初始化引導時留下的記錄!!!存在叢集的那裡了呢?
上MySQL官網,看到了這麼個命令—— Cluster.listRouters()
Working with a Cluster's Routers
You can bootstrap multiple instances of MySQL Router against InnoDB Cluster or InnoDB ReplicaSet. From version 8.0.19, to show a list of all registered MySQL Router instances, issue:
Cluster.listRouters()
The result provides information about each registered MySQL Router instance, such as its name in the metadata, the hostname, ports, and so on. For example, issue:
mysql-js> Cluster.listRouters() { "clusterName": "example", "routers": { "ic-1:3306": { "hostname": "ic-1:3306", "lastCheckIn": "2020-01-16 11:43:45", "roPort": 6447, "roXPort": 64470, "rwPort": 6446, "rwXPort": 64460, "version": "8.0.19" } } }
轉到叢集相關主機上,用MySQL Shell連線上去,獲取到叢集控制程式碼(var cluster=dba.getCluster('myCluster'))後,執行一下上述命令,果然是有記錄在案:
執行以下命令將它們移除就好:
mysql-js> cluster.removeRouterMetadata('linux666::'); mysql-js> cluster.removeRouterMetadata('linux666::system');
最後到MySQL Router安裝機上重新連線上叢集進行初始化引導,就Ok了!
以前就是關於 MySQL Router “Error: It appears that a router instance named 'system' has been previously configured in this host. If that instance no longer exists, use the --force option to overwrite it.”的解決辦法!