使用MHA实现Mysql高可用

MHA工具由两部分组成:Manager管理端和node节点

环境统一用CentOS7,数据库用二进制安装的MySQL 5.7.34版本,安装过程参考安装文档章节
MHA manager: 10.10.6.187 MHA监控Manager节点
MySQL-01: 10.10.6.188 主从复制的主节点,MHA被监控node节点
MySQL-02: 10.10.6.189 主从复制的从节点,MHA被监控node节点
MySQL-03: 10.10.6.190 主从复制的从节点,MHA被监控node节点

注意,数据库版本不同与MHA版本不兼容,可能导致MHA检查不通过:

检查报错#Checking if super_read_only is defined and turned on…DBD::mysql::st execute failed: Unknown system variable ‘super_read_only’
Mariadb10.3.6 不支持 super_read_only,只能用mha4mysql-0.56
mysql5.7 支持 super_read_only,可以配合mha4mysql-0.58
show variables like ‘super_read_only’;或者select @@super_read_only;

下面是关于read_only和super_read_only的一段总结

read_only 表示是否允许普通用户写入。如果为on,表示禁止普通用户写入。
super_read_only 表示是否禁止超级用户写入,包括普通用户,即针对所有用户。 默认关闭。
如果打开 super_read_only,则read_only会自动打开。
如果关闭 read_only,则 super_read_only 会自动关闭。

MHA安装包下载地址:
https://github.com/yoshinorim/mha4mysql-manager/releases
https://github.com/yoshinorim/mha4mysql-node/releases

一、首先后面三台数据库做主从同步,采用半同步复制
主节点设置server_id,反向解析,中继日志、二进制日志,(只为了试验的话,server-id和skip_name_resolve即可)

$ cat /etc/my.cnf
[mysqld]
server-id=1
relay-log=relay-bin
log-bin=master-bin
skip_name_resolve

两个从节点,设置不同的server_id,中继日志、二进制日志,只读,不清除中继日志

[root@localhost]$ cat /etc/my.cnf
[ mysqld]
server-id=2  ##另外一个设为不同的
relay-log=relay-bin
log-bin=master-bin
read_only=1
relay_log_purge=0
skip_name_resolve

主节点授权同步的用户,授权mha用户

[root@localhost]$ mysql
mysql> grant all privileges on *.* to mhauser@'10.10.6.%' identified by '123123';
Query OK, 0 rows affected (0.02 sec)

mysql> grant replication slave on *.* to repluser@'10.10.6.189' identified by '123123';
Query OK, 0 rows affected (0.02 sec)

mysql> grant replication slave on *.* to repluser@'10.10.6.190' identified by '123123';
Query OK, 0 rows affected (0.06 sec)

mysql> flush  privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000001 |     451  |              |                  |                   |
+-------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)

mysql> select @@super_read_only, @@read_only;
+-------------------+-------------+
| @@super_read_only | @@read_only |
+-------------------+-------------+
|                 0 |           1 |
+-------------------+-------------+
1 row in set (0.00 sec)

两个从节点配置

[root@localhost]$ mysql
mysql> CHANGE MASTER TO
    ->   MASTER_HOST='10.10.6.188',          	#指定主服务器的地址
    ->   MASTER_USER='repluser',             	#指定同步用户
    ->   MASTER_PASSWORD='123123',           	#指定密码
    ->   MASTER_PORT=3306,                   	#指定端口,默认3306不设置即可
    ->   MASTER_LOG_FILE='master-bin.000001', 	#指定二进制文件,上一步master status的file
    ->   MASTER_LOG_POS=451;                	#指定起始位置,上一步master status的position
