请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

关于MHA故障切换的问题

老师,我根据视频,配置好了 1主2从的 3台mysql服务器,
ip 为 192.168.200.1 ,192.168.200.2 ,192.168.200.3
还有一台单独弄成管理服务 192.168.200.100 ,总共4台虚拟机~
主从配置也配好了, 主为192.168.200.1 从为剩下的两台
MHA也都按照要求所有依赖包都安装了,
ssh 账号我没有使用root ,用的当前账号vagrant
启动后 使用:

[vagrant@manager mha]$ masterha_check_ssh --conf=/etc/mha/mysql-mha.conf
Thu Apr 30 14:50:20 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu Apr 30 14:50:20 2020 - [info] Reading application default configuration from /etc/mha/mysql-mha.conf..
Thu Apr 30 14:50:20 2020 - [info] Reading server configuration from /etc/mha/mysql-mha.conf..
Thu Apr 30 14:50:20 2020 - [info] Starting SSH connection tests..
Thu Apr 30 14:50:23 2020 - [debug] 
Thu Apr 30 14:50:20 2020 - [debug]  Connecting via SSH from vagrant@192.168.200.2(192.168.200.2:22) to vagrant@192.168.200.1(192.168.200.1:22)..
Thu Apr 30 14:50:22 2020 - [debug]   ok.
Thu Apr 30 14:50:22 2020 - [debug]  Connecting via SSH from vagrant@192.168.200.2(192.168.200.2:22) to vagrant@192.168.200.3(192.168.200.3:22)..
Thu Apr 30 14:50:23 2020 - [debug]   ok.
Thu Apr 30 14:50:23 2020 - [debug] 
Thu Apr 30 14:50:20 2020 - [debug]  Connecting via SSH from vagrant@192.168.200.1(192.168.200.1:22) to vagrant@192.168.200.2(192.168.200.2:22)..
Thu Apr 30 14:50:21 2020 - [debug]   ok.
Thu Apr 30 14:50:21 2020 - [debug]  Connecting via SSH from vagrant@192.168.200.1(192.168.200.1:22) to vagrant@192.168.200.3(192.168.200.3:22)..
Thu Apr 30 14:50:22 2020 - [debug]   ok.
Thu Apr 30 14:50:24 2020 - [debug] 
Thu Apr 30 14:50:21 2020 - [debug]  Connecting via SSH from vagrant@192.168.200.3(192.168.200.3:22) to vagrant@192.168.200.1(192.168.200.1:22)..
Thu Apr 30 14:50:22 2020 - [debug]   ok.
Thu Apr 30 14:50:22 2020 - [debug]  Connecting via SSH from vagrant@192.168.200.3(192.168.200.3:22) to vagrant@192.168.200.2(192.168.200.2:22)..
Thu Apr 30 14:50:24 2020 - [debug]   ok.
Thu Apr 30 14:50:24 2020 - [info] All SSH connection tests passed successfully.

[vagrant@manager mha]$ masterha_check_repl --conf=/etc/mha/mysql-mha.conf
Thu Apr 30 14:52:56 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Thu Apr 30 14:52:56 2020 - [info] Reading application default configuration from /etc/mha/mysql-mha.conf..
Thu Apr 30 14:52:56 2020 - [info] Reading server configuration from /etc/mha/mysql-mha.conf..
Thu Apr 30 14:52:56 2020 - [info] MHA::MasterMonitor version 0.58.
Thu Apr 30 14:52:57 2020 - [info] GTID failover mode = 1
Thu Apr 30 14:52:57 2020 - [info] Dead Servers:
Thu Apr 30 14:52:57 2020 - [info] Alive Servers:
Thu Apr 30 14:52:57 2020 - [info]   192.168.200.1(192.168.200.1:3306)
Thu Apr 30 14:52:57 2020 - [info]   192.168.200.2(192.168.200.2:3306)
Thu Apr 30 14:52:57 2020 - [info]   192.168.200.3(192.168.200.3:3306)
Thu Apr 30 14:52:57 2020 - [info] Alive Slaves:
Thu Apr 30 14:52:57 2020 - [info]   192.168.200.2(192.168.200.2:3306)  Version=8.0.20 (oldest major version between slaves) log-bin:enabled
Thu Apr 30 14:52:57 2020 - [info]     GTID ON
Thu Apr 30 14:52:57 2020 - [info]     Replicating from 192.168.200.1(192.168.200.1:3306)
Thu Apr 30 14:52:57 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Thu Apr 30 14:52:57 2020 - [info]   192.168.200.3(192.168.200.3:3306)  Version=8.0.20 (oldest major version between slaves) log-bin:enabled
Thu Apr 30 14:52:57 2020 - [info]     GTID ON
Thu Apr 30 14:52:57 2020 - [info]     Replicating from 192.168.200.1(192.168.200.1:3306)
Thu Apr 30 14:52:57 2020 - [info]     Not candidate for the new Master (no_master is set)
Thu Apr 30 14:52:57 2020 - [info] Current Alive Master: 192.168.200.1(192.168.200.1:3306)
Thu Apr 30 14:52:57 2020 - [info] Checking slave configurations..
Thu Apr 30 14:52:57 2020 - [info]  read_only=1 is not set on slave 192.168.200.2(192.168.200.2:3306).
Thu Apr 30 14:52:57 2020 - [info]  read_only=1 is not set on slave 192.168.200.3(192.168.200.3:3306).
Thu Apr 30 14:52:57 2020 - [info] Checking replication filtering settings..
Thu Apr 30 14:52:57 2020 - [info]  binlog_do_db= , binlog_ignore_db= 
Thu Apr 30 14:52:57 2020 - [info]  Replication filtering check ok.
Thu Apr 30 14:52:57 2020 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Thu Apr 30 14:52:57 2020 - [info] Checking SSH publickey authentication settings on the current master..
Thu Apr 30 14:52:58 2020 - [info] HealthCheck: SSH to 192.168.200.1 is reachable.
Thu Apr 30 14:52:58 2020 - [info] 
192.168.200.1(192.168.200.1:3306) (current master)
 +--192.168.200.2(192.168.200.2:3306)
 +--192.168.200.3(192.168.200.3:3306)

