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

目录

  • 一、MHA概述
    • 1.1 什么是MHA?
    • 1.2 MHA的组成
    • 1.3 MHA有什么特点?
    • 1.4:MHA形成的原因
  • 二、MHA实验
    • 2.1 实验环境
    • 实验拓扑
    • 实验步骤

一、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高可用配置及故障切换_第1张图片

二、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高可用配置及故障切换_第2张图片

实验步骤

1、配置主从同步

主服务器
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
[root@localhost ~]# hostnamectl set-hostname Mysql1
[root@localhost ~]# su
[root@mysql1 ~]# 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
       
[root@mysql1 ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
[root@mysql1 ~]# ln -s /usr/local/mysql/bin/mysqlbinlog /usr/bin/
[root@mysql1 ~]# systemctl restart mysqld
[root@mysql1 ~]# netstat -antp | grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      94409/mysqld   
[root@mysql1 ~]# 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 |              |                  |                   |
+-------------------+----------+--------------+------------------+-------------------+
主备服务器
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
[root@localhost ~]# hostnamectl set-hostname Mysql2
[root@localhost ~]# su
[root@mysql2 ~]# 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
[root@mysql2 ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
[root@mysql2 ~]# ln -s /usr/local/mysql/bin/mysqlbinlog /usr/bin/
[root@mysql2 ~]# systemctl restart mysqld
[root@mysql2 ~]# netstat -antp | grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      88672/mysqld        
[root@mysql2 ~]# 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;
从服务器
[root@promote ~]# iptables -F
[root@promote ~]# setenforce 0
[root@promote ~]# hostnamectl set-hostname Mysql3
[root@promote ~]# su
[root@mysql3 ~]# 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
[root@mysql3 ~]# ln -s /usr/local/mysql/bin/mysql /usr/bin/
[root@mysql3 ~]# ln -s /usr/local/mysql/bin/mysqlbinlog /usr/bin/
[root@mysql3 ~]# systemctl restart mysqld
[root@mysql3 ~]# netstat -antp | grep mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      90340/mysqld        
[root@mysql3 ~]# 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免密登录授权配置

主服务器
[root@mysql1 ~]# yum -y install epel-release --nogpgcheck
[root@mysql1 ~]# yum -y install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN
[root@mysql1 ~]# 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  公共                        图片  音乐
[root@mysql1 ~]# tar zxvf mha4mysql-node-0.58.tar.gz 
[root@mysql1 ~]# 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   视频  下载
[root@mysql1 ~]# cd mha4mysql-node-0.58/
[root@mysql1 mha4mysql-node-0.58]# ls
AUTHORS  COPYING  inc  Makefile.PL  META.yml  rpm
bin      debian   lib  MANIFEST     README    t
[root@mysql1 mha4mysql-node-0.58]# perl Makefile.PL 
[root@mysql1 mha4mysql-node-0.58]# make
[root@mysql1 mha4mysql-node-0.58]# make install               //安装完成
[root@mysql1 mha4mysql-node-0.58]# cd ~                      //主服务器设置两台从服务器免密登录
[root@mysql1 ~]# ssh-keygen -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 root@mysql1
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|     .           |
|    o o          |
|   = = .         |
|o.=E= * S        |
|=o.*o+ * .       |
|O.=ooo* o        |
|+O.o+* + +       |
|+o+.oo+ + .      |
+----[SHA256]-----+
[root@mysql1 ~]# 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
root@192.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.
[root@mysql1 ~]# 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
root@192.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.

主备服务器配置主从的免密登录
[root@mysql2 ~]# yum -y install epel-release --nogpgcheck
[root@mysql2 ~]# yum -y install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN
[root@mysql2 ~]# 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  公共                        图片  音乐
[root@mysql2 ~]# tar zxvf mha4mysql-node-0.58.tar.gz 
[root@mysql2 ~]# 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   视频  下载
[root@mysql2 ~]# cd mha4mysql-node-0.58/
[root@mysql2 mha4mysql-node-0.58]# ls
AUTHORS  COPYING  inc  Makefile.PL  META.yml  rpm
bin      debian   lib  MANIFEST     README    t
[root@mysql2 mha4mysql-node-0.58]# perl Makefile.PL 
[root@mysql2 mha4mysql-node-0.58]# make
[root@mysql2 mha4mysql-node-0.58]# make install
[root@mysql2 mha4mysql-node-0.58]# cd ~
[root@mysql2 ~]# ssh-keygen -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 root@mysql2
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]-----+
[root@mysql2 ~]# 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
[email protected]'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.

[root@mysql2 ~]# 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
[email protected]'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.

从服务器配置主从的免密登录
[root@mysql3 ~]# yum -y install epel-release --nogpgcheck
[root@mysql3 ~]# yum -y install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN
[root@mysql3 ~]# 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  公共                        图片  音乐
[root@mysql3 ~]# tar zxvf mha4mysql-node-0.58.tar.gz 
[root@mysql3 ~]# 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   视频  下载
[root@mysql3 ~]# cd mha4mysql-node-0.58/
[root@mysql3 mha4mysql-node-0.58]# ls
AUTHORS  COPYING  inc  Makefile.PL  META.yml  rpm
bin      debian   lib  MANIFEST     README    t
[root@mysql3 mha4mysql-node-0.58]# perl Makefile.PL 
[root@mysql3 mha4mysql-node-0.58]# make
[root@mysql3 mha4mysql-node-0.58]# make install
[root@mysql3 mha4mysql-node-0.58]# cd ~
[root@mysql3 ~]# ssh-keygen -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 root@mysql3
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]-----+
[root@mysql3 ~]# 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
root@192.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.
[root@mysql3 ~]# 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
root@192.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

