Linux学习作业---第十六周(8.3-8.10)

一、编写脚本,支持让用户自主选择,使用mysqldump还是xtraback全量备份
1、安装xtraback
由于yum 安装的xtraback版本太低无法支持mysql5.7,因此通过官网下载percona-percona-xtrabackup-24-2.4.20

yum -y install perl perl-devel libaio libaio-devel perl-Time-HiRes perl-DBD-MySQL rsync perl-Digest-MD5  #先安装依赖包
rpm -ivh percona-xtrabackup-24-2.4.20-1.el7.x86_64.rpm  #安装percona-xtrabackup

2、创建备份账户
用户名:BACKUP 密码:BACKUP
授予的权限


备份账户权限

3、脚本

#mysql每天全备份脚本
#
# 以下配置信息请自己修改
mysql_user="BACKUP" #MySQL备份用户
mysql_password="BACKUP" #MySQL备份用户的密码
mysql_port=3306 #MySQL端口
backup_location=/data/backup #备份数据存放位置
backup_Ymd=`date +%Y-%m-%d` #定义备份目录中的年月日时间
backup_dir=$backup_location/$backup_Ymd #备份文件夹全路径

 
# 判断MYSQL是否启动,mysql没有启动则备份退出
mysql_ps=`ps -ef |grep mysql |wc -l`
mysql_listen=`netstat -ntlp |grep $mysql_port |wc -l`
if [ [$mysql_ps == 0] -o [$mysql_listen == 0] ]; then
echo "ERROR:MySQL is not running! backup stop!" > $backup_dir/$backup_Ymd.log
exit
fi

#选择备份方式
read -p "ENTER:1 mysqldump ENTER:2 xtrabackup": option
if [ $option == "1" ];then
mkdir -p $backup_dir
mysqldump -h127.0.0.1 -P$mysql_port -u$mysql_user -p$mysql_password --skip-lock-tables --all-databases >$backup_dir/$backup_Ymd.sql
elif [ $option == "2" ];then
mkdir -p $backup_dir
xtrabackup --backup -u$mysql_user -p$mysql_password --socket=/var/mysql/mysql.sock --target-dir=$backup_dir
else
echo "option is fail!" >> $backup_dir/$backup_Ymd.log
fi

二、配置Mysql主从同步
1、采用GTID模式
从MySQL 5.6.5 开始新增了一种基于 GTID 的复制方式。通过 GTID 保证了每个在主库上提交的事务在集群中有一个唯一的ID。这种方式强化了数据库的主备一致性,故障恢复以及容错能力。

GTID (Global Transaction ID)是全局事务ID,当在主库上提交事务或者被从库应用时,可以定位和追踪每一个事务,对DBA来说意义就很大了,我们可以适当的解放出来,不用手工去可以找偏移量的值了,而是通过CHANGE MASTER TO MASTER_HOST='xxx', MASTER_AUTO_POSITION=1的即可方便的搭建从库,在故障修复中也可以采用MASTER_AUTO_POSITION=‘X’的方式。
2、环境描述
主master IP:172.16.23.230
备slave IP:172.16.23.231
3、配置文件
主master my.cnf配置

lower_case_table_names=1
character-set-server=utf8mb4
datadir=/data/mysql-data
socket=/var/mysql/mysql.sock
symbolic-links=0
innodb_data_home_dir=/data/mysql-data
innodb_data_file_path=ibdata1:16M:autoextend:max:10G
innodb_log_group_home_dir=/data/mysql-log
innodb_buffer_pool_size=512M
innodb_file_per_table = 1
max_allowed_packet = 100M
max_connections = 1500
log-error=/data/mysql-log/error_log/mysqld.log
pid-file=/data/mysql-pid/mysqld.pid
log-bin=mysql-bin 
server-id=1
expire-logs-days = 14
max-binlog-size = 500M
sync_binlog=1
binlog_format=row
gtid_mode=ON                     #开启gtid模式
enforce-gtid-consistency=ON             #强制gtid一致性
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

备slave my.cnf配置

