MySQL Group Replication如何获取主节点ip地址

Posted

技术标签:

【中文标题】MySQL Group Replication如何获取主节点ip地址【英文标题】:How MySQL Group Replication get primary node ip address 【发布时间】:2017-05-12 09:11:13 【问题描述】:

根据mysql 5.7参考手册:

http://dev.mysql.com/doc/refman/5.7/en/group-replication-find-primary.html

http://dev.mysql.com/doc/refman/5.7/en/group-replication-monitoring.html

在单模式部署组复制时,我们可以使用下面的 sql 来查找主节点的主机名:

mysql> SELECT * FROM performance_schema.replication_group_members WHERE MEMBER_ID = (SELECT VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME= 'group_replication_primary_member');
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 9176f4d3-c7f6-11e6-bcf7-fa163ee40410 | myhost      |       24801 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
1 row in set (0.00 sec)

问题是:如何获取ip地址而不是主机名?

【问题讨论】:

【参考方案1】:

您无法获取主机名的任何 IP 地址。如果您正在连接到某个主机,那么您知道该主机名的 IP 地址。这是 mysql 论坛上的 mailing list,对您有帮助。

【讨论】:

【参考方案2】:

好的,我们可以使用名为report_host的属性来指向我们的ip地址,例如:

在我自己的机器上,我部署了三个节点(s1,s2,s3)组成一个复制组,一共my.cnf,定义它(10.202.7.88是我的ip地址):

report_host=10.202.7.88

然后重启所有节点,重新配置三个节点组成复制组,然后查询:

mysql> select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 933a5345-d321-11e6-b971-fa163ee40410 | 10.202.7.88 |       24801 | ONLINE       |
| group_replication_applier | 9abe6249-d321-11e6-bb5c-fa163ee40410 | 10.202.7.88 |       24802 | ONLINE       |
| group_replication_applier | a1c89c34-d321-11e6-bbbc-fa163ee40410 | 10.202.7.88 |       24803 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
3 rows in set (0.00 sec)

然后我们可以使用上面我们提到的sql来获取主节点ip地址:

mysql> SELECT * FROM performance_schema.replication_group_members WHERE MEMBER_ID = (SELECT VARIABLE_VALUE FROM performance_schema.global_status WHERE VARIABLE_NAME= 'group_replication_primary_member');
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 933a5345-d321-11e6-b971-fa163ee40410 | 10.202.7.88 |       24801 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
1 row in set (0.00 sec)

【讨论】:

以上是关于MySQL Group Replication如何获取主节点ip地址的主要内容,如果未能解决你的问题,请参考以下文章

组复制安全 | 全方位认识 MySQL 8.0 Group Replication

组复制常见疑问 | 全方位认识 MySQL 8.0 Group Replication

mysql group replication

MySQL group replication介绍

Mysql Group Replication 简析

mysql-group-replication 测试环境的搭建与排错