Thu Apr 30 14:52:58 2020 - [info] Checking replication health on 192.168.200.2..
Thu Apr 30 14:52:58 2020 - [info]  ok.
Thu Apr 30 14:52:58 2020 - [info] Checking replication health on 192.168.200.3..
Thu Apr 30 14:52:58 2020 - [info]  ok.
Thu Apr 30 14:52:58 2020 - [info] Checking master_ip_failover_script status:
Thu Apr 30 14:52:58 2020 - [info]   /usr/bin/master_ip_failover --command=status --ssh_user=vagrant --orig_master_host=192.168.200.1 --orig_master_ip=192.168.200.1 --orig_master_port=3306 


IN SCRIPT TEST====sudo /sbin/ifconfig eth1:1 down==sudo /sbin/ifconfig eth1:1 192.168.200.10/24===

Checking the Status of the script.. OK 
Thu Apr 30 14:52:58 2020 - [info]  OK.
Thu Apr 30 14:52:58 2020 - [warning] shutdown_script is not defined.
Thu Apr 30 14:52:58 2020 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.

我试着把主的mysql停掉, 发现没有切换到 192.168.200.2 ,发现 mysql-mha.master_status.health :

[vagrant@manager mha]$ cat mysql-mha.master_status.health 
26979	20:PING_FAILING	master:192.168.200.1

还有manager.log 一直重复输出这一段:

Thu Apr 30 14:56:05 2020 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.200.1' (111))
Thu Apr 30 14:56:05 2020 - [warning] Connection failed 2 time(s)..
Thu Apr 30 14:56:06 2020 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.200.1' (111))
Thu Apr 30 14:56:06 2020 - [warning] Connection failed 3 time(s)..
Thu Apr 30 14:56:07 2020 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.200.1' (111))
Thu Apr 30 14:56:07 2020 - [warning] Connection failed 4 time(s)..
Thu Apr 30 14:56:07 2020 - [warning] Secondary network check script returned errors. Failover should not start so checking server status again. Check network settings for details.
Thu Apr 30 14:56:08 2020 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.200.1' (111))
Thu Apr 30 14:56:08 2020 - [warning] Connection failed 1 time(s)..
Thu Apr 30 14:56:08 2020 - [info] Executing SSH check script: exit 0
Thu Apr 30 14:56:08 2020 - [info] Executing secondary network check script: /usr/bin/masterha_secondary_check -s 192.168.200.1 -s 192.168.200.2 -s 192.168.200.3  --user=vagrant  --master_host=192.168.200.1  --master_ip=192.168.200.1  --master_port=3306 --master_user=dba_mha --master_password=123456 --ping_type=SELECT
Thu Apr 30 14:56:08 2020 - [warning] HealthCheck: SSH to 192.168.200.1 is NOT reachable.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).^M
Monitoring server 192.168.200.1 is NOT reachable!
Thu Apr 30 14:56:08 2020 - [warning] At least one of monitoring servers is not reachable from this script. This is likely a network problem. Failover should not happen.

看着像是报错我SSH连接问题,但是我4台服务器,我都手动测试了 ssh vagrant@192.168.200.% 这种形式,都能连接成功,前面ssh检查也成功, 谷歌百度也查不到资料~ 不知道哪儿出问题了

/etc/mha/mysq-mha.conf

[server default]
user=dba_mha
password=123456
ssh_user=vagrant
ssh_port=22
repl_user=repl
repl_password=123456
manager_workdir=/home/vagrant/mha
manager_log=/home/vagrant/mha/manager.log
remote_workdir=/home/vagrant/mha
ping_interval=1
master_binlog_dir=/var/log/mysql
master_ip_failover_script=/usr/bin/master_ip_failover
secondary_check_script=/usr/bin/masterha_secondary_check -s 192.168.200.1 -s 192.168.200.2 -s 192.168.200.3
[server1]
hostname=192.168.200.1

[server2]
hostname=192.168.200.2
candidate_master=1

[server3]
hostname=192.168.200.3
no_master=1

其他都跟视频里一样的

正在回答

1回答

由于MHA要重新配置网卡IP,所以SSH账号一定要具有root权限, 所以建议使用root账号。

0 回复 有任何疑惑可以回复我~
  • 提问者 爱吃apple的阿狸 #1
    非常感谢!
    回复 有任何疑惑可以回复我~ 2020-05-01 15:40:45
  • 提问者 爱吃apple的阿狸 #2
    我换了root账号就好了
    回复 有任何疑惑可以回复我~ 2020-05-01 15:41:02
  • 提问者 爱吃apple的阿狸 #3
    那如果我宕机的master修复后,如何再加入集群呢, MHA会自动恢复么?
    回复 有任何疑惑可以回复我~ 2020-05-01 16:29:30
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信