欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mysql——MHA高可用配置及故障切换

程序员文章站 2022-04-09 21:33:37
...

一、MHA概述

1.1 什么是MHA?

  • 一套优秀的MySQL高可用环境下故障切换和主从复制的软件
  • 支持故障切换
  • MySQL故障过程中,MHA能做到0-30秒内自动完成故障切换,并且在进行故障切换的过程中,MHA能在最大程度上保证数据的一致性,以达到真正意义上的高可用
  • MHA还提供在线主库切换的功能,能够安全地切换当前运行的主库到一个新的主库中(通过将从库提升为主库),大概0.5-2秒内即可完成

1.2 MHA的组成

  • MHA Manager (管理节点):用来接收外部信号,监控下方数据节点的工作状态
  • MHA Node (数据节点):工作的单位,负责具体的工作

1.3 MHA有什么特点?

  • 自动故障切换过程中,MHA试图从宕机的主服务器上保存二进制日志,最大程度的保证数据的不丢失
  • 使用半同步复制,可以大大降低数据丢失的风险
  • 目前MHA支持一主多从架构,最少三台服务,即一主两从

1.4:MHA形成的原因

传统mysql主从架构存在单点故障的问题
单点故障,主服务器宕机,则服务挂掉
mysql——MHA高可用配置及故障切换

二、MHA实验

2.1 实验环境

VMware软件
一台centos7.6作为MHA服务器
三台centos7.6作为主服务器主备服务器从服务器
manager服务器192.168.200.40
master主服务器192.168.200.90
slave/master主备/从服务器192.168.200.80
slave从192.168.200.110

实验拓扑

mysql——MHA高可用配置及故障切换

实验步骤

1、配置主从同步

主服务器
[aaa@qq.com ~]# iptables -F
[aaa@qq.com ~]# setenforce 0
[aaa@qq.com ~]# hostnamectl set-hostname Mysql1
[aaa@qq.com ~]# su
[aaa@qq.com ~]# vim /etc/my.cnf
[client]
port=3306
default-character-set=utf8
socket=/usr/local/mysql/mysql.sock