lower_case_table_names=1
character-set-server=utf8mb4
datadir=/data/mysql-data
socket=/var/mysql/mysql.sock
symbolic-links=0
innodb_data_home_dir=/data/mysql-data
innodb_data_file_path=ibdata1:16M:autoextend:max:10G
innodb_log_group_home_dir=/data/mysql-log
innodb_buffer_pool_size=512M
innodb_file_per_table = 1
max_allowed_packet = 100M
max_connections = 1500
log-error=/data/mysql-log/error_log/mysqld.log
pid-file=/data/mysql-pid/mysqld.pid
log-bin=mysql-bin
server-id=2                      #与主server-id不一样
expire-logs-days = 14
max-binlog-size = 500M
sync_binlog=1
binlog_format=row
relay-log-index=slave-relay-bin.index
relay-log=slave-relay-bin
gtid_mode=ON
enforce-gtid-consistency=ON
log_slave_updates=ON               #将relay_log内容再写入从库的binlog中
skip-slave-start=1                         #启动跳过自动同步
relay_log_recovery=1                   #自动生成relaylog并获取master日志
sync_binlog=1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
#skip-grant-tables

4、主库创建同步账户repl,权限如下


image.png

5、配置主从
主库上查看show master status \G

mysql> show master status \G
*************************** 1. row ***************************
             File: mysql-bin.000001
         Position: 754
     Binlog_Do_DB: 
 Binlog_Ignore_DB: 
Executed_Gtid_Set: 5a1652b6-7fe4-11ea-9a9c-0050569081eb:1-3
1 row in set (0.00 sec)

从库配置

Query OK, 0 rows affected, 1 warning (0.00 sec)

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

mysql> change master to
    -> master_host='172.16.23.230',
    -> master_port=3306,
    -> master_user='repl',
    -> master_password='repl',
    -> master_log_file='mysql-bin.000001',
    -> master_log_pos=754;
Query OK, 0 rows affected, 2 warnings (0.03 sec)

mysql> start slave;
Query OK, 0 rows affected (0.01 sec)
ysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 172.16.23.230
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 754
               Relay_Log_File: slave-relay-bin.000003
                Relay_Log_Pos: 320
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              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: 754
              Relay_Log_Space: 527
              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: 5a1652b6-7fe4-11ea-9a9c-0050569081eb
             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)

ERROR: 
No query specified

三、使用MHA实现Mysql高可用
MYSQL主:172.16.23.230
MYSQL备:172.16.23.231
MHA master:172.16.23.232
1、配置SSH免密登陆

主:
ssh-keygen
ssh-copy-id [email protected]
ssh-copy-id [email protected]
备:
ssh-keygen
ssh-copy-id [email protected]
ssh-copy-id [email protected]
MHA master:
ssh-keygen
ssh-copy-id [email protected]
ssh-copy-id [email protected]

2、安装依赖的perl包

yum install -y perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager

3、安装MHA

主:
rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch.rpm
备:
rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch.rpm
MHA master:
rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch.rpm
rpm -ivh mha4mysql-manager-0.58-0.el7.centos.noarch.rpm

4、配置MHA
新建主配置文件

vi /data/mha/mha.conf

[server default]
manager_workdir=/data/mha                          #mha工作目录
manager_log=/data/mha/manager.log
master_binlog_dir=/data/mysql-data              #mysql数据目录
#master_ip_failover_script= /usr/local/bin/master_ip_failover
#master_ip_online_change_script= /usr/local/bin/master_ip_online_change
user=root                                                        #远程登陆用户
password=123456                                         
ping_interval=1                                               #监控主数据库
remote_workdir=/data/mha                            #远程mha工作目录
repl_password=repl                                        #主从复制账户
repl_user=repl                                                 #主从复制账户密码
#report_script=/usr/local/send_report
#secondary_check_script= /usr/local/bin/masterha_secondary_check -s server03 -s server02             #shutdown_script=""
ssh_user=root
[server2]
hostname=172.16.23.230
port=3306
[server3]
hostname=172.16.23.231
port=3306
candidate_master=1                                  #主数据库down之后,推荐为master
check_repl_delay=0

