MySQL 主从复制与 MHA

1、编写脚本,支持让用户自主选择,使用mysqldump还是xtraback全量备份。

#!/bin/bash
BACKUP_DIR=/data
USER=root
PASSWORD=123456

select var in {'mysqldump','xtraback'} ;do
    case $var in
        'mysqldump' )
            # mysqldump
            mysqldump -A -u$USER -F -E -R -x -p$PASSWORD --master-data=1\
                      --flush-privileges --triggers \
                      --default-character-set=utf8 --hex-blob\
                      >$BACKUP_DIR/fullbak_`date +%F-%T`.sql
            ;;
        'xtraback' )
            # xtraback
            innobackupex --user=$USER --password=$PASSWORD $BACKUP_DIR
            ;;
        * ) echo 'please choice mysqldump or xtraback';;
    esac
    break
done

2、配置Mysql主从同步

主机IP 角色
192.168.58.139
192.168.58.140

https://dev.mysql.com/downloads/repo/yum/

2.1. 安装主节点

# 安装MySQL官方YUM源
~]# wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm
~]# rpm -ivh mysql80-community-release-el7-3.noarch.rpm 

# 安装MySQL
~]# yum install mysql-community-server -y

# 启动MySQL
~]# systemctl enable mysqld.service
~]# systemctl start mysqld.service 

# 启动日志中找到初始密码
~]# cat /var/log/mysqld.log     
2020-03-21T10:37:16.974791Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.19) initializing of server in progress as process 26718
2020-03-21T10:37:18.435015Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: Yp(r#yidX1K)
2020-03-21T10:37:20.546231Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.19) starting as process 26770
2020-03-21T10:37:20.893411Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2020-03-21T10:37:20.925400Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.0.19'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server - GPL.
2020-03-21T10:37:21.024553Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060

# 使用初始密码登录MySQL
~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.19

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 
# 修改初始密码
mysql> alter user 'root'@'localhost'IDENTIFIED BY 'MyNewPass@123'; 
Query OK, 0 rows affected (0.01 sec)


mysql> create database demo;
Query OK, 1 row affected (0.01 sec)

# 创建测试库,测试表
mysql> use demo;
Database changed