[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
character_set_server=utf8mb4
pid-file=/usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
server-id=1
log_bin=master-bin
log-slave-updates=ture   

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
       
[aaa@qq.com ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
[aaa@qq.com ~]# ln -s /usr/local/mysql/bin/mysqlbinlog /usr/bin/
[aaa@qq.com ~]# systemctl restart mysqld
[aaa@qq.com ~]# netstat -antp | grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      94409/mysqld   
[aaa@qq.com ~]# mysql -uroot -pabc123
mysql> grant replication slave on *.* to 'myslave'@'192.168.200.%' identified by '123';
mysql> grant all privileges on *.* to 'mha'@'192.168.200.%' identified by 'manager';
mysql> flush privileges;
mysql> grant all privileges on *.* to 'mha'@'Mysql1' identified by 'manager';
mysql> grant all privileges on *.* to 'mha'@'Mysql2' identified by 'manager';
mysql> grant all privileges on *.* to 'mha'@'Mysql3' identified by 'manager';
mysql> flush privileges;
mysql> show master status;
+-------------------+----------+--------------+------------------+-------------------+
| File              | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-------------------+----------+--------------+------------------+-------------------+
| master-bin.000001 |     1899 |              |                  |                   |
+-------------------+----------+--------------+------------------+-------------------+
主备服务器
[aaa@qq.com ~]# iptables -F
[aaa@qq.com ~]# setenforce 0
[aaa@qq.com ~]# hostnamectl set-hostname Mysql2
[aaa@qq.com ~]# su
[aaa@qq.com ~]# vim /etc/my.cnf
[client]
port=3306
socket=/usr/local/mysql/mysql.sock

[mysql]
port=3306
default-character-set=utf8mb4                        
socket=/usr/local/mysql/mysql.sock

[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
character_set_server=utf8mb4                         
pid-file=/usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
server-id=2                                          
log_bin=master-bin                                      
relay-log=relay-log-bin                               
relay-log-index=slave-relay-bin.index

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
[aaa@qq.com ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
[aaa@qq.com ~]# ln -s /usr/local/mysql/bin/mysqlbinlog /usr/bin/
[aaa@qq.com ~]# systemctl restart mysqld
[aaa@qq.com ~]# netstat -antp | grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      88672/mysqld        
[aaa@qq.com ~]# mysql -uroot -pabc123
mysql> grant replication slave on *.* to 'myslave'@'192.168.200.%' identified by '123';
mysql>  grant all privileges on *.* to 'mha'@'192.168.200.%' identified by 'manager';
mysql> flush privileges;
mysql> grant all privileges on *.* to 'mha'@'Mysql1' identified by 'manager';
mysql> grant all privileges on *.* to 'mha'@'Mysql2' identified by 'manager';
mysql> grant all privileges on *.* to 'mha'@'Mysql3' identified by 'manager';
mysql> flush privileges;
mysql> change master to master_host='192.168.200.90',master_user='myslave',master_password='123',master_log_file='master-bin.000001',master_log_pos=1899;
mysql> flush privileges;
mysql> start slave;
mysql> show slave status\G;
  Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
mysql> set global read_only=1;
mysql> flush privileges;
从服务器
[aaa@qq.com ~]# iptables -F
[aaa@qq.com ~]# setenforce 0
[aaa@qq.com ~]# hostnamectl set-hostname Mysql3
[aaa@qq.com ~]# su
[aaa@qq.com ~]# vim /etc/my.cnf
[client]
port=3306
socket=/usr/local/mysql/mysql.sock

[mysql]
port=3306
default-character-set=utf8mb4
socket=/usr/local/mysql/mysql.sock

[mysqld]
user=mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port=3306
character-set-server = utf8mb4
pid-file=/usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
server-id=3
log_bin=master-bin
relay-log=relay-log-bin
relay-log-index=slave-relay-bin.index

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
[aaa@qq.com ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
[aaa@qq.com ~]# ln -s /usr/local/mysql/bin/mysqlbinlog /usr/bin/
[aaa@qq.com ~]# systemctl restart mysqld
[aaa@qq.com ~]# netstat -antp | grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      90340/mysqld        
[aaa@qq.com ~]# mysql -uroot -pabc123
mysql> grant replication slave on *.* to 'myslave'@'192.168.200.%' identified by '123';
mysql>  grant all privileges on *.* to 'mha'@'192.168.200.%' identified by 'manager';
mysql> flush privileges;
mysql> grant all privileges on *.* to 'mha'@'Mysql1' identified by 'manager';
mysql> grant all privileges on *.* to 'mha'@'Mysql2' identified by 'manager';
mysql> grant all privileges on *.* to 'mha'@'Mysql3' identified by 'manager';
mysql> flush privileges;
mysql> change master to master_host='192.168.200.90',master_user='myslave',master_password='123',master_log_file='master-bin.000001',master_log_pos=1899;
mysql> flush privileges;
mysql> start slave;
mysql> show slave status\G;
  Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
mysql> set global read_only=1;
mysql> flush privileges;

主从同步完成,进行验证,没问题
2、主从服务器安装mha的node文件,并进行ssh免密登录授权配置

主服务器
[aaa@qq.com ~]# yum -y install epel-release --nogpgcheck
[aaa@qq.com ~]# yum -y install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN
[aaa@qq.com ~]# ls
anaconda-ks.cfg                mha4mysql-node-0.58.tar.gz  模板  文档  桌面
initial-setup-ks.cfg           mysql-boost-5.7.20.tar.gz   视频  下载
mha4mysql-manager-0.58.tar.gz  公共                        图片  音乐
[aaa@qq.com ~]# tar zxvf mha4mysql-node-0.58.tar.gz 
[aaa@qq.com ~]# ls
anaconda-ks.cfg                mha4mysql-node-0.58         公共  图片  音乐
initial-setup-ks.cfg           mha4mysql-node-0.58.tar.gz  模板  文档  桌面
mha4mysql-manager-0.58.tar.gz  mysql-boost-5.7.20.tar.gz   视频  下载
[aaa@qq.com ~]# cd mha4mysql-node-0.58/
[aaa@qq.com mha4mysql-node-0.58]# ls
AUTHORS  COPYING  inc  Makefile.PL  META.yml  rpm
bin      debian   lib  MANIFEST     README    t
[aaa@qq.com mha4mysql-node-0.58]# perl Makefile.PL 
[aaa@qq.com mha4mysql-node-0.58]# make
[aaa@qq.com mha4mysql-node-0.58]# make install               //安装完成
[aaa@qq.com mha4mysql-node-0.58]# cd ~                      //主服务器设置两台从服务器免密登录
[aaa@qq.com ~]# ssh-****** -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:pq5JMOsg65ZZWe83MpKFMf8EGGr5u4SgMIrVqyC2Hwc aaa@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|     .           |
|    o o          |
|   = = .         |
|o.=E= * S        |
|=o.*o+ * .       |
|O.=ooo* o        |
|+O.o+* + +       |
|+o+.oo+ + .      |
+----[SHA256]-----+
[aaa@qq.com ~]# ssh-copy-id 192.168.200.80 						     //授权两台从服务器免密登录
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.200.80 (192.168.200.80)' can't be established.
ECDSA key fingerprint is SHA256:N5nxR2HffZdSxo0zaKcWTafbevqnrjCj2ULe0dVdPa0.
ECDSA key fingerprint is MD5:78:58:0a:09:66:76:ad:7a:02:28:15:2b:f7:57:2c:ef.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
aaa@qq.com.168.200.80's password: 
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh '192.168.200.80'"
and check to make sure that only the key(s) you wanted were added.
[aaa@qq.com ~]# ssh-copy-id 192.168.200.110                                                  //授权
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.200.110 (192.168.200.110)' can't be established.
ECDSA key fingerprint is SHA256:eLdHi9BvCNVro0zGiYPq1F+Psfoo9V+9EDIvdZDR8vM.
ECDSA key fingerprint is MD5:2d:34:ae:97:fd:bc:af:4f:e1:6b:92:22:48:4d:69:b4.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
aaa@qq.com.168.200.110's password: 
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh '192.168.200.110'"
and check to make sure that only the key(s) you wanted were added.

主备服务器配置主从的免密登录
[aaa@qq.com ~]# yum -y install epel-release --nogpgcheck
[aaa@qq.com ~]# yum -y install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN
[aaa@qq.com ~]# ls
anaconda-ks.cfg                mha4mysql-node-0.58.tar.gz  模板  文档  桌面
initial-setup-ks.cfg           mysql-boost-5.7.20.tar.gz   视频  下载
mha4mysql-manager-0.58.tar.gz  公共                        图片  音乐
[aaa@qq.com ~]# tar zxvf mha4mysql-node-0.58.tar.gz 
[aaa@qq.com ~]# ls
anaconda-ks.cfg                mha4mysql-node-0.58         公共  图片  音乐
initial-setup-ks.cfg           mha4mysql-node-0.58.tar.gz  模板  文档  桌面
mha4mysql-manager-0.58.tar.gz  mysql-boost-5.7.20.tar.gz   视频  下载
[aaa@qq.com ~]# cd mha4mysql-node-0.58/
[aaa@qq.com mha4mysql-node-0.58]# ls
AUTHORS  COPYING  inc  Makefile.PL  META.yml  rpm
bin      debian   lib  MANIFEST     README    t
[aaa@qq.com mha4mysql-node-0.58]# perl Makefile.PL 
[aaa@qq.com mha4mysql-node-0.58]# make
[aaa@qq.com mha4mysql-node-0.58]# make install
[aaa@qq.com mha4mysql-node-0.58]# cd ~
[aaa@qq.com ~]# ssh-****** -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Lsqb7sgFSaGVOVRmGeg8UW9c8q8AjwkHYLHYfnKnSak aaa@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|.=***o. .        |
|o+B=.o +         |
|o++oo + .        |
| o++ B   .       |
|  =.B + S .      |
|   B + o .       |
|  E + . o        |
| . + o .         |
|  ooB.           |
+----[SHA256]-----+
[aaa@qq.com ~]# ssh-copy-id 192.168.200.90
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.200.90 (192.168.200.90)' can't be established.
ECDSA key fingerprint is SHA256:LGVQSrzmeWOjKsn2nM6C187BdfANy9jsFvmzXotxD7M.
ECDSA key fingerprint is MD5:d2:cd:3a:66:ab:05:b8:16:f8:42:4a:88:4c:60:14:b4.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
aaa@qq.com's password: 
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh '192.168.200.90'"
and check to make sure that only the key(s) you wanted were added.

[aaa@qq.com ~]# ssh-copy-id 192.168.200.110
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.200.110 (192.168.200.110)' can't be established.
ECDSA key fingerprint is SHA256:eLdHi9BvCNVro0zGiYPq1F+Psfoo9V+9EDIvdZDR8vM.
ECDSA key fingerprint is MD5:2d:34:ae:97:fd:bc:af:4f:e1:6b:92:22:48:4d:69:b4.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
aaa@qq.com's password: 
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh '192.168.200.110'"
and check to make sure that only the key(s) you wanted were added.

从服务器配置主从的免密登录
[aaa@qq.com ~]# yum -y install epel-release --nogpgcheck
[aaa@qq.com ~]# yum -y install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN
[aaa@qq.com ~]# ls
anaconda-ks.cfg                mha4mysql-node-0.58.tar.gz  模板  文档  桌面
initial-setup-ks.cfg           mysql-boost-5.7.20.tar.gz   视频  下载
mha4mysql-manager-0.58.tar.gz  公共                        图片  音乐
[aaa@qq.com ~]# tar zxvf mha4mysql-node-0.58.tar.gz 
[aaa@qq.com ~]# ls
anaconda-ks.cfg                mha4mysql-node-0.58         公共  图片  音乐
initial-setup-ks.cfg           mha4mysql-node-0.58.tar.gz  模板  文档  桌面
mha4mysql-manager-0.58.tar.gz  mysql-boost-5.7.20.tar.gz   视频  下载
[aaa@qq.com ~]# cd mha4mysql-node-0.58/
[aaa@qq.com mha4mysql-node-0.58]# ls
AUTHORS  COPYING  inc  Makefile.PL  META.yml  rpm
bin      debian   lib  MANIFEST     README    t
[aaa@qq.com mha4mysql-node-0.58]# perl Makefile.PL 
[aaa@qq.com mha4mysql-node-0.58]# make
[aaa@qq.com mha4mysql-node-0.58]# make install
[aaa@qq.com mha4mysql-node-0.58]# cd ~
[aaa@qq.com ~]# ssh-****** -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:q4W5zpTErDyE8QrhMxrXlL/BXGMO3fteP2SMELquimk aaa@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|     . . . .     |
|. . o . = o .    |
|.. * * = o o     |
|o+o + O S o . o  |
|.+o+ o * o . . + |
|. . + * +   . +  |
|   Eo+ + . . . o |
|  .o o*..   .   o|
+----[SHA256]-----+
[aaa@qq.com ~]# ssh-copy-id 192.168.200.90
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.200.90 (192.168.200.90)' can't be established.
ECDSA key fingerprint is SHA256:LGVQSrzmeWOjKsn2nM6C187BdfANy9jsFvmzXotxD7M.
ECDSA key fingerprint is MD5:d2:cd:3a:66:ab:05:b8:16:f8:42:4a:88:4c:60:14:b4.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
aaa@qq.com.168.200.90's password: 
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh '192.168.200.90'"
and check to make sure that only the key(s) you wanted were added.
[aaa@qq.com ~]# ssh-copy-id 192.168.200.80
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.200.80 (192.168.200.80)' can't be established.
ECDSA key fingerprint is SHA256:N5nxR2HffZdSxo0zaKcWTafbevqnrjCj2ULe0dVdPa0.
ECDSA key fingerprint is MD5:78:58:0a:09:66:76:ad:7a:02:28:15:2b:f7:57:2c:ef.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
aaa@qq.com.168.200.80's password: 
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh '192.168.200.80'"
and check to make sure that only the key(s) you wanted were added.

3、配置manager服务器 安装mha

[aaa@qq.com ~]# iptables -F
[aaa@qq.com ~]# setenforce 0
[aaa@qq.com ~]# hostnamectl set-hostname mha
[aaa@qq.com ~]# su
[aaa@qq.com ~]# yum -y install epel-release --nogpgcheck
[aaa@qq.com ~]# yum -y install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN
[aaa@qq.com ~]# ls
anaconda-ks.cfg                mha4mysql-node-0.58.tar.gz  模板  文档  桌面
initial-setup-ks.cfg           mysql-boost-5.7.20.tar.gz   视频  下载
mha4mysql-manager-0.58.tar.gz  公共                        图片  音乐
[aaa@qq.com ~]# tar zxvf mha4mysql-node-0.58.tar.gz 
[aaa@qq.com ~]# ls
anaconda-ks.cfg                mha4mysql-node-0.58         公共  图片  音乐
initial-setup-ks.cfg           mha4mysql-node-0.58.tar.gz  模板  文档  桌面
mha4mysql-manager-0.58.tar.gz  mysql-boost-5.7.20.tar.gz   视频  下载
[aaa@qq.com ~]# cd mha4mysql-node-0.58/
[aaa@qq.com mha4mysql-node-0.58]# ls
AUTHORS  COPYING  inc  Makefile.PL  META.yml  rpm
bin      debian   lib  MANIFEST     README    t
[aaa@qq.com mha4mysql-node-0.58]# perl Makefile.PL 
[aaa@qq.com mha4mysql-node-0.58]# make
[aaa@qq.com mha4mysql-node-0.58]# make install
[aaa@qq.com mha4mysql-node-0.58]# cd ~
[aaa@qq.com ~]# tar zxvf mha4mysql-manager-0.58.tar.gz 
[aaa@qq.com ~]# cd mha4mysql-manager-0.58/
[aaa@qq.com mha4mysql-manager-0.58]# perl Makefile.PL 
[aaa@qq.com mha4mysql-manager-0.58]# make
[aaa@qq.com mha4mysql-manager-0.58]# make install
[aaa@qq.com mha4mysql-manager-0.58]# ls /usr/local/bin/                          //检查生成的工具
apply_diff_relay_logs        masterha_conf_host              masterha_stop
filter_mysqlbinlog            masterha_manager                purge_relay_logs
masterha_check_repl        masterha_master_monitor    save_binary_logs
masterha_check_ssh         masterha_master_switch
masterha_check_status    masterha_secondary_check
[aaa@qq.com mha4mysql-manager-0.58]# ssh-****** -t rsa                  //一路回车
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:5Gqwpw8/N22M1P654zTqxzWfaGq3hnfDgw/ORwvqcXI aaa@qq.com
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|                 |
|        .        |
|       o         |
|    .   S.       |
|     o .. .  .o. |
|    o +. = +=E*oo|
|     *. + =*@X.O.|
|    ..oo +=*@*=.o|
+----[SHA256]-----+
[aaa@qq.com mha4mysql-manager-0.58]# cd ~
[aaa@qq.com ~]# ls -a
.                .bash_history  .bashrc  .cshrc     .ICEauthority         mha4mysql-manager-0.58         mha4mysql-node-0.58.tar.gz  .tcshrc      公共  图片  音乐
..               .bash_logout   .cache   .dbus      initial-setup-ks.cfg  mha4mysql-manager-0.58.tar.gz  .pki                        .viminfo     模板  文档  桌面
anaconda-ks.cfg  .bash_profile  .config  .esd_auth  .local                mha4mysql-node-0.58            .ssh                        .Xauthority  视频  下载
[aaa@qq.com ~]# cd .ssh/
[aaa@qq.com .ssh]# ls    //查看**对
id_rsa  id_rsa.pub
[aaa@qq.com .ssh]# ssh-copy-id 192.168.200.90
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.200.80 (192.168.200.80)' can't be established.
ECDSA key fingerprint is SHA256:N5nxR2HffZdSxo0zaKcWTafbevqnrjCj2ULe0dVdPa0.
ECDSA key fingerprint is MD5:78:58:0a:09:66:76:ad:7a:02:28:15:2b:f7:57:2c:ef.
Are you sure you want to continue connecting (yes/no)? yes                      //填yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
aaa@qq.com.168.200.80's password:             //输入root登录密码
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh '192.168.200.90'"
and check to make sure that only the key(s) you wanted were added.

[aaa@qq.com .ssh]# ssh-copy-id 192.168.200.80
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.200.80 (192.168.200.80)' can't be established.
ECDSA key fingerprint is SHA256:N5nxR2HffZdSxo0zaKcWTafbevqnrjCj2ULe0dVdPa0.
ECDSA key fingerprint is MD5:78:58:0a:09:66:76:ad:7a:02:28:15:2b:f7:57:2c:ef.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
aaa@qq.com.168.200.80's password: 
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh '192.168.200.80'"
and check to make sure that only the key(s) you wanted were added.

[aaa@qq.com .ssh]# ssh-copy-id 192.168.200.110
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.200.110 (192.168.200.110)' can't be established.
ECDSA key fingerprint is SHA256:eLdHi9BvCNVro0zGiYPq1F+Psfoo9V+9EDIvdZDR8vM.
ECDSA key fingerprint is MD5:2d:34:ae:97:fd:bc:af:4f:e1:6b:92:22:48:4d:69:b4.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
aaa@qq.com.168.200.110's password: 
Number of key(s) added: 1
Now try logging into the machine, with:   "ssh '192.168.200.110'"
and check to make sure that only the key(s) you wanted were added.

[aaa@qq.com .ssh]# cp -ra /root/mha4mysql-manager-0.58/samples/scripts/ /usr/local/bin/
[aaa@qq.com .ssh]# ls /usr/local/bin/
apply_diff_relay_logs  masterha_check_status    masterha_master_switch    save_binary_logs
filter_mysqlbinlog     masterha_conf_host       masterha_secondary_check  scripts
masterha_check_repl    masterha_manager         masterha_stop
masterha_check_ssh     masterha_master_monitor  purge_relay_logs
[aaa@qq.com .ssh]# cd /usr/local/bin/
[aaa@qq.com bin]# cd scripts/
[aaa@qq.com scripts]# ls
master_ip_failover  master_ip_online_change  power_manager  send_report
[aaa@qq.com scripts]# cp /usr/local/bin/scripts/master_ip_failover /usr/local/bin/
[aaa@qq.com scripts]# vim /usr/local/bin/master_ip_failover
my (
  $command,        $ssh_user,         $orig_master_host,
  $orig_master_ip, $orig_master_port, $new_master_host,
  $new_master_ip,  $new_master_port,  $new_master_user,
  $new_master_password
);
##########写入下面的内容#################
my $vip = '192.168.200.200';
my $brdc = '192.168.200.255';
my $ifdev = 'ens33';
my $key = '1';
my $ssh_start_vip = "/sbin/ifconfig ens33:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig ens33:$key down";
my $exit_code = 0;
#################################
GetOptions(
  'command=s'             => \$command,
  'ssh_user=s'            => \$ssh_user,
  'orig_master_host=s'    => \$orig_master_host,
  'orig_master_ip=s'      => \$orig_master_ip,
  'orig_master_port=i'    => \$orig_master_port,
  'new_master_host=s'     => \$new_master_host,
  'new_master_ip=s'       => \$new_master_ip,
  'new_master_port=i'     => \$new_master_port,
  'new_master_user=s'     => \$new_master_user,
  'new_master_password=s' => \$new_master_password,
);

[aaa@qq.com scripts]# mkdir /etc/masterha   //创建文件夹放配置文件
[aaa@qq.com scripts]# cp /root/mha4mysql-manager-0.58/samples/conf/app1.cnf /etc/masterha/
[aaa@qq.com scripts]# cd /etc/masterha/
app1.cnf
[aaa@qq.com masterha]# vim app1.cnf 
[server default]
manager_workdir=/var/log/masterha/app1
manager_log=/var/log/masterha/app1/manager.log
master_binlog_dir=/usr/local/mysql/data/
master_ip_failover_script=/usr/local/bin/master_ip_failover
master_ip_online_change_script=/usr/local/bin/master_ip_online_change
password=manager
user=mha
ping_interval=1
remote_workdir=/tmp
repl_password=123
repl_user=myslave
report_script=/usr/local/send_report
secondary_check_script=/usr/local/bin/masterha_secondary_check -s 192.168.200.80 -s 192.168.200.110
shutdown_script=""
ssh_user=root

[server1]
hostname=192.168.200.90
port=3306

[server2]
hostname=192.168.200.80
port=3306
candidate_master=1
check_repl_delay=0

[server3]
hostname=192.168.200.110
port=3306

[aaa@qq.com masterha]# cd /usr/local/bin/
[aaa@qq.com bin]# ls
apply_diff_relay_logs  masterha_check_status    masterha_master_switch    purge_relay_logs
filter_mysqlbinlog     masterha_conf_host       masterha_secondary_check  save_binary_logs
masterha_check_repl    masterha_manager         masterha_stop             scripts
masterha_check_ssh     masterha_master_monitor  master_ip_failover
[aaa@qq.com bin]# cd scripts/
[aaa@qq.com scripts]# cp master_ip_online_change ../
[aaa@qq.com scripts]# cd ..
[aaa@qq.com bin]# pwd
/usr/local/bin
[aaa@qq.com bin]# ls
apply_diff_relay_logs  masterha_check_status    masterha_master_switch    master_ip_online_change
filter_mysqlbinlog     masterha_conf_host       masterha_secondary_check  purge_relay_logs
masterha_check_repl    masterha_manager         masterha_stop             save_binary_logs
masterha_check_ssh     masterha_master_monitor  master_ip_failover        scripts
[aaa@qq.com bin]# cd scripts/
[aaa@qq.com scripts]# cp send_report /usr/local/
[aaa@qq.com scripts]# ls /usr/local/
bin  etc  games  include  lib  lib64  libexec  mysql  sbin  send_report  share  src

[aaa@qq.com scripts]# masterha_check_ssh -conf=/etc/masterha/app1.cnf      //检测ssh
Mon Aug 31 03:53:38 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Aug 31 03:53:38 2020 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Mon Aug 31 03:53:38 2020 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Mon Aug 31 03:53:38 2020 - [info] Starting SSH connection tests..
Mon Aug 31 03:53:40 2020 - [debug] 
Mon Aug 31 03:53:38 2020 - [debug]  Connecting via SSH from aaa@qq.com(192.168.200.80:22) to aaa@qq.com(192.168.200.90:22)..
Mon Aug 31 03:53:39 2020 - [debug]   ok.
Mon Aug 31 03:53:39 2020 - [debug]  Connecting via SSH from aaa@qq.com(192.168.200.80:22) to aaa@qq.com(192.168.200.110:22)..
Mon Aug 31 03:53:40 2020 - [debug]   ok.
Mon Aug 31 03:53:40 2020 - [debug] 
Mon Aug 31 03:53:38 2020 - [debug]  Connecting via SSH from aaa@qq.com(192.168.200.90:22) to aaa@qq.com(192.168.200.80:22)..
Mon Aug 31 03:53:39 2020 - [debug]   ok.
Mon Aug 31 03:53:39 2020 - [debug]  Connecting via SSH from aaa@qq.com(192.168.200.90:22) to aaa@qq.com(192.168.200.110:22)..
Mon Aug 31 03:53:40 2020 - [debug]   ok.
Mon Aug 31 03:53:41 2020 - [debug] 
Mon Aug 31 03:53:39 2020 - [debug]  Connecting via SSH from aaa@qq.com(192.168.200.110:22) to aaa@qq.com(192.168.200.90:22)..
Mon Aug 31 03:53:40 2020 - [debug]   ok.
Mon Aug 31 03:53:40 2020 - [debug]  Connecting via SSH from aaa@qq.com(192.168.200.110:22) to aaa@qq.com(192.168.200.80:22)..
Mon Aug 31 03:53:41 2020 - [debug]   ok.
Mon Aug 31 03:53:41 2020 - [info] All SSH connection tests passed successfully.

[aaa@qq.com ~]# masterha_check_repl -conf=/etc/masterha/app1.cnf
Mon Aug 31 08:45:33 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Aug 31 08:45:33 2020 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Mon Aug 31 08:45:33 2020 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Mon Aug 31 08:45:33 2020 - [info] MHA::MasterMonitor version 0.58.
Mon Aug 31 08:45:34 2020 - [info] GTID failover mode = 0
Mon Aug 31 08:45:34 2020 - [info] Dead Servers:
Mon Aug 31 08:45:34 2020 - [info] Alive Servers:
Mon Aug 31 08:45:34 2020 - [info]   192.168.200.90(192.168.200.90:3306)
Mon Aug 31 08:45:34 2020 - [info]   192.168.200.80(192.168.200.80:3306)
Mon Aug 31 08:45:34 2020 - [info]   192.168.200.110(192.168.200.110:3306)
Mon Aug 31 08:45:34 2020 - [info] Alive Slaves:
Mon Aug 31 08:45:34 2020 - [info]   192.168.200.80(192.168.200.80:3306)  Version=5.7.20-log (oldest major version between slaves) log-bin:enabled
Mon Aug 31 08:45:34 2020 - [info]     Replicating from 192.168.200.90(192.168.200.90:3306)
Mon Aug 31 08:45:34 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Mon Aug 31 08:45:34 2020 - [info]   192.168.200.110(192.168.200.110:3306)  Version=5.7.20-log (oldest major version between slaves) log-bin:enabled
Mon Aug 31 08:45:34 2020 - [info]     Replicating from 192.168.200.90(192.168.200.90:3306)
Mon Aug 31 08:45:34 2020 - [info] Current Alive Master: 192.168.200.90(192.168.200.90:3306)
Mon Aug 31 08:45:34 2020 - [info] Checking slave configurations..
Mon Aug 31 08:45:34 2020 - [info]  read_only=1 is not set on slave 192.168.200.80(192.168.200.80:3306).
Mon Aug 31 08:45:34 2020 - [warning]  relay_log_purge=0 is not set on slave 192.168.200.80(192.168.200.80:3306).
Mon Aug 31 08:45:34 2020 - [info]  read_only=1 is not set on slave 192.168.200.110(192.168.200.110:3306).
Mon Aug 31 08:45:34 2020 - [warning]  relay_log_purge=0 is not set on slave 192.168.200.110(192.168.200.110:3306).
Mon Aug 31 08:45:34 2020 - [info] Checking replication filtering settings..
Mon Aug 31 08:45:34 2020 - [info]  binlog_do_db= , binlog_ignore_db= 
Mon Aug 31 08:45:34 2020 - [info]  Replication filtering check ok.
Mon Aug 31 08:45:34 2020 - [info] GTID (with auto-pos) is not supported
Mon Aug 31 08:45:34 2020 - [info] Starting SSH connection tests..
Mon Aug 31 08:45:38 2020 - [info] All SSH connection tests passed successfully.
Mon Aug 31 08:45:38 2020 - [info] Checking MHA Node version..
Mon Aug 31 08:45:39 2020 - [info]  Version check ok.
Mon Aug 31 08:45:39 2020 - [info] Checking SSH publickey authentication settings on the current master..
Mon Aug 31 08:45:39 2020 - [info] HealthCheck: SSH to 192.168.200.90 is reachable.
Mon Aug 31 08:45:40 2020 - [info] Master MHA Node version is 0.58.
Mon Aug 31 08:45:40 2020 - [info] Checking recovery script configurations on 192.168.200.90(192.168.200.90:3306)..
Mon Aug 31 08:45:40 2020 - [info]   Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/usr/local/mysql/data/ --output_file=/tmp/save_binary_logs_test --manager_version=0.58 --start_file=master-bin.000003 
Mon Aug 31 08:45:40 2020 - [info]   Connecting to aaa@qq.com(192.168.200.90:22).. 
  Creating /tmp if not exists..    ok.
  Checking output directory is accessible or not..
   ok.
  Binlog found at /usr/local/mysql/data/, up to master-bin.000003
Mon Aug 31 08:45:40 2020 - [info] Binlog setting check done.
Mon Aug 31 08:45:40 2020 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Mon Aug 31 08:45:40 2020 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='mha' --slave_host=192.168.200.80 --slave_ip=192.168.200.80 --slave_port=3306 --workdir=/tmp --target_version=5.7.20-log --manager_version=0.58 --relay_log_info=/usr/local/mysql/data/relay-log.info  --relay_dir=/usr/local/mysql/data/  --slave_pass=xxx
Mon Aug 31 08:45:40 2020 - [info]   Connecting to aaa@qq.com(192.168.200.80:22).. 
  Checking slave recovery environment settings..
    Opening /usr/local/mysql/data/relay-log.info ... ok.
    Relay log found at /usr/local/mysql/data, up to relay-log-bin.000009
    Temporary relay log file is /usr/local/mysql/data/relay-log-bin.000009
    Checking if super_read_only is defined and turned on.. not present or turned off, ignoring.
    Testing mysql connection and privileges..
mysql: [Warning] Using a password on the command line interface can be insecure.
 done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Mon Aug 31 08:45:41 2020 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='mha' --slave_host=192.168.200.110 --slave_ip=192.168.200.110 --slave_port=3306 --workdir=/tmp --target_version=5.7.20-log --manager_version=0.58 --relay_log_info=/usr/local/mysql/data/relay-log.info  --relay_dir=/usr/local/mysql/data/  --slave_pass=xxx
Mon Aug 31 08:45:41 2020 - [info]   Connecting to aaa@qq.com.168.200.110(192.168.200.110:22).. 
  Checking slave recovery environment settings..
    Opening /usr/local/mysql/data/relay-log.info ... ok.
    Relay log found at /usr/local/mysql/data, up to relay-log-bin.000011
    Temporary relay log file is /usr/local/mysql/data/relay-log-bin.000011
    Checking if super_read_only is defined and turned on.. not present or turned off, ignoring.
    Testing mysql connection and privileges..
mysql: [Warning] Using a password on the command line interface can be insecure.
 done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Mon Aug 31 08:45:41 2020 - [info] Slaves settings check done.
Mon Aug 31 08:45:41 2020 - [info] 
192.168.200.90(192.168.200.90:3306) (current master)
 +--192.168.200.80(192.168.200.80:3306)
 +--192.168.200.110(192.168.200.110:3306)

Mon Aug 31 08:45:41 2020 - [info] Checking replication health on 192.168.200.80..
Mon Aug 31 08:45:41 2020 - [info]  ok.
Mon Aug 31 08:45:41 2020 - [info] Checking replication health on 192.168.200.110..
Mon Aug 31 08:45:41 2020 - [info]  ok.
Mon Aug 31 08:45:41 2020 - [info] Checking master_ip_failover_script status:
Mon Aug 31 08:45:41 2020 - [info]   /usr/local/bin/master_ip_failover --command=status --ssh_user=root --orig_master_host=192.168.200.90 --orig_master_ip=192.168.200.90 --orig_master_port=3306 

IN SCRIPT TEST====/sbin/ifconfig ens33:1 down==/sbin/ifconfig ens33:1 192.168.195.200===

Checking the Status of the script.. OK 
Mon Aug 31 08:45:41 2020 - [info]  OK.
Mon Aug 31 08:45:41 2020 - [warning] shutdown_script is not defined.
Mon Aug 31 08:45:41 2020 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.   //出现这话就成功了

验证实验

[aaa@qq.com ~]# /sbin/ifconfig ens33:1 192.168.200.200/24
[aaa@qq.com ~]# nohup masterha_manager --conf=/etc/masterha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/masterha/app1/manager.log 2>&1 &
[aaa@qq.com ~]# jobs
[1]+  运行中               nohup masterha_manager --conf=/etc/masterha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/masterha/app1/manager.log 2>&1 &
[aaa@qq.com ~]# masterha_check_status --conf=/etc/masterha/app1.cnf
app1 (pid:103931) is running(0:PING_OK), master:192.168.200.90
查看日志
[aaa@qq.com ~]# cat /var/log/masterha/app1/manager.log 
Mon Aug 31 16:46:31 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Aug 31 16:46:31 2020 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Mon Aug 31 16:46:31 2020 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Mon Aug 31 16:46:31 2020 - [info] MHA::MasterMonitor version 0.58.
Mon Aug 31 16:46:32 2020 - [info] GTID failover mode = 0
Mon Aug 31 16:46:32 2020 - [info] Dead Servers:
Mon Aug 31 16:46:32 2020 - [info] Alive Servers:
Mon Aug 31 16:46:32 2020 - [info]   192.168.200.90(192.168.200.90:3306)
Mon Aug 31 16:46:32 2020 - [info]   192.168.200.80(192.168.200.80:3306)
Mon Aug 31 16:46:32 2020 - [info]   192.168.200.110(192.168.200.110:3306)
Mon Aug 31 16:46:32 2020 - [info] Alive Slaves:
Mon Aug 31 16:46:32 2020 - [info]   192.168.200.80(192.168.200.80:3306)  Version=5.7.20-log (oldest major version between slaves) log-bin:enabled
Mon Aug 31 16:46:32 2020 - [info]     Replicating from 192.168.200.90(192.168.200.90:3306)
Mon Aug 31 16:46:32 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Mon Aug 31 16:46:32 2020 - [info]   192.168.200.110(192.168.200.110:3306)  Version=5.7.20-log (oldest major version between slaves) log-bin:enabled
Mon Aug 31 16:46:32 2020 - [info]     Replicating from 192.168.200.90(192.168.200.90:3306)
Mon Aug 31 16:46:32 2020 - [info] Current Alive Master: 192.168.200.90(192.168.200.90:3306)
Mon Aug 31 16:46:32 2020 - [info] Checking slave configurations..
Mon Aug 31 16:46:32 2020 - [info]  read_only=1 is not set on slave 192.168.200.80(192.168.200.80:3306).
Mon Aug 31 16:46:32 2020 - [warning]  relay_log_purge=0 is not set on slave 192.168.200.80(192.168.200.80:3306).
Mon Aug 31 16:46:32 2020 - [info]  read_only=1 is not set on slave 192.168.200.110(192.168.200.110:3306).
Mon Aug 31 16:46:32 2020 - [warning]  relay_log_purge=0 is not set on slave 192.168.200.110(192.168.200.110:3306).
Mon Aug 31 16:46:32 2020 - [info] Checking replication filtering settings..
Mon Aug 31 16:46:32 2020 - [info]  binlog_do_db= , binlog_ignore_db= 
Mon Aug 31 16:46:32 2020 - [info]  Replication filtering check ok.
Mon Aug 31 16:46:32 2020 - [info] GTID (with auto-pos) is not supported
Mon Aug 31 16:46:32 2020 - [info] Starting SSH connection tests..
Mon Aug 31 16:46:34 2020 - [info] All SSH connection tests passed successfully.
Mon Aug 31 16:46:34 2020 - [info] Checking MHA Node version..
Mon Aug 31 16:46:40 2020 - [info]  Version check ok.
Mon Aug 31 16:46:40 2020 - [info] Checking SSH publickey authentication settings on the current master..
Mon Aug 31 16:46:40 2020 - [info] HealthCheck: SSH to 192.168.200.90 is reachable.
Mon Aug 31 16:46:41 2020 - [info] Master MHA Node version is 0.58.
Mon Aug 31 16:46:41 2020 - [info] Checking recovery script configurations on 192.168.200.90(192.168.200.90:3306)..
Mon Aug 31 16:46:41 2020 - [info]   Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/usr/local/mysql/data/ --output_file=/tmp/save_binary_logs_test --manager_version=0.58 --start_file=master-bin.000003 
Mon Aug 31 16:46:41 2020 - [info]   Connecting to aaa@qq.com.168.200.90(192.168.200.90:22).. 
  Creating /tmp if not exists..    ok.
  Checking output directory is accessible or not..
   ok.
  Binlog found at /usr/local/mysql/data/, up to master-bin.000003
Mon Aug 31 16:46:41 2020 - [info] Binlog setting check done.
Mon Aug 31 16:46:41 2020 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Mon Aug 31 16:46:41 2020 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='mha' --slave_host=192.168.200.80 --slave_ip=192.168.200.80 --slave_port=3306 --workdir=/tmp --target_version=5.7.20-log --manager_version=0.58 --relay_log_info=/usr/local/mysql/data/relay-log.info  --relay_dir=/usr/local/mysql/data/  --slave_pass=xxx
Mon Aug 31 16:46:41 2020 - [info]   Connecting to aaa@qq.com.168.200.80(192.168.200.80:22).. 
  Checking slave recovery environment settings..
    Opening /usr/local/mysql/data/relay-log.info ... ok.
    Relay log found at /usr/local/mysql/data, up to relay-log-bin.000009
    Temporary relay log file is /usr/local/mysql/data/relay-log-bin.000009
    Checking if super_read_only is defined and turned on.. not present or turned off, ignoring.
    Testing mysql connection and privileges..
mysql: [Warning] Using a password on the command line interface can be insecure.
 done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Mon Aug 31 16:46:41 2020 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='mha' --slave_host=192.168.200.110 --slave_ip=192.168.200.110 --slave_port=3306 --workdir=/tmp --target_version=5.7.20-log --manager_version=0.58 --relay_log_info=/usr/local/mysql/data/relay-log.info  --relay_dir=/usr/local/mysql/data/  --slave_pass=xxx
Mon Aug 31 16:46:41 2020 - [info]   Connecting to aaa@qq.com.168.200.110(192.168.200.110:22).. 
  Checking slave recovery environment settings..
    Opening /usr/local/mysql/data/relay-log.info ... ok.
    Relay log found at /usr/local/mysql/data, up to relay-log-bin.000011
    Temporary relay log file is /usr/local/mysql/data/relay-log-bin.000011
    Checking if super_read_only is defined and turned on.. not present or turned off, ignoring.
    Testing mysql connection and privileges..
mysql: [Warning] Using a password on the command line interface can be insecure.
 done.
    Testing mysqlbinlog output.. done.
    Cleaning up test file(s).. done.
Mon Aug 31 16:46:42 2020 - [info] Slaves settings check done.
Mon Aug 31 16:46:42 2020 - [info] 
192.168.200.90(192.168.200.90:3306) (current master)
 +--192.168.200.80(192.168.200.80:3306)
 +--192.168.200.110(192.168.200.110:3306)
Mon Aug 31 16:46:42 2020 - [info] Checking master_ip_failover_script status:
Mon Aug 31 16:46:42 2020 - [info]   /usr/local/bin/master_ip_failover --command=status --ssh_user=root --orig_master_host=192.168.200.90 --orig_master_ip=192.168.200.90 --orig_master_port=3306 
IN SCRIPT TEST====/sbin/ifconfig ens33:1 down==/sbin/ifconfig ens33:1 192.168.195.200===
Checking the Status of the script.. OK 
Mon Aug 31 16:46:42 2020 - [info]  OK.
Mon Aug 31 16:46:42 2020 - [warning] shutdown_script is not defined.
Mon Aug 31 16:46:42 2020 - [info] Set master ping interval 1 seconds.
Mon Aug 31 16:46:42 2020 - [info] Set secondary check script: /usr/local/bin/masterha_secondary_check -s 192.168.200.80 -s 192.168.200.110
Mon Aug 31 16:46:42 2020 - [info] Starting ping health check on 192.168.200.90(192.168.200.90:3306)..
Mon Aug 31 16:46:42 2020 - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond..
[aaa@qq.com ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.200.90  netmask 255.255.255.0  broadcast 192.168.200.255
        inet6 fe80::1084:e6f4:fe54:f1ba  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:6d:45:fd  txqueuelen 1000  (Ethernet)
        RX packets 708606  bytes 981615983 (936.1 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 169089  bytes 17498433 (16.6 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.200.200  netmask 255.255.255.0  broadcast 192.168.200.255
        ether 00:0c:29:6d:45:fd  txqueuelen 1000  (Ethernet)
[aaa@qq.com ~]# netstat -antp | grep 3306
tcp6       0      0 :::3306                 :::*                    LISTEN      99814/mysqld        
tcp6       0      0 192.168.200.90:3306     192.168.200.110:45866   ESTABLISHED 99814/mysqld        
tcp6       0      0 192.168.200.90:3306     192.168.200.80:45212    ESTABLISHED 99814/mysqld        
tcp6       0      0 192.168.200.90:3306     192.168.200.40:41568    ESTABLISHED 99814/mysqld  
[aaa@qq.com ~]# killall mysqld        干掉主服务器
[aaa@qq.com ~]# netstat -antp | grep 3306
tcp6       0      0 192.168.200.90:3306     192.168.200.40:41574    TIME_WAIT   -                   
tcp6       0      0 192.168.200.90:3306     192.168.200.40:41592    TIME_WAIT   -                   
tcp6       0      0 192.168.200.90:3306     192.168.200.40:41586    TIME_WAIT   -                   
tcp6       0      0 192.168.200.90:3306     192.168.200.110:47320   TIME_WAIT   -                   
tcp6       0      0 192.168.200.90:3306     192.168.200.40:41580    TIME_WAIT   -                   
tcp6       0      0 192.168.200.90:3306     192.168.200.80:46696    TIME_WAIT   -  
[aaa@qq.com ~]# ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.200.90  netmask 255.255.255.0  broadcast 192.168.200.255
        inet6 fe80::1084:e6f4:fe54:f1ba  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:6d:45:fd  txqueuelen 1000  (Ethernet)
        RX packets 709796  bytes 981740488 (936.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 169926  bytes 17622394 (16.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[aaa@qq.com ~]# ifconfig                    查看主备出现VIP
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.200.80  netmask 255.255.255.0  broadcast 192.168.200.255
        inet6 fe80::b948:c5a0:c6f:e7b7  prefixlen 64  scopeid 0x20<link>
        ether 00:0c:29:cd:9a:36  txqueuelen 1000  (Ethernet)
        RX packets 682864  bytes 975227981 (930.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 378639  bytes 29835335 (28.4 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
ens33:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.195.200  netmask 255.255.255.0  broadcast 192.168.195.255
        ether 00:0c:29:cd:9a:36  txqueuelen 1000  (Ethernet)