[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
[root@localhost ~]# hostnamectl set-hostname mha
[root@localhost ~]# su
[root@mha ~]# yum -y install epel-release --nogpgcheck
[root@mha ~]# yum -y install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-CPAN
[root@mha ~]# 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  公共                        图片  音乐
[root@mha ~]# tar zxvf mha4mysql-node-0.58.tar.gz 
[root@mha ~]# 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   视频  下载
[root@mha ~]# cd mha4mysql-node-0.58/
[root@mha mha4mysql-node-0.58]# ls
AUTHORS  COPYING  inc  Makefile.PL  META.yml  rpm
bin      debian   lib  MANIFEST     README    t
[root@mha mha4mysql-node-0.58]# perl Makefile.PL 
[root@mha mha4mysql-node-0.58]# make
[root@mha mha4mysql-node-0.58]# make install
[root@mha mha4mysql-node-0.58]# cd ~
[root@mha ~]# tar zxvf mha4mysql-manager-0.58.tar.gz 
[root@mha ~]# cd mha4mysql-manager-0.58/
[root@mha mha4mysql-manager-0.58]# perl Makefile.PL 
[root@mha mha4mysql-manager-0.58]# make
[root@mha mha4mysql-manager-0.58]# make install
[root@mha 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
[root@mha mha4mysql-manager-0.58]# ssh-keygen -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 root@mha
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|                 |
|        .        |
|       o         |
|    .   S.       |
|     o .. .  .o. |
|    o +. = +=E*oo|
|     *. + =*@X.O.|
|    ..oo +=*@*=.o|
+----[SHA256]-----+
[root@mha mha4mysql-manager-0.58]# cd ~
[root@mha ~]# 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  视频  下载
[root@mha ~]# cd .ssh/
[root@mha .ssh]# ls    //查看密钥对
id_rsa  id_rsa.pub
[root@mha .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
root@192.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.

[root@mha .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
root@192.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.

[root@mha .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
root@192.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.

[root@mha .ssh]# cp -ra /root/mha4mysql-manager-0.58/samples/scripts/ /usr/local/bin/
[root@mha .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
[root@mha .ssh]# cd /usr/local/bin/
[root@mha bin]# cd scripts/
[root@mha scripts]# ls
master_ip_failover  master_ip_online_change  power_manager  send_report
[root@mha scripts]# cp /usr/local/bin/scripts/master_ip_failover /usr/local/bin/
[root@mha 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,
);

[root@mha scripts]# mkdir /etc/masterha   //创建文件夹放配置文件
[root@mha scripts]# cp /root/mha4mysql-manager-0.58/samples/conf/app1.cnf /etc/masterha/
[root@mha scripts]# cd /etc/masterha/
app1.cnf
[root@mha 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

[root@mha masterha]# cd /usr/local/bin/
[root@mha 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
[root@mha bin]# cd scripts/
[root@mha scripts]# cp master_ip_online_change ../
[root@mha scripts]# cd ..
[root@mha bin]# pwd
/usr/local/bin
[root@mha 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
[root@mha bin]# cd scripts/
[root@mha scripts]# cp send_report /usr/local/
[root@mha scripts]# ls /usr/local/
bin  etc  games  include  lib  lib64  libexec  mysql  sbin  send_report  share  src

[root@mha 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 [email protected](192.168.200.80:22) to [email protected](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 [email protected](192.168.200.80:22) to [email protected](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 [email protected](192.168.200.90:22) to [email protected](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 [email protected](192.168.200.90:22) to [email protected](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 [email protected](192.168.200.110:22) to [email protected](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 [email protected](192.168.200.110:22) to [email protected](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.

[root@mha ~]# 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 [email protected](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 [email protected](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 root@192.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.   //出现这话就成功了

验证实验

[root@mysql1 ~]# /sbin/ifconfig ens33:1 192.168.200.200/24
[root@mha ~]# 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 &
[root@mha ~]# 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 &
[root@mha ~]# masterha_check_status --conf=/etc/masterha/app1.cnf
app1 (pid:103931) is running(0:PING_OK), master:192.168.200.90
查看日志
[root@mha ~]# 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 root@192.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 root@192.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 root@192.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..
[root@mysql1 ~]# ifconfig
ens33: flags=4163,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
        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,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)
[root@mysql1 ~]# 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  
[root@mysql1 ~]# killall mysqld        干掉主服务器
[root@mysql1 ~]# 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   -  
[root@mysql1 ~]# ifconfig
ens33: flags=4163,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
        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

[root@mysql2 ~]# ifconfig                    查看主备出现VIP
ens33: flags=4163,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
        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,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)

你可能感兴趣的:(mysql,MHA,mysql,主从同步,数据库高可用)