问题背景
- MySQL 5.7.24
- MySQL Shell 8.0.13
- MySQL Router 8.0.13
MySQL InnoDB Cluster(Group Replication)搭建成功。Single Primary模式,具体如下:
# 主服务器
192.168.233.136:3307
# 从服务器
192.168.233.136:3307
# 从服务器
192.168.233.136:3307
尝试利用官方推荐的MySQL Router进行集群的路由,但是在初始化Router命令式报错如下:
[root@xxx etc]# mysqlrouter --bootstrap 192.168.233.136:3307 --directory /usr/local/mysqlrouter --user root
Please enter MySQL password for root:
WARNING: The MySQL server does not have SSL configured and metadata used by the router may be transmitted unencrypted.
Bootstrapping MySQL Router instance at '/usr/local/mysqlrouter'...
Error: Could not register this Router instance with the cluster because querying this host's hostname from OS failed:
Could not get local hostname: Temporary failure in name resolution (ret: -3, errno: 0)
You may want to try --report-host option to manually supply this hostname.
解决方法
根据错误提示在命令行后添加主机名即可
[root@xxx etc]# mysqlrouter --bootstrap localhost:3307 --directory /usr/local/mysqlrouter --user root --report-host xxx
Please enter MySQL password for root:
WARNING: The MySQL server does not have SSL configured and metadata used by the router may be transmitted unencrypted.
Bootstrapping MySQL Router instance at '/usr/local/mysqlrouter'...
Checking for old Router accounts
Creating account mysql_router1_f2o1wqkibyp2@'%'
MySQL Router has now been configured for the InnoDB cluster 'myCluster'.
The following connection information can be used to connect to the cluster after MySQL Router has been started with generated configuration..
Classic MySQL protocol connections to cluster 'myCluster':
- Read/Write Connections: localhost:6446
- Read/Only Connections: localhost:6447
X protocol connections to cluster 'myCluster':
- Read/Write Connections: localhost:64460
- Read/Only Connections: localhost:64470
[root@cmiot1 etc]# cd /usr/local/mysqlrouter/
[root@cmiot1 mysqlrouter]# ll
total 28
drwx------ 2 root root 4096 Dec 4 14:39 data
drwx------ 2 root root 4096 Dec 4 14:39 log
-rw------- 1 root root 1286 Dec 4 14:39 mysqlrouter.conf
-rw------- 1 root root 93 Dec 4 14:39 mysqlrouter.key
drwx------ 2 root root 4096 Dec 4 14:39 run
-rwx------ 1 root root 290 Dec 4 14:39 start.sh
-rwx------ 1 root root 176 Dec 4 14:39 stop.sh
[root@cmiot1 mysqlrouter]#
此时,初始化的文件均已生成在/usr/local/mysqlrouter
文件夹中,若要启动Router直接在当前文件夹中执行
[root@cmiot1 mysqlrouter]# ./start.sh
即可