mysql> CREATE TABLE `test_tab` (
    ->   `id` int(11) NOT NULL AUTO_INCREMENT,
    ->   `name` varchar(20) DEFAULT NULL,
    ->   `create_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
    ->   PRIMARY KEY (`id`)
    -> ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 Query OK, 0 rows affected, 2 warnings (0.05 sec)

2.2 主节点打开 binlog

# [mysqld] 配置段添加 binlog 配置
~]# vi /etc/my.cnf
[mysqld]
...
log_bin=/data/mysql/binlogs/server1
server_id=100

# 创建binglog目录并修改其权限,并禁用selinux
~]# mkdir -p /data/mysql/binlogs
~]# chown -R mysql:mysql /data/mysql/binlogs

# 重启mysql
~]# systemctl restart mysqld.service

mysql> show variables like 'log_bin%';
+---------------------------------+-----------------------------------+
| Variable_name                   | Value                             |
+---------------------------------+-----------------------------------+
| log_bin                         | ON                                |
| log_bin_basename                | /data/mysql/binlogs/server1       |
| log_bin_index                   | /data/mysql/binlogs/server1.index |
| log_bin_trust_function_creators | OFF                               |
| log_bin_use_v1_row_events       | OFF                               |
+---------------------------------+-----------------------------------+
5 rows in set (0.00 sec)

mysql> show master logs;
+----------------+-----------+-----------+
| Log_name       | File_size | Encrypted |
+----------------+-----------+-----------+
| server1.000001 |       155 | No        |
+----------------+-----------+-----------+
1 row in set (0.00 sec)

~]# ll /data/mysql/binlogs/
total 8
-rw-r-----. 1 mysql mysql 155 Mar 21 19:31 server1.000001
-rw-r-----. 1 mysql mysql  35 Mar 21 19:31 server1.index

2.3 准备复制

# 在主节点上 创建复制用户
mysql> CREATE USER 'repl'@'192.168.58.%' IDENTIFIED WITH mysql_native_password BY 'MyNewPass@123';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT REPLICATION SLAVE ON *.* TO 'repl'@'192.168.58.%';
Query OK, 0 rows affected (0.00 sec)

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

# 将主节点上的数据导出,并复制到从节点
~]# mysqldump -uroot -p --single-transaction  --master-data=2  -A > master_dump.sql
~]# scp master_dump.sql [email protected]:/tmp/

2.4 创建从库

#采用同样的方式安装MySQL,并修改 server_id
~]# vi /etc/my.cnf
...
log_bin=/data/mysql/binlogs/server1
server_id=101
...
# 重启服务
~]# systemctl restart mysqld.service

# 导入主库数据
~]# mysql -uroot -p < /tmp/master_dump.sql 

# 在导出的数据文件的中找到 master MASTER_LOG_FILE 和 MASTER_LOG_FILE
~]# head -n 40 /tmp/master_dump.sql  
-- MySQL dump 10.13  Distrib 8.0.19, for Linux (x86_64)
--
-- Host: localhost    Database: 
-- ------------------------------------------------------
-- Server version       8.0.19

...
-- CHANGE MASTER TO MASTER_LOG_FILE='server1.000001', MASTER_LOG_FILE=419575;
...

# 将 master 指向主库
mysql> CHANGE MASTER TO MASTER_HOST='192.168.58.139',
    ->                  MASTER_USER='repl',
    ->                  MASTER_PASSWORD='MyNewPass@123',
    ->                  MASTER_LOG_FILE='server1.000001', 
    ->                  MASTER_LOG_POS=419575;
Query OK, 0 rows affected, 2 warnings (0.04 sec)

# 开始复制
mysql> start slave;
Query OK, 0 rows affected (0.01 sec)

mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.58.139
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: server1.000001
          Read_Master_Log_Pos: 3799819
               Relay_Log_File: node01-relay-bin.000002
                Relay_Log_Pos: 3380564
        Relay_Master_Log_File: server1.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: 3799819
              Relay_Log_Space: 3380773
              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: 100
                  Master_UUID: eff14492-6b5f-11ea-a887-000c298cc2bc
             Master_Info_File: mysql.slave_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: 
       Master_public_key_path: 
        Get_master_public_key: 0
            Network_Namespace: 
1 row in set (0.00 sec)

# 在主从上验证数据是否一致
mysql> select count(1) from test_tab;
+----------+
| count(1) |
+----------+
|    13156 |
+----------+
1 row in set (0.00 sec)

3、使用MHA实现Mysql高可用。

https://github.com/yoshinorim/mha4mysql-manager

https://github.com/yoshinorim/mha4mysql-node

https://github.com/yoshinorim/mha4mysql-manager/wiki

3.1 配置主从

在上面主从配置 2.4节 的基础上新增一个从节点

主机IP 角色
192.168.58.139 主、MHA Node
192.168.58.140 从、MHA Node
192.168.58.141 从、MHA Node
192.168.58.149 MHA Manager
# 在主库上查看 2 个从库
mysql> show slave hosts;
+-----------+------+------+-----------+--------------------------------------+
| Server_id | Host | Port | Master_id | Slave_UUID                           |
+-----------+------+------+-----------+--------------------------------------+
|       101 |      | 3306 |       100 | e37e0733-6b6a-11ea-aaac-000c2990c4ca |
|       102 |      | 3306 |       100 | b713a552-6b6a-11ea-94c2-000c29fad781 |
+-----------+------+------+-----------+--------------------------------------+
2 rows in set (0.00 sec)

# 创建 MHA 管理用户
mysql> CREATE USER dba_mha@'192.168.58.%' IDENTIFIED WITH mysql_native_password BY 'MyNewPass@123';
Query OK, 0 rows affected (0.01 sec)

mysql> GRANT ALL PRIVILEGES ON *.* TO dba_mha@'192.168.58.%';
Query OK, 0 rows affected (0.00 sec)

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

3.2 配置SSH免密

# 在192.168.58.139上配置免密,配置完免密以后 4 台机器可以相互免密
~]# ssh-keygen 
~]# ssh-copy-id 192.168.58.139
~]# scp -r .ssh [email protected]:/root/
~]# scp -r .ssh [email protected]:/root/
~]# scp -r .ssh [email protected]:/root/

3.3 安装配置 MHA Manager

~]# yum install epel-release -y

~]# yum install perl-DBD-MySQL \
            perl-Config-Tiny \
            perl-Log-Dispatch \
            perl-Parallel-ForkManager -y
            
~]# rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch.rpm 
~]# rpm -ivh mha4mysql-manager-0.58-0.el7.centos.noarch.rpm

~]# mkdir -p /usr/local/mha
~]# mkdir -p /etc/mha  

~]# cat /etc/mha/mha.conf
[server default]
# mysql user and password
user=dba_mha
password=MyNewPass@123

repl_user=repl
repl_password=MyNewPass@123

# working directory on the manager
manager_workdir=/usr/local/mha

# manager log file
manager_log=/usr/local/mha/manager.log

# working directory on MySQL servers
remote_workdir=/usr/local/mha

master_binlog_dir= /data/mysql/binlogs/

master_ip_failover_script = /usr/local/mha/master_ip_failover -network_type=ens33 --gateway=192.168.58.2 --virtual_ip=192.168.58.110 --key=2

secondary_check_script = /usr/bin/masterha_secondary_check -s 192.168.58.139 -s 192.168.58.140 -s 192.168.58.141

[server1]
hostname=192.168.58.139
candidate_master=1

[server2]
hostname=192.168.58.140
candidate_master=1

[server3]
hostname=192.168.58.141
no_master=1


~]# vi /usr/local/mha/master_ip_failover     
#!/usr/bin/env perl

use strict;
use warnings FATAL => 'all';

use Getopt::Long;

my (
    $command, $orig_master_host, $orig_master_ip,$ssh_user,
    $orig_master_port, $new_master_host, $new_master_ip,$new_master_port,
    $orig_master_ssh_port,$new_master_ssh_port,$new_master_user,$new_master_password
);

my $vip = '192.168.56.110/24';
my $key = '1';
my $ssh_start_vip = "/sbin/ifconfig enp0s3:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig enp0s3:$key down";
my $ssh_Bcast_arp= "/sbin/arping -I enp0s3 -c 3 -A 192.168.56.110";

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,
    'orig_master_ssh_port=i' => \$orig_master_ssh_port,
    'new_master_host=s'  => \$new_master_host,
    'new_master_ip=s'    => \$new_master_ip,
    'new_master_port=i'  => \$new_master_port,
    'new_master_ssh_port' => \$new_master_ssh_port,
    'new_master_user' => \$new_master_user,
    'new_master_password' => \$new_master_password

);

exit &main();

sub main {
    $ssh_user = defined $ssh_user ? $ssh_user : 'root';
    print "\n\nIN SCRIPT TEST====$ssh_user|$ssh_stop_vip==$ssh_user|$ssh_start_vip===\n\n";

    if ( $command eq "stop" || $command eq "stopssh" ) {

        my $exit_code = 1;
        eval {
            print "Disabling the VIP on old master: $orig_master_host \n";
            &stop_vip();
            $exit_code = 0;
        };
        if ($@) {
            warn "Got Error: $@\n";
            exit $exit_code;
        }
        exit $exit_code;
    }
    elsif ( $command eq "start" ) {

        my $exit_code = 10;
        eval {
            print "Enabling the VIP - $vip on the new master - $new_master_host \n";
            &start_vip();
            &start_arp();
            $exit_code = 0;
        };
        if ($@) {
            warn $@;
            exit $exit_code;
        }
        exit $exit_code;
    }
    elsif ( $command eq "status" ) {
        print "Checking the Status of the script.. OK \n";
        exit 0;
    }
    else {
        &usage();
        exit 1;
    }
}

sub start_vip() {
    `ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
}
sub stop_vip() {
    `ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;
}

sub start_arp() {
    `ssh $ssh_user\@$new_master_host \" $ssh_Bcast_arp \"`;
}
sub usage {
    print
    "Usage: master_ip_failover --command=start|stop|stopssh|status --ssh_user=user --orig_master_host=host --orig_master_ip=ip --orig_master_port=port --new_master_host=host --new_master_ip=ip --new_master_port=port\n";
    }
    
