问题出现的前因:
因为重新安装了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.”的解决办法!