
作者 韩杰 · 沃趣科技高级数据库工程师
出品 沃趣科技

给定实例,如何发现自己
这里涉及到两个参数:HostnameResolveMethod、MySQLHostnameResolveMethod
HostnameResolveMethod有三个选项:"cname"、"default"、"none"
cname:通过CNAME做域名解析(resolve hostname)
default:不做特别的解析, no special resolving via net protocols
none:do nothing
MySQLHostnameResolveMethod有三个选项:"@@hostname"、"@@report_host"、""
@@hostname: select @@hostname
@@report_host: select @@report_host
"": do nothing
因此,最好保证线上环境,不同服务器的主机名都不同。
给定主库,如何发现从库
由参数DiscoverByShowSlaveHosts控制。
从库设置了正确的report_host,show slave hosts中的host字段显示正确的IP,则直接通过show slave hosts发现从库。
从库设置了错误的report_host,show slave hosts中的host字段显示错误的IP,则orchestrator找不到从库。
[mysql] 2019/10/29 17:57:24 driver.go:81: net.Error from Dial()': dial tcp 10.10.30.222:3306: i/o timeout
[mysql] 2019/10/29 17:57:25 driver.go:81: net.Error from Dial()': dial tcp 10.10.30.222:3306: i/o timeout
[mysql] 2019/10/29 17:57:26 driver.go:81: net.Error from Dial()': dial tcp 10.10.30.222:3306: i/o timeout
2019-10-29 17:57:26 ERROR driver: bad connection
2019-10-29 18:15:34 ERROR dial tcp 10.10.30.228:3306: connect: connection refused
2019-10-29 18:15:40 ERROR dial tcp 10.10.30.228:3306: connect: connection refused
2019-10-29 18:15:46 ERROR dial tcp 10.10.30.228:3306: connect: connection refused
2019-10-29 18:15:52 ERROR dial tcp 10.10.30.228:3306: connect: connection refused
// 或者
2019-10-29 18:11:11 ERROR Error 1045: Access denied for user 'orchestrator'@'10.10.30.146' (using password: YES)
WARNING: NamedStopwatch.Stop("instance") IsRunning is false
2019-10-29 18:11:17 ERROR Error 1045: Access denied for user 'orchestrator'@'10.10.30.146' (using password: YES)
WARNING: NamedStopwatch.Stop("instance") IsRunning is false
从库没有设置report_host,show slave hosts中的host字段显示为空,则通过processlist发现从库。
- 此时,会报如下信息:
2019-08-06 18:12:49 ERROR ReadTopologyInstance(10.10.30.129:3306) show slave hosts: ReadTopologyInstance(10.10.30.129:3306) 'show slave hosts' returned row with <host,port>: <,3306>
如果为false,则通过information_schema.processlist去发现从库。
select substring_index(host, ':', 1) as slave_hostname from information_schema.processlist where command IN ('Binlog Dump', 'Binlog Dump GTID');
给定从库,如何发现主库
通过show slave status命令去发现主库。
DiscoveryByShowSlaveHosts意义
既然show slave status命令显示的host不一定准确,那为什么还要加入DiscoverByShowSlaveHosts这个参数呢?
更重要的是,如果只是通过information_schema.processlist去发现从库,master无法知道replica监听的是哪个端口。show processlist只会显示复制进程使用的套接字端口,而不是replica实例监听的端口。所以需要用户在配置文件中设置好report_host和report_port参数,并且在orch的配置文件中将参数DiscoverByShowSlaveHosts设置为true。
注意点
report_port
The default value for this option is the port number actually used by the slave. This is also the default value displayed by SHOW SLAVE HOSTS.
DiscoverByShowSlaveHosts设置为false
DiscoverByShowSlaveHosts设置为true
##这里我的master是10.10.30.230:3307,slave是10.10.30.249:3306,且从库没有设置report_host
// show slave hosts报错信息如下
2019-10-29 17:37:18 ERROR ReadTopologyInstance(10.10.30.230:3307) show slave hosts: ReadTopologyInstance(10.10.30.230:3307) 'show slave hosts' returned row with <host,port>: <,3306>
// 显示10.10.30.249:3307连不上,说明通过processlist发现从库用的是和主库相同的端口
2019-10-29 17:37:24 ERROR dial tcp 10.10.30.249:3307: connect: connection refused
此时需要手动进行发现:
web界面:clusters/discover
结 论
参考文章
http://code.openark.org/blog/mysql/the-importance-of-report_host-report_port

更多干货,欢迎来撩~
文章转载自yangyidba,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