~]# chmod +x /usr/local/mha/master_ip_failover

~]# masterha_check_ssh --conf=/etc/mha/mha.conf     
Sun Mar 22 02:56:24 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sun Mar 22 02:56:24 2020 - [info] Reading application default configuration from /etc/mha/mha.conf..
Sun Mar 22 02:56:24 2020 - [info] Reading server configuration from /etc/mha/mha.conf..
Sun Mar 22 02:56:24 2020 - [info] Starting SSH connection tests..
Sun Mar 22 02:56:26 2020 - [debug] 
Sun Mar 22 02:56:24 2020 - [debug]  Connecting via SSH from [email protected](192.168.58.139:22) to [email protected](192.168.58.140:22)..
Sun Mar 22 02:56:25 2020 - [debug]   ok.
Sun Mar 22 02:56:25 2020 - [debug]  Connecting via SSH from [email protected](192.168.58.139:22) to [email protected](192.168.58.141:22)..
Sun Mar 22 02:56:25 2020 - [debug]   ok.
Sun Mar 22 02:56:27 2020 - [debug] 
Sun Mar 22 02:56:25 2020 - [debug]  Connecting via SSH from [email protected](192.168.58.141:22) to [email protected](192.168.58.139:22)..
Sun Mar 22 02:56:26 2020 - [debug]   ok.
Sun Mar 22 02:56:26 2020 - [debug]  Connecting via SSH from [email protected](192.168.58.141:22) to [email protected](192.168.58.140:22)..
Sun Mar 22 02:56:26 2020 - [debug]   ok.
Sun Mar 22 02:56:27 2020 - [debug] 
Sun Mar 22 02:56:25 2020 - [debug]  Connecting via SSH from [email protected](192.168.58.140:22) to [email protected](192.168.58.139:22)..
Sun Mar 22 02:56:25 2020 - [debug]   ok.
Sun Mar 22 02:56:25 2020 - [debug]  Connecting via SSH from [email protected](192.168.58.140:22) to [email protected](192.168.58.141:22)..
Sun Mar 22 02:56:26 2020 - [debug]   ok.
Sun Mar 22 02:56:27 2020 - [info] All SSH connection tests passed successfully.