Query OK, 0 rows affected (0.02 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.10.6.188
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000001
          Read_Master_Log_Pos: 451
               Relay_Log_File: relay-bin.000002
                Relay_Log_Pos: 321
        Relay_Master_Log_File: master-bin.000001
             Slave_IO_Running: Yes				#这两个选项一定要是yes才会正常同步,IO线程
            Slave_SQL_Running: Yes				#这两个选项一定要是yes才会正常同步,SQL线程
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 451
              Relay_Log_Space: 522
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 1
                  Master_UUID: c9ccf7b6-7def-11ec-8b5e-000c29778521
             Master_Info_File: /data/mysql/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind: 
      Last_IO_Error_Timestamp: 
     Last_SQL_Error_Timestamp: 
               Master_SSL_Crl: 
           Master_SSL_Crlpath: 
           Retrieved_Gtid_Set: 
            Executed_Gtid_Set: 
                Auto_Position: 0
         Replicate_Rewrite_DB: 
                 Channel_Name: 
           Master_TLS_Version: 
1 row in set (0.00 sec)

++++++++++++++++++++++++++++++++++++++++++++++++++++++
排错:
报错:Last_IO_Error: Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work.

各个MySQL机器需要设置不同的UUID,修改mysql目录下的auto.cnf文件,不一致即可,然后重启mysql

mysql> show variables like '%server_uuid%'; 
+---------------+--------------------------------------+
| Variable_name | Value                                |
+---------------+--------------------------------------+
| server_uuid   | c9ccf7b6-7def-11ec-8b5e-000c29778521 |
+---------------+--------------------------------------+

报错:Got fatal error 1236 from master when reading data from binary log: ‘Could not find first log file name in binary log index file’

二进制文件没找到,CHANGE MASTER TO再检查一遍。stop slave,然后再配置slave

++++++++++++++++++++++++++++++++++++++++++++++++++++++

二、MHA安装包、安装依赖,所有节点安装node包,MHA监控节点安装Manager包

[root@localhost]$ yum -y install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager    ##node节点的依赖
[root@localhost]$ yum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN -y    ##manager节点的依赖

[root@localhost]$ yum install -y mha4mysql-node-0.58-0.el7.centos.noarch.rpm  		##所有节点安装
[root@localhost]$ yum install -y mha4mysql-manager-0.58-0.el7.centos.noarch.rpm		##监控节点安装

三、监控的过程依赖ssh,所以要做基于key验证
在监控manager节点生成key,发送给自己

[root@localhost]$ ssh-keygen   ##一路回车
[root@localhost]$ ssh-copy-id 10.10.6.187

发送到node节点

[root@localhost]$ cd ~
[root@localhost]$ scp -r .ssh/ root@10.10.6.188:/root/
[root@localhost]$ scp -r .ssh/ root@10.10.6.189:/root/
[root@localhost]$ scp -r .ssh/ root@10.10.6.190:/root/

四、在监控manager节点上编辑配置文件,如果监控的主从有很多组,配置文件在/etc/mastermha下,如果只监控一组主从,默认配置文件为/etc/mastermha_drfault.cnf

[root@localhost]$ mkdir /etc/mastermha
[root@localhost]$ vim /etc/mastermha/app1.cnf
[server default]
user=mhauser
password=123123
manager_workdir=/data/mastermha/app1/
manager_log=/data/mastermha/app1/manager.log
remote_workdir=/data/mastermha/app1/
master_binlog_dir=/data/mysql/data
ssh_user=root
repl_user=repluser
repl_password=123123
ping_interval=1
[server1]
hostname=10.10.6.188

[server2]
hostname=10.10.6.189
candidate_master=1

[server3]
hostname=10.10.6.190
candidate_master=1

测试ssh连接是否正常

[root@localhost]$ masterha_check_ssh --conf /etc/mastermha/app1.cnf
Tue Dec 21 15:27:11 2021 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Tue Dec 21 15:27:11 2021 - [info] Reading application default configuration from /etc/mastermha/app1.cnf..
Tue Dec 21 15:27:11 2021 - [info] Reading server configuration from /etc/mastermha/app1.cnf..
Tue Dec 21 15:27:11 2021 - [info] Starting SSH connection tests..
Tue Dec 21 15:27:11 2021 - [debug] 
Tue Dec 21 15:27:11 2021 - [debug]  Connecting via SSH from root@10.10.6.188(10.10.6.188:22) to root@10.10.6.189(10.10.6.189:22)..
Tue Dec 21 15:27:11 2021 - [debug]   ok.
Tue Dec 21 15:27:11 2021 - [debug]  Connecting via SSH from root@10.10.6.188(10.10.6.188:22) to root@10.10.6.190(10.10.6.190:22)..
Tue Dec 21 15:27:11 2021 - [debug]   ok.
Tue Dec 21 15:27:12 2021 - [debug] 
Tue Dec 21 15:27:11 2021 - [debug]  Connecting via SSH from root@10.10.6.189(10.10.6.189:22) to root@10.10.6.188(10.10.6.188:22)..
Tue Dec 21 15:27:11 2021 - [debug]   ok.
Tue Dec 21 15:27:11 2021 - [debug]  Connecting via SSH from root@10.10.6.189(10.10.6.189:22) to root@10.10.6.190(10.10.6.190:22)..
Tue Dec 21 15:27:11 2021 - [debug]   ok.
Tue Dec 21 15:27:12 2021 - [debug] 
Tue Dec 21 15:27:12 2021 - [debug]  Connecting via SSH from root@10.10.6.190(10.10.6.190:22) to root@10.10.6.188(10.10.6.188:22)..
Tue Dec 21 15:27:12 2021 - [debug]   ok.
Tue Dec 21 15:27:12 2021 - [debug]  Connecting via SSH from root@10.10.6.190(10.10.6.190:22) to root@10.10.6.189(10.10.6.189:22)..
Tue Dec 21 15:27:12 2021 - [debug]   ok.
Tue Dec 21 15:27:12 2021 - [info] All SSH connection tests passed successfully.

测试主从同步是否正常,这一步是最容器出现错误的,坑无数

[root@localhost]$ masterha_check_repl --conf /etc/mastermha/app1.cnf
Fri Sep  7 09:53:22 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Fri Sep  7 09:53:22 2018 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Fri Sep  7 09:53:22 2018 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Fri Sep  7 09:53:22 2018 - [info] MHA::MasterMonitor version 0.56.
Fri Sep  7 09:53:23 2018 - [info] GTID failover mode = 0
Fri Sep  7 09:53:23 2018 - [info] Dead Servers:
Fri Sep  7 09:53:23 2018 - [info] Alive Servers:
Fri Sep  7 09:53:23 2018 - [info]   192.168.5.51(192.168.5.51:9106)
Fri Sep  7 09:53:23 2018 - [info]   192.168.5.52(192.168.5.52:9106)
Fri Sep  7 09:53:23 2018 - [info]   192.168.5.53(192.168.5.53:9106)
Fri Sep  7 09:53:23 2018 - [info] Alive Slaves:
Fri Sep  7 09:53:23 2018 - [info]   192.168.5.52(192.168.5.52:9106)  Version=10.3.6-MariaDB-log (oldest major version between slaves) log-bin:enabled
Fri Sep  7 09:53:23 2018 - [info]     Replicating from 192.168.5.51(192.168.5.51:9106)
Fri Sep  7 09:53:23 2018 - [info]     Primary candidate for the new Master (candidate_master is set)
Fri Sep  7 09:53:23 2018 - [info]   192.168.5.53(192.168.5.53:9106)  Version=10.3.6-MariaDB-log (oldest major version between slaves) log-bin:enabled
Fri Sep  7 09:53:23 2018 - [info]     Replicating from 192.168.5.51(192.168.5.51:9106)
Fri Sep  7 09:53:23 2018 - [info] Current Alive Master: 192.168.5.51(192.168.5.51:9106)
Fri Sep  7 09:53:23 2018 - [info] Checking slave configurations..
Fri Sep  7 09:53:23 2018 - [info] Checking replication filtering settings..
Fri Sep  7 09:53:23 2018 - [info]  binlog_do_db= , binlog_ignore_db= information_schema,mysql,performance_schema,test
Fri Sep  7 09:53:23 2018 - [info]  Replication filtering check ok.
Fri Sep  7 09:53:23 2018 - [info] GTID (with auto-pos) is not supported
Fri Sep  7 09:53:23 2018 - [info] Starting SSH connection tests..
Fri Sep  7 09:53:27 2018 - [info] All SSH connection tests passed successfully.
Fri Sep  7 09:53:27 2018 - [info] Checking MHA Node version..
Fri Sep  7 09:53:28 2018 - [info]  Version check ok.
Fri Sep  7 09:53:28 2018 - [info] Checking SSH publickey authentication settings on the current master..
Fri Sep  7 09:53:28 2018 - [info] HealthCheck: SSH to 192.168.5.51 is reachable.
Fri Sep  7 09:53:29 2018 - [info] Master MHA Node version is 0.56.
Fri Sep  7 09:53:29 2018 - [info] Checking recovery script configurations on 192.168.5.51(192.168.5.51:9106)..
Fri Sep  7 09:53:29 2018 - [info]   Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/data/mysql/binlog --output_file=/data/mysql/binlog/save_binary_logs_test --manager_version=0.56 --start_file=mysql-bin.000004 
Fri Sep  7 09:53:29 2018 - [info]   Connecting to root@192.168.5.51(192.168.5.51:65535).. 
  Creating /data/mysql/binlog if not exists..    ok.
  Checking output directory is accessible or not..
   ok.
  Binlog found at /data/mysql/binlog, up to mysql-bin.000004
Fri Sep  7 09:53:29 2018 - [info] Binlog setting check done.
Fri Sep  7 09:53:29 2018 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Fri Sep  7 09:53:29 2018 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='blufly' --slave_host=192.168.5.52 --slave_ip=192.168.5.52 --slave_port=9106 --workdir=/data/mysql/binlog --target_version=10.3.6-MariaDB-log --manager_version=0.56 --relay_log_info=/data/mysql/relay-log.info  --relay_dir=/data/mysql/  --slave_pass=xxx
Fri Sep  7 09:53:29 2018 - [info]   Connecting to root@192.168.5.52(192.168.5.52:65535).. 
  Checking slave recovery environment settings..
    Opening /data/mysql/relay-log.info ... ok.
    Relay log found at /data/mysql/binlog, up to mysql-relay-bin.000003
    Temporary relay log file is /data/mysql/binlog/mysql-relay-bin.000003
    Testing mysql connection and privileges.. done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Fri Sep  7 09:53:30 2018 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='blufly' --slave_host=192.168.5.53 --slave_ip=192.168.5.53 --slave_port=9106 --workdir=/data/mysql/binlog --target_version=10.3.6-MariaDB-log --manager_version=0.56 --relay_log_info=/data/mysql/relay-log.info  --relay_dir=/data/mysql/  --slave_pass=xxx
Fri Sep  7 09:53:30 2018 - [info]   Connecting to root@192.168.5.53(192.168.5.53:65535).. 
  Checking slave recovery environment settings..
    Opening /data/mysql/relay-log.info ... ok.
    Relay log found at /data/mysql/binlog, up to mysql-relay-bin.000003
    Temporary relay log file is /data/mysql/binlog/mysql-relay-bin.000003
    Testing mysql connection and privileges.. done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Fri Sep  7 09:53:30 2018 - [info] Slaves settings check done.
Fri Sep  7 09:53:30 2018 - [info] 
192.168.5.51(192.168.5.51:9106) (current master)
 +--192.168.5.52(192.168.5.52:9106)
 +--192.168.5.53(192.168.5.53:9106)
Fri Sep  7 09:53:30 2018 - [info] Checking replication health on 192.168.5.52..
Fri Sep  7 09:53:30 2018 - [info]  ok.
Fri Sep  7 09:53:30 2018 - [info] Checking replication health on 192.168.5.53..
Fri Sep  7 09:53:30 2018 - [info]  ok.
Fri Sep  7 09:53:30 2018 - [info] Checking master_ip_failover_script status:
Fri Sep  7 09:53:30 2018 - [info]   /usr/local/bin/master_ip_failover --command=status --ssh_user=root --orig_master_host=192.168.5.51 --orig_master_ip=192.168.5.51 --orig_master_port=9106  --orig_master_ssh_port=65535
Unknown option: orig_master_ssh_port
IN SCRIPT TEST====/etc/init.d/keepalived stop==/etc/init.d/keepalived start===
Checking the Status of the script.. OK 
Fri Sep  7 09:53:30 2018 - [info]  OK.
Fri Sep  7 09:53:30 2018 - [warning] shutdown_script is not defined.
Fri Sep  7 09:53:30 2018 - [info] Got exit code 0 (Not master dead).
MySQL Replication Health is OK.

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
排错

Can't exec "mysqlbinlog": No such file or directory at /usr/share/perl5/vendor_perl/MHA/BinlogManager.pm line 106.
mysqlbinlog version command failed with rc 1:0, please verify PATH, LD_LIBRARY_PATH, and client options
 at /usr/bin/apply_diff_relay_logs line 532.

默认的路径下找不到mysqlbinlog命令,所有节点做个软连接
ln -sv /usr/local/mysql/bin/mysqlbinlog /usr/local/bin/mysqlbinlog
sh: mysql: command not found
mysql command failed with rc 127:0!
 at /usr/bin/apply_diff_relay_logs line 404.
	main::check() called at /usr/bin/apply_diff_relay_logs line 536
	eval {...} called at /usr/bin/apply_diff_relay_logs line 514
	main::main() called at /usr/bin/apply_diff_relay_logs line 121


MHA走系统默认去/usr/bin下找mysql命令,所有节点做个软连接
ln -sv /usr/local/mysql/bin/mysql /usr/bin/mysql

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

六、开启MHA监控服务

故障切换备选主库的算法:

1、一般判断从库的是从(position/GTID)判断优劣,数据有差异,最接近于master的slave,成为备选主。
2、数据一致的情况下,按照配置文件顺序,选择备选主库。
3、设定有权重(candidate_master=1),按照权重强制指定备选主。
默认情况下如果一个slave落后master 100M的relay logs的话,即使有权重,也会失效。
如果check_repl_delay=0的话,即使落后很多日志,也强制选择其为备选主。

启动命令

  • –ignore_last_failover:在默认情况下,如果 MHA 检测到连续发生宕机,且两次宕机间隔不足 8 小时的话,则不会进行 Failover, 之所以这样限制是为了避免 ping-pong 效应。
    该参数代表忽略上次 MHA 触发切换产生的文件,默认情况下,MHA发生切换后会在日志记目录,下次再次切换的时候如果发现该目录下存在该文件将不允许触发切换,除非在第一次切换后收到删除该文件,为了方便,这里设置为–ignore_last_failover。
[root@localhost]$ nohup masterha_manager --conf=/etc/mastermha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null &
[1] 19926


[root@localhost]$ tail -f manager.log
10.10.6.188(10.10.6.188:3306) (current master)
 +--10.10.6.189(10.10.6.189:3306)
 +--10.10.6.190(10.10.6.190:3306)

Wed Jan 26 01:23:37 2022 - [warning] master_ip_failover_script is not defined.
Wed Jan 26 01:23:37 2022 - [warning] shutdown_script is not defined.
Wed Jan 26 01:23:37 2022 - [info] Set master ping interval 1 seconds.
Wed Jan 26 01:23:37 2022 - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from two or more routes.
Wed Jan 26 01:23:37 2022 - [info] Starting ping health check on 10.10.6.188(10.10.6.188:3306)..
Wed Jan 26 01:23:37 2022 - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond..

查看状态的命令

比如查看主节点是谁,状态如何
[root@localhost]$ masterha_check_status --conf=/etc/mastermha/app1.cnf
app1 (pid:19926) is running(0:PING_OK), master:10.10.6.188

[root@localhost]$ tail -f manager.log | grep "current master"
10.10.6.188(10.10.6.188:3306) (current master)

停止MHA监控的命令

masterha_stop --conf=/etc/mastermha/app1.cnf
Stopped app1 successfully.
[1]+  Exit 1                  nohup masterha_manager --conf=/etc/mastermha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/masterha/app1/manager.log

七、模拟宕机,测试主节点转移
主节点宕机

[root@localhost data]# service mysqld stop
Shutting down MySQL............ SUCCESS! 

此时在监控节点查看MHA进程已关闭,通过日志可以看到转移的过程

[root@localhost data]# ps -ef | grep mastermha

[root@localhost data]# tail -fn 500 /data/mastermha/app1/manager.log
...
...
...
Wed Jan 26 01:32:24 2022 - [info]  Non-candidate masters:
Wed Jan 26 01:32:24 2022 - [info]  Searching from candidate_master slaves which have received the latest relay log events..
Wed Jan 26 01:32:24 2022 - [info] New master is 10.10.6.189(10.10.6.189:3306)
Wed Jan 26 01:32:24 2022 - [info] Starting master failover..
Wed Jan 26 01:32:24 2022 - [info] 
From:
10.10.6.188(10.10.6.188:3306) (current master)
 +--10.10.6.189(10.10.6.189:3306)
 +--10.10.6.190(10.10.6.190:3306)

To:
10.10.6.189(10.10.6.189:3306) (new master)
 +--10.10.6.190(10.10.6.190:3306)
...
...
...
----- Failover Report -----

app1: MySQL Master failover 10.10.6.188(10.10.6.188:3306) to 10.10.6.189(10.10.6.189:3306) succeeded

Master 10.10.6.188(10.10.6.188:3306) is down!

Check MHA Manager logs at localhost.localdomain:/data/mastermha/app1/manager.log for details.

Started automated(non-interactive) failover.
The latest slave 10.10.6.189(10.10.6.189:3306) has all relay logs for recovery.
Selected 10.10.6.189(10.10.6.189:3306) as a new master.
10.10.6.189(10.10.6.189:3306): OK: Applying all logs succeeded.
10.10.6.190(10.10.6.190:3306): This host has the latest relay log events.
Generating relay diff files from the latest slave succeeded.
10.10.6.190(10.10.6.190:3306): OK: Applying all logs succeeded. Slave started, replicating from 10.10.6.189(10.10.6.189:3306)
10.10.6.189(10.10.6.189:3306): Resetting slave info succeeded.
Master failover to 10.10.6.189(10.10.6.189:3306) completed successfully.

在第三个节点,查看slave状态,指向新的master节点,此时的主节点是只读的,如果要长期做为主的话,要去除配置文件的read-only选项,再修改MHA的app1.cnf文件,把修复好的原主节点加入,变成了从节点

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.10.6.189
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: master-bin.000002
          Read_Master_Log_Pos: 154
               Relay_Log_File: relay-bin.000002
                Relay_Log_Pos: 321
        Relay_Master_Log_File: master-bin.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 154
              Relay_Log_Space: 522
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
  Replicate_Ignore_Server_Ids: 
             Master_Server_Id: 2
                  Master_UUID: c9ccf7b6-7def-11ec-8b5e-000c29778522
             Master_Info_File: /data/mysql/data/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
1 row in set (0.00 sec)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值