5、检测配置

[root@MHA mha]# masterha_check_ssh -conf=/data/mha/mha.conf 
Sun Aug  9 15:26:21 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sun Aug  9 15:26:21 2020 - [info] Reading application default configuration from /data/mha/mha.conf..
Sun Aug  9 15:26:21 2020 - [info] Reading server configuration from /data/mha/mha.conf..
Sun Aug  9 15:26:21 2020 - [info] Starting SSH connection tests..
Sun Aug  9 15:26:22 2020 - [debug] 
Sun Aug  9 15:26:21 2020 - [debug]  Connecting via SSH from [email protected](172.16.23.230:22) to [email protected](172.16.23.231:22)..
Sun Aug  9 15:26:22 2020 - [debug]   ok.
Sun Aug  9 15:26:22 2020 - [debug] 
Sun Aug  9 15:26:22 2020 - [debug]  Connecting via SSH from [email protected](172.16.23.231:22) to [email protected](172.16.23.230:22)..
Sun Aug  9 15:26:22 2020 - [debug]   ok.
Sun Aug  9 15:26:22 2020 - [info] All SSH connection tests passed successfully.
[root@MHA mha]# masterha_check_repl -conf=/data/mha/mha.conf 
Sun Aug  9 15:26:49 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sun Aug  9 15:26:49 2020 - [info] Reading application default configuration from /data/mha/mha.conf..
Sun Aug  9 15:26:49 2020 - [info] Reading server configuration from /data/mha/mha.conf..
Sun Aug  9 15:26:49 2020 - [info] MHA::MasterMonitor version 0.58.
Sun Aug  9 15:26:51 2020 - [info] GTID failover mode = 1
Sun Aug  9 15:26:51 2020 - [info] Dead Servers:
Sun Aug  9 15:26:51 2020 - [info] Alive Servers:
Sun Aug  9 15:26:51 2020 - [info]   172.16.23.230(172.16.23.230:3306)
Sun Aug  9 15:26:51 2020 - [info]   172.16.23.231(172.16.23.231:3306)
Sun Aug  9 15:26:51 2020 - [info] Alive Slaves:
Sun Aug  9 15:26:51 2020 - [info]   172.16.23.231(172.16.23.231:3306)  Version=5.7.29-log (oldest major version between slaves) log-bin:enabled
Sun Aug  9 15:26:51 2020 - [info]     GTID ON
Sun Aug  9 15:26:51 2020 - [info]     Replicating from 172.16.23.230(172.16.23.230:3306)
Sun Aug  9 15:26:51 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Sun Aug  9 15:26:51 2020 - [info] Current Alive Master: 172.16.23.230(172.16.23.230:3306)
Sun Aug  9 15:26:51 2020 - [info] Checking slave configurations..
Sun Aug  9 15:26:51 2020 - [info]  read_only=1 is not set on slave 172.16.23.231(172.16.23.231:3306).
Sun Aug  9 15:26:51 2020 - [info] Checking replication filtering settings..
Sun Aug  9 15:26:51 2020 - [info]  binlog_do_db= , binlog_ignore_db= 
Sun Aug  9 15:26:51 2020 - [info]  Replication filtering check ok.
Sun Aug  9 15:26:51 2020 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Sun Aug  9 15:26:51 2020 - [info] Checking SSH publickey authentication settings on the current master..
Sun Aug  9 15:26:51 2020 - [info] HealthCheck: SSH to 172.16.23.230 is reachable.
Sun Aug  9 15:26:51 2020 - [info] 
172.16.23.230(172.16.23.230:3306) (current master)
 +--172.16.23.231(172.16.23.231:3306)

Sun Aug  9 15:26:51 2020 - [info] Checking replication health on 172.16.23.231..
Sun Aug  9 15:26:51 2020 - [info]  ok.
Sun Aug  9 15:26:51 2020 - [warning] master_ip_failover_script is not defined.
Sun Aug  9 15:26:51 2020 - [warning] shutdown_script is not defined.
Sun Aug  9 15:26:51 2020 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.