~]# masterha_check_repl --conf=/etc/mha/mha.conf                                                                              Mon Mar 23 01:19:16 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Mar 23 01:19:16 2020 - [info] Reading application default configuration from /etc/mha/mha.conf..
Mon Mar 23 01:19:16 2020 - [info] Reading server configuration from /etc/mha/mha.conf..
Mon Mar 23 01:19:16 2020 - [info] MHA::MasterMonitor version 0.58.
Mon Mar 23 01:19:18 2020 - [info] GTID failover mode = 0
Mon Mar 23 01:19:18 2020 - [info] Dead Servers:
Mon Mar 23 01:19:18 2020 - [info] Alive Servers:
Mon Mar 23 01:19:18 2020 - [info]   192.168.58.139(192.168.58.139:3306)
Mon Mar 23 01:19:18 2020 - [info]   192.168.58.140(192.168.58.140:3306)
Mon Mar 23 01:19:18 2020 - [info]   192.168.58.141(192.168.58.141:3306)
Mon Mar 23 01:19:18 2020 - [info] Alive Slaves:
Mon Mar 23 01:19:18 2020 - [info]   192.168.58.140(192.168.58.140:3306)  Version=8.0.19 (oldest major version between slaves) log-bin:enabled
Mon Mar 23 01:19:18 2020 - [info]     Replicating from 192.168.58.139(192.168.58.139:3306)
Mon Mar 23 01:19:18 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Mon Mar 23 01:19:18 2020 - [info]   192.168.58.141(192.168.58.141:3306)  Version=8.0.19 (oldest major version between slaves) log-bin:enabled
Mon Mar 23 01:19:18 2020 - [info]     Replicating from 192.168.58.139(192.168.58.139:3306)
Mon Mar 23 01:19:18 2020 - [info]     Not candidate for the new Master (no_master is set)
Mon Mar 23 01:19:18 2020 - [info] Current Alive Master: 192.168.58.139(192.168.58.139:3306)
Mon Mar 23 01:19:18 2020 - [info] Checking slave configurations..
Mon Mar 23 01:19:18 2020 - [info]  read_only=1 is not set on slave 192.168.58.140(192.168.58.140:3306).
Mon Mar 23 01:19:18 2020 - [warning]  relay_log_purge=0 is not set on slave 192.168.58.140(192.168.58.140:3306).
Mon Mar 23 01:19:18 2020 - [info]  read_only=1 is not set on slave 192.168.58.141(192.168.58.141:3306).
Mon Mar 23 01:19:18 2020 - [warning]  relay_log_purge=0 is not set on slave 192.168.58.141(192.168.58.141:3306).
Mon Mar 23 01:19:18 2020 - [info] Checking replication filtering settings..
Mon Mar 23 01:19:18 2020 - [info]  binlog_do_db= , binlog_ignore_db= 
Mon Mar 23 01:19:18 2020 - [info]  Replication filtering check ok.
Mon Mar 23 01:19:18 2020 - [info] GTID (with auto-pos) is not supported
Mon Mar 23 01:19:18 2020 - [info] Starting SSH connection tests..
Mon Mar 23 01:19:20 2020 - [info] All SSH connection tests passed successfully.
Mon Mar 23 01:19:20 2020 - [info] Checking MHA Node version..
Mon Mar 23 01:19:21 2020 - [info]  Version check ok.
Mon Mar 23 01:19:21 2020 - [info] Checking SSH publickey authentication settings on the current master..
Mon Mar 23 01:19:21 2020 - [info] HealthCheck: SSH to 192.168.58.139 is reachable.
Mon Mar 23 01:19:21 2020 - [info] Master MHA Node version is 0.58.
Mon Mar 23 01:19:21 2020 - [info] Checking recovery script configurations on 192.168.58.139(192.168.58.139:3306)..
Mon Mar 23 01:19:21 2020 - [info]   Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/data/mysql/binlogs/ --output_file=/usr/local/mha/save_binary_logs_test --manager_version=0.58 --start_file=server1.000002 
Mon Mar 23 01:19:21 2020 - [info]   Connecting to [email protected](192.168.58.139:22).. 
  Creating /usr/local/mha if not exists..    ok.
  Checking output directory is accessible or not..
   ok.
  Binlog found at /data/mysql/binlogs/, up to server1.000002
