GreatSQL社区

搜索

[已解决] MySQL Shell搭建的单主MGR集群却无法切换主节点

764 4 2024-3-27 08:44
本帖最后由 tony 于 2024-3-28 10:30 编辑

1.首先使用mysql客户端切换主节点到mgr02成功

  1. mysql> select group_replication_set_as_primary('f4343bed-e68a-11ee-9d06-000c293b6e72');
  2. +--------------------------------------------------------------------------+
  3. | group_replication_set_as_primary('f4343bed-e68a-11ee-9d06-000c293b6e72') |
  4. +--------------------------------------------------------------------------+
  5. | Primary server switched to: f4343bed-e68a-11ee-9d06-000c293b6e72         |
  6. +--------------------------------------------------------------------------+
  7. 1 row in set (1.16 sec)

  8. mysql> select * from performance_schema.replication_group_members;
  9. +---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+----------------------------+
  10. | CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE | MEMBER_ROLE | MEMBER_VERSION | MEMBER_COMMUNICATION_STACK |
  11. +---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+----------------------------+
  12. | group_replication_applier | 2b5c6540-e5d0-11ee-8376-000c29ec4ae4 | mgr01       |        3306 | ONLINE       | SECONDARY   | 8.0.35         | MySQL                      |
  13. | group_replication_applier | 3ac2f4f2-e68b-11ee-8c27-000c2978862a | mgr03       |        3306 | ONLINE       | SECONDARY   | 8.0.35         | MySQL                      |
  14. | group_replication_applier | f4343bed-e68a-11ee-9d06-000c293b6e72 | mgr02       |        3306 | ONLINE       | PRIMARY     | 8.0.35         | MySQL                      |
  15. +---------------------------+--------------------------------------+-------------+-------------+--------------+-------------+----------------+----------------------------+
  16. 3 rows in set (0.00 sec)

  17. mysql>
复制代码
2.利用MySQL Shell在mgr02上切换主节点却失败,报错Cluster.setPrimaryInstance: The instance 'mgr01:3306' does not belong to the cluster: 'mgr_test'. (RuntimeError)
  1. MySQL  localhost  JS > var c=dba.getCluster()
  2. MySQL  localhost  JS > c.status()
  3. {
  4.     "clusterName": "mgr_test",
  5.     "defaultReplicaSet": {
  6.         "name": "default",
  7.         "primary": "mgr02:3306",
  8.         "ssl": "REQUIRED",
  9.         "status": "OK",
  10.         "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",
  11.         "topology": {
  12.             "mgr01:3306": {
  13.                 "address": "mgr01:3306",
  14.                 "memberRole": "SECONDARY",
  15.                 "memberState": "(MISSING)",
  16.                 "mode": "n/a",
  17.                 "readReplicas": {},
  18.                 "role": "HA",
  19.                 "shellConnectError": "MySQL Error 1045: Could not open connection to 'mgr01:3306': Access denied for user 'root'@'mgr02' (using password: YES)",
  20.                 "status": "ONLINE",
  21.                 "version": "8.0.35"
  22.             },
  23.             "mgr02:3306": {
  24.                 "address": "mgr02:3306",
  25.                 "memberRole": "PRIMARY",
  26.                 "memberState": "(MISSING)",
  27.                 "mode": "n/a",
  28.                 "readReplicas": {},
  29.                 "role": "HA",
  30.                 "shellConnectError": "MySQL Error 1045: Could not open connection to 'mgr02:3306': Access denied for user 'root'@'mgr02' (using password: YES)",
  31.                 "status": "ONLINE",
  32.                 "version": "8.0.35"
  33.             },
  34.             "mgr03:3306": {
  35.                 "address": "mgr03:3306",
  36.                 "memberRole": "SECONDARY",
  37.                 "memberState": "(MISSING)",
  38.                 "mode": "n/a",
  39.                 "readReplicas": {},
  40.                 "role": "HA",
  41.                 "shellConnectError": "MySQL Error 1045: Could not open connection to 'mgr03:3306': Access denied for user 'root'@'mgr02' (using password: YES)",
  42.                 "status": "ONLINE",
  43.                 "version": "8.0.35"
  44.             }
  45.         },
  46.         "topologyMode": "Single-Primary"
  47.     },
  48.     "groupInformationSourceMember": "mgr02:3306"
  49. }
  50. MySQL  localhost  JS > c.setPrimaryInstance('mgr01:3306')
  51. Cluster.setPrimaryInstance: The instance 'mgr01:3306' does not belong to the cluster: 'mgr_test'. (RuntimeError)
  52. MySQL  localhost  JS >c.setPrimaryInstance('mgr01:3306')
复制代码
mysql shell 日志如下
  1. 2024-03-26 16:00:02: Info: Dba.getCluster: tid=93: CONNECTED: /data%2Fmysql%2Fdata%2Fmysql.sock
  2. 2024-03-26 16:00:02: Info: Connecting to MySQL at: mysql://root@/data%2Fmysql%2Fdata%2Fmysql.sock?connect-timeout=5000
  3. 2024-03-26 16:00:02: Info: Dba.getCluster: tid=94: CONNECTED: /data%2Fmysql%2Fdata%2Fmysql.sock
  4. 2024-03-26 16:00:03: Info: Group Replication 'group_name' value: cb3fe36c-eb4e-11ee-bd6a-000c29ec4ae4
  5. 2024-03-26 16:00:03: Info: Metadata 'group_name' value: cb3fe36c-eb4e-11ee-bd6a-000c29ec4ae4
  6. 2024-03-26 16:01:25: Info: Connecting to MySQL at: mysql://root@mgr01:3306?connect-timeout=5000
  7. 2024-03-26 16:01:25: Info: Connecting to MySQL at: mysql://root@mgr02:3306?connect-timeout=5000
  8. 2024-03-26 16:01:25: Info: Connecting to MySQL at: mysql://root@mgr03:3306?connect-timeout=5000
  9. 2024-03-26 16:02:51: Info: Connecting to MySQL at: mysql://root@mgr01:3306?connect-timeout=5000
  10. 2024-03-26 16:09:08: Info: Connecting to MySQL at: mysql://root@mgr01:3306?connect-timeout=5000
复制代码


全部回复(4)
yejr 2024-3-27 08:52:14
mgr01这个节点要在Shell里重新join一次
1. removeInstance()删掉节点
2. addInstance()加入节点
tony 2024-3-27 10:22:32
yejr 发表于 2024-3-27 08:52
mgr01这个节点要在Shell里重新join一次
1. removeInstance()删掉节点
2. addInstance()加入节点 ...

叶老师找到原因了,我MySQL Shell使用root用户登录切换的,我改用mgr用户可以切换成功了。
yejr 2024-3-27 17:10:06
tony 发表于 2024-3-27 10:22
叶老师找到原因了,我MySQL Shell使用root用户登录切换的,我改用mgr用户可以切换成功了。 ...

记得在shell里,root账户是没办法操纵MGR的,需要切换到MGR专用账户
tony 2024-3-28 10:12:26
yejr 发表于 2024-3-27 17:10
记得在shell里,root账户是没办法操纵MGR的,需要切换到MGR专用账户

是的,所以切换失败了,mgr专用账户没问题。
tony

8

主题

0

博客

173

贡献

注册会员

Rank: 2

积分
196

助人为乐(铜)

合作电话:010-64087828

社区邮箱:greatsql@greatdb.com

社区公众号
社区小助手
QQ群
GMT+8, 2024-12-4 01:22 , Processed in 0.023934 second(s), 18 queries , Redis On.
快速回复 返回顶部 返回列表