6、启动MHA

masterha_manager -conf=/data/mha/mha.conf > /data/mha/mha.log 2>&1 &

7、模拟故障
杀死主库进程

 ps -ef |grep mysql
root      5986     1  0 12:00 ?        00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql-data --pid-file=/data/mysql-pid/mysqld.pid
mysql     6354  5986  0 12:00 ?        00:00:11 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql-data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/data/mysql-log/error_log/mysqld.log --pid-file=/data/mysql-pid/mysqld.pid --socket=/var/mysql/mysql.sock
root     10682  8711  0 15:33 pts/1    00:00:00 grep --color=auto mysql

kill -9 5986 6354

查看MHA日志

tail -200 manager.log 
Sun Aug  9 15:32:51 2020 - [info] MHA::MasterMonitor version 0.58.
Sun Aug  9 15:32:52 2020 - [info] GTID failover mode = 1
Sun Aug  9 15:32:52 2020 - [info] Dead Servers:
Sun Aug  9 15:32:52 2020 - [info] Alive Servers:
Sun Aug  9 15:32:52 2020 - [info]   172.16.23.230(172.16.23.230:3306)
Sun Aug  9 15:32:52 2020 - [info]   172.16.23.231(172.16.23.231:3306)
Sun Aug  9 15:32:52 2020 - [info] Alive Slaves:
Sun Aug  9 15:32:52 2020 - [info]   172.16.23.231(172.16.23.231:3306)  Version=5.7.29-log (oldest major version between slaves) log-bin:enabled
Sun Aug  9 15:32:52 2020 - [info]     GTID ON
Sun Aug  9 15:32:52 2020 - [info]     Replicating from 172.16.23.230(172.16.23.230:3306)
Sun Aug  9 15:32:52 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Sun Aug  9 15:32:52 2020 - [info] Current Alive Master: 172.16.23.230(172.16.23.230:3306)
Sun Aug  9 15:32:52 2020 - [info] Checking slave configurations..
Sun Aug  9 15:32:52 2020 - [info]  read_only=1 is not set on slave 172.16.23.231(172.16.23.231:3306).
Sun Aug  9 15:32:52 2020 - [info] Checking replication filtering settings..
Sun Aug  9 15:32:52 2020 - [info]  binlog_do_db= , binlog_ignore_db= 
Sun Aug  9 15:32:52 2020 - [info]  Replication filtering check ok.
Sun Aug  9 15:32:52 2020 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Sun Aug  9 15:32:52 2020 - [info] Checking SSH publickey authentication settings on the current master..
Sun Aug  9 15:32:52 2020 - [info] HealthCheck: SSH to 172.16.23.230 is reachable.
Sun Aug  9 15:32:52 2020 - [info] 
172.16.23.230(172.16.23.230:3306) (current master)
 +--172.16.23.231(172.16.23.231:3306)