Mon Mar 23 01:19:21 2020 - [info] Binlog setting check done.
Mon Mar 23 01:19:21 2020 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Mon Mar 23 01:19:21 2020 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='dba_mha' --slave_host=192.168.58.140 --slave_ip=192.168.58.140 --slave_port=3306 --workdir=/usr/local/mha --target_version=8.0.19 --manager_version=0.58 --relay_dir=/var/lib/mysql --current_relay_log=node01-relay-bin.000005  --slave_pass=xxx
Mon Mar 23 01:19:21 2020 - [info]   Connecting to [email protected](192.168.58.140:22).. 
  Checking slave recovery environment settings..
    Relay log found at /var/lib/mysql, up to node01-relay-bin.000005
    Temporary relay log file is /var/lib/mysql/node01-relay-bin.000005
    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 Mar 23 01:19:22 2020 - [info]   Executing command : apply_diff_relay_logs --command=test --slave_user='dba_mha' --slave_host=192.168.58.141 --slave_ip=192.168.58.141 --slave_port=3306 --workdir=/usr/local/mha --target_version=8.0.19 --manager_version=0.58 --relay_dir=/var/lib/mysql --current_relay_log=node02-relay-bin.000005  --slave_pass=xxx
Mon Mar 23 01:19:22 2020 - [info]   Connecting to [email protected](192.168.58.141:22).. 
  Checking slave recovery environment settings..
    Relay log found at /var/lib/mysql, up to node02-relay-bin.000005
    Temporary relay log file is /var/lib/mysql/node02-relay-bin.000005
    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 Mar 23 01:19:22 2020 - [info] Slaves settings check done.