Sun Aug  9 15:32:52 2020 - [warning] master_ip_failover_script is not defined.
Sun Aug  9 15:32:52 2020 - [warning] shutdown_script is not defined.
Sun Aug  9 15:32:52 2020 - [info] Set master ping interval 1 seconds.
Sun Aug  9 15:32:52 2020 - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from two or more routes.
Sun Aug  9 15:32:52 2020 - [info] Starting ping health check on 172.16.23.230(172.16.23.230:3306)..
Sun Aug  9 15:32:52 2020 - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond..
Sun Aug  9 15:34:20 2020 - [warning] Got error on MySQL select ping: 2006 (MySQL server has gone away)
Sun Aug  9 15:34:20 2020 - [info] Executing SSH check script: exit 0
Sun Aug  9 15:34:20 2020 - [info] HealthCheck: SSH to 172.16.23.230 is reachable.
Sun Aug  9 15:34:21 2020 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '172.16.23.230' (111))
Sun Aug  9 15:34:21 2020 - [warning] Connection failed 2 time(s)..
Sun Aug  9 15:34:22 2020 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '172.16.23.230' (111))
Sun Aug  9 15:34:22 2020 - [warning] Connection failed 3 time(s)..
Sun Aug  9 15:34:23 2020 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '172.16.23.230' (111))
Sun Aug  9 15:34:23 2020 - [warning] Connection failed 4 time(s)..
Sun Aug  9 15:34:23 2020 - [warning] Master is not reachable from health checker!
Sun Aug  9 15:34:23 2020 - [warning] Master 172.16.23.230(172.16.23.230:3306) is not reachable!
Sun Aug  9 15:34:23 2020 - [warning] SSH is reachable.
Sun Aug  9 15:34:23 2020 - [info] Connecting to a master server failed. Reading configuration file /etc/masterha_default.cnf and /data/mha/mha.conf again, and trying to connect to all servers to check server status..
Sun Aug  9 15:34:23 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sun Aug  9 15:34:23 2020 - [info] Reading application default configuration from /data/mha/mha.conf..
Sun Aug  9 15:34:23 2020 - [info] Reading server configuration from /data/mha/mha.conf..
Sun Aug  9 15:34:24 2020 - [info] GTID failover mode = 1
Sun Aug  9 15:34:24 2020 - [info] Dead Servers:
Sun Aug  9 15:34:24 2020 - [info]   172.16.23.230(172.16.23.230:3306)
Sun Aug  9 15:34:24 2020 - [info] Alive Servers:
Sun Aug  9 15:34:24 2020 - [info]   172.16.23.231(172.16.23.231:3306)
Sun Aug  9 15:34:24 2020 - [info] Alive Slaves:
Sun Aug  9 15:34:24 2020 - [info]   172.16.23.231(172.16.23.231:3306)  Version=5.7.29-log (oldest major version between slaves) log-bin:enabled
Sun Aug  9 15:34:24 2020 - [info]     GTID ON
Sun Aug  9 15:34:24 2020 - [info]     Replicating from 172.16.23.230(172.16.23.230:3306)
Sun Aug  9 15:34:24 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Sun Aug  9 15:34:24 2020 - [info] Checking slave configurations..
Sun Aug  9 15:34:24 2020 - [info]  read_only=1 is not set on slave 172.16.23.231(172.16.23.231:3306).
Sun Aug  9 15:34:24 2020 - [info] Checking replication filtering settings..
Sun Aug  9 15:34:24 2020 - [info]  Replication filtering check ok.
Sun Aug  9 15:34:24 2020 - [info] Master is down!
Sun Aug  9 15:34:24 2020 - [info] Terminating monitoring script.
Sun Aug  9 15:34:24 2020 - [info] Got exit code 20 (Master dead).
Sun Aug  9 15:34:24 2020 - [info] MHA::MasterFailover version 0.58.
Sun Aug  9 15:34:24 2020 - [info] Starting master failover.
Sun Aug  9 15:34:24 2020 - [info] 
Sun Aug  9 15:34:24 2020 - [info] * Phase 1: Configuration Check Phase..
Sun Aug  9 15:34:24 2020 - [info] 
Sun Aug  9 15:34:25 2020 - [info] GTID failover mode = 1
Sun Aug  9 15:34:25 2020 - [info] Dead Servers:
Sun Aug  9 15:34:25 2020 - [info]   172.16.23.230(172.16.23.230:3306)
Sun Aug  9 15:34:25 2020 - [info] Checking master reachability via MySQL(double check)...
Sun Aug  9 15:34:25 2020 - [info]  ok.
Sun Aug  9 15:34:25 2020 - [info] Alive Servers:
Sun Aug  9 15:34:25 2020 - [info]   172.16.23.231(172.16.23.231:3306)
Sun Aug  9 15:34:25 2020 - [info] Alive Slaves:
Sun Aug  9 15:34:25 2020 - [info]   172.16.23.231(172.16.23.231:3306)  Version=5.7.29-log (oldest major version between slaves) log-bin:enabled
Sun Aug  9 15:34:25 2020 - [info]     GTID ON
Sun Aug  9 15:34:25 2020 - [info]     Replicating from 172.16.23.230(172.16.23.230:3306)
Sun Aug  9 15:34:25 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Sun Aug  9 15:34:25 2020 - [info] Starting GTID based failover.
Sun Aug  9 15:34:25 2020 - [info] 
Sun Aug  9 15:34:25 2020 - [info] ** Phase 1: Configuration Check Phase completed.
Sun Aug  9 15:34:25 2020 - [info] 
Sun Aug  9 15:34:25 2020 - [info] * Phase 2: Dead Master Shutdown Phase..
Sun Aug  9 15:34:25 2020 - [info] 
Sun Aug  9 15:34:25 2020 - [info] Forcing shutdown so that applications never connect to the current master..
Sun Aug  9 15:34:25 2020 - [warning] master_ip_failover_script is not set. Skipping invalidating dead master IP address.
Sun Aug  9 15:34:25 2020 - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.
Sun Aug  9 15:34:26 2020 - [info] * Phase 2: Dead Master Shutdown Phase completed.
Sun Aug  9 15:34:26 2020 - [info] 
Sun Aug  9 15:34:26 2020 - [info] * Phase 3: Master Recovery Phase..
Sun Aug  9 15:34:26 2020 - [info] 
Sun Aug  9 15:34:26 2020 - [info] * Phase 3.1: Getting Latest Slaves Phase..
Sun Aug  9 15:34:26 2020 - [info] 
Sun Aug  9 15:34:26 2020 - [info] The latest binary log file/position on all slaves is mysql-bin.000001:33586381
Sun Aug  9 15:34:26 2020 - [info] Retrieved Gtid Set: 5a1652b6-7fe4-11ea-9a9c-0050569081eb:5-460
Sun Aug  9 15:34:26 2020 - [info] Latest slaves (Slaves that received relay log files to the latest):
Sun Aug  9 15:34:26 2020 - [info]   172.16.23.231(172.16.23.231:3306)  Version=5.7.29-log (oldest major version between slaves) log-bin:enabled
Sun Aug  9 15:34:26 2020 - [info]     GTID ON
Sun Aug  9 15:34:26 2020 - [info]     Replicating from 172.16.23.230(172.16.23.230:3306)
Sun Aug  9 15:34:26 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Sun Aug  9 15:34:26 2020 - [info] The oldest binary log file/position on all slaves is mysql-bin.000001:33586381
Sun Aug  9 15:34:26 2020 - [info] Retrieved Gtid Set: 5a1652b6-7fe4-11ea-9a9c-0050569081eb:5-460
Sun Aug  9 15:34:26 2020 - [info] Oldest slaves:
Sun Aug  9 15:34:26 2020 - [info]   172.16.23.231(172.16.23.231:3306)  Version=5.7.29-log (oldest major version between slaves) log-bin:enabled
Sun Aug  9 15:34:26 2020 - [info]     GTID ON
Sun Aug  9 15:34:26 2020 - [info]     Replicating from 172.16.23.230(172.16.23.230:3306)
Sun Aug  9 15:34:26 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Sun Aug  9 15:34:26 2020 - [info] 
Sun Aug  9 15:34:26 2020 - [info] * Phase 3.3: Determining New Master Phase..
Sun Aug  9 15:34:26 2020 - [info] 
Sun Aug  9 15:34:26 2020 - [info] Searching new master from slaves..
Sun Aug  9 15:34:26 2020 - [info]  Candidate masters from the configuration file:
Sun Aug  9 15:34:26 2020 - [info]   172.16.23.231(172.16.23.231:3306)  Version=5.7.29-log (oldest major version between slaves) log-bin:enabled
Sun Aug  9 15:34:26 2020 - [info]     GTID ON
Sun Aug  9 15:34:26 2020 - [info]     Replicating from 172.16.23.230(172.16.23.230:3306)
Sun Aug  9 15:34:26 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Sun Aug  9 15:34:26 2020 - [info]  Non-candidate masters:
Sun Aug  9 15:34:26 2020 - [info]  Searching from candidate_master slaves which have received the latest relay log events..
Sun Aug  9 15:34:26 2020 - [info] New master is 172.16.23.231(172.16.23.231:3306)
Sun Aug  9 15:34:26 2020 - [info] Starting master failover..
Sun Aug  9 15:34:26 2020 - [info] 
From:
172.16.23.230(172.16.23.230:3306) (current master)
 +--172.16.23.231(172.16.23.231:3306)