Mon Mar 23 01:19:22 2020 - [info] 
192.168.58.139(192.168.58.139:3306) (current master)
 +--192.168.58.140(192.168.58.140:3306)
 +--192.168.58.141(192.168.58.141:3306)

Mon Mar 23 01:19:22 2020 - [info] Checking replication health on 192.168.58.140..
Mon Mar 23 01:19:22 2020 - [info]  ok.
Mon Mar 23 01:19:22 2020 - [info] Checking replication health on 192.168.58.141..
Mon Mar 23 01:19:22 2020 - [info]  ok.
Mon Mar 23 01:19:22 2020 - [info] Checking master_ip_failover_script status:
Mon Mar 23 01:19:22 2020 - [info]   /usr/local/mha/master_ip_failover -network_type=ens33 --gateway=192.168.58.2 --virtual_ip=192.168.58.110 --key=2 --command=status --ssh_user=root --orig_master_host=192.168.58.139 --orig_master_ip=192.168.58.139 --orig_master_port=3306 


IN SCRIPT TEST
/sbin/ifconfig ens33:2 down
/sbin/ifconfig ens33:2 192.168.58.110 up



/sbin/arping -c1 -Iens33 -s192.168.58.110 192.168.58.2

Checking the Status of the script.. OK 
ens33: flags=4163  mtu 1500
        inet 192.168.58.139  netmask 255.255.255.0  broadcast 192.168.58.255
        inet6 fe80::2996:6c29:311c:45d  prefixlen 64  scopeid 0x20
        ether 00:0c:29:8c:c2:bc  txqueuelen 1000  (Ethernet)
        RX packets 10652  bytes 948242 (926.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10281  bytes 3024837 (2.8 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

ens33:2: flags=4163  mtu 1500
        inet 192.168.58.110  netmask 255.255.255.0  broadcast 192.168.58.255
        ether 00:0c:29:8c:c2:bc  txqueuelen 1000  (Ethernet)

lo: flags=73  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Mon Mar 23 01:19:22 2020 - [info]  OK.
Mon Mar 23 01:19:22 2020 - [warning] shutdown_script is not defined.
Mon Mar 23 01:19:22 2020 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.


~]# masterha_manager --conf=/etc/mha/mha.conf 
Mon Mar 23 01:30:57 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Mar 23 01:30:57 2020 - [info] Reading application default configuration from /etc/mha/mha.conf..
Mon Mar 23 01:30:57 2020 - [info] Reading server configuration from /etc/mha/mha.conf..

3.4 安装配置 MHA Node

~]# yum install perl-DBD-MySQL -y
~]# rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch.rpm 

你可能感兴趣的:(MySQL 主从复制与 MHA)