To:
172.16.23.231(172.16.23.231:3306) (new master)
Sun Aug  9 15:34:26 2020 - [info] 
Sun Aug  9 15:34:26 2020 - [info] * Phase 3.3: New Master Recovery Phase..
Sun Aug  9 15:34:26 2020 - [info] 
Sun Aug  9 15:34:26 2020 - [info]  Waiting all logs to be applied.. 
Sun Aug  9 15:34:26 2020 - [info]   done.
Sun Aug  9 15:34:26 2020 - [info] Getting new master's binlog name and position..
Sun Aug  9 15:34:26 2020 - [info]  mysql-bin.000003:33584967
Sun Aug  9 15:34:26 2020 - [info]  All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='172.16.23.231', MASTER_PORT=3306, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='xxx';
Sun Aug  9 15:34:26 2020 - [info] Master Recovery succeeded. File:Pos:Exec_Gtid_Set: mysql-bin.000003, 33584967, 5a1652b6-7fe4-11ea-9a9c-0050569081eb:5-460,
d9aabb6d-d9f8-11ea-ad22-0050569053ba:1-3
Sun Aug  9 15:34:26 2020 - [warning] master_ip_failover_script is not set. Skipping taking over new master IP address.
Sun Aug  9 15:34:26 2020 - [info] ** Finished master recovery successfully.
Sun Aug  9 15:34:26 2020 - [info] * Phase 3: Master Recovery Phase completed.
Sun Aug  9 15:34:26 2020 - [info] 
Sun Aug  9 15:34:26 2020 - [info] * Phase 4: Slaves Recovery Phase..
Sun Aug  9 15:34:26 2020 - [info] 
Sun Aug  9 15:34:26 2020 - [info] 
Sun Aug  9 15:34:26 2020 - [info] * Phase 4.1: Starting Slaves in parallel..
Sun Aug  9 15:34:26 2020 - [info] 
Sun Aug  9 15:34:26 2020 - [info] All new slave servers recovered successfully.
Sun Aug  9 15:34:26 2020 - [info] 
Sun Aug  9 15:34:26 2020 - [info] * Phase 5: New master cleanup phase..
Sun Aug  9 15:34:26 2020 - [info] 
Sun Aug  9 15:34:26 2020 - [info] Resetting slave info on the new master..
Sun Aug  9 15:34:26 2020 - [info]  172.16.23.231: Resetting slave info succeeded.
Sun Aug  9 15:34:26 2020 - [info] Master failover to 172.16.23.231(172.16.23.231:3306) completed successfully.
Sun Aug  9 15:34:26 2020 - [info] 

----- Failover Report -----

mha: MySQL Master failover 172.16.23.230(172.16.23.230:3306) to 172.16.23.231(172.16.23.231:3306) succeeded

Master 172.16.23.230(172.16.23.230:3306) is down!

Check MHA Manager logs at MHA:/data/mha/manager.log for details.

Started automated(non-interactive) failover.
Selected 172.16.23.231(172.16.23.231:3306) as a new master.
172.16.23.231(172.16.23.231:3306): OK: Applying all logs succeeded.
172.16.23.231(172.16.23.231:3306): Resetting slave info succeeded.
Master failover to 172.16.23.231(172.16.23.231:3306) completed successfully.

发现从库已经成功切换成master
注意,故障转移完成后, manager将会自动停止, 此时使用 masterha_check_status 命令检测将会遇到错误提示, 如下所示:

[root@MHA mha]# masterha_check_status -conf=/data/mha/mha.conf
mha is stopped(2:NOT_RUNNING).

你可能感兴趣的:(Linux学习作业---第十六周(8.3-8.10))