基于MHA的mysql集群架构实战

1. mysql MHA架构介绍

Mha(master high availability)目前在mysql高可用方面是一个相对成熟的解决方案,由日本DeNA公司youshimaton(现职Facebook公司)开发,是一套优秀的作为mysql高可用环境下故障切换和主从提升的高可用软件。在故障切换过程中,MHA能做到在0~30秒之内自动完成数据库的故障切换,并能在最大程度上保证数据的一致性(切换过程中)。
软件组成
MHA manager(管理节点): MHA Manager可以单独部署在一台机器上管理多个master-slave集群,也可以部署在一台slave节点上
MHA Node(数据节点):运行在每台Mysql服务器上,MHA Manager会定时探测集群中的master节点,当master出现故障是,它可以自动将最新数据的slave提升为master,然后将所有的slave重新指向新的master。整个故障转移过程对应用程序完全透明。

在MHA自动故障切换过程中,MHA 试图从宕机的主服务器上保存二进制日志,最大程度的保证数据的不丢失,但这种方法并不适用所有环境。如:主服务器硬件故障或无法通过ssh访问,MHA就没法保存二进制日志,只能进行转移而丢失了最新的数据。
MHA可以和半同步复制结合起来,如果只有一个slave已经收到了最新的二进制日志,MHA可以将最新的二进制日志应用于所有的slave服务器上。最大程度上保持所有节点的数据一致性。
目前MHA主要支持一主多从架构,要搭建MHA,要求集群中必须最少由三台数据库服务器,一主二从。
在这里插入图片描述
MHA工作原理总结
(1)从宕机崩溃的master保存二进制日志事件(binlog events)
(2)识别含有最新更新的slave
(3)应用差异的中继日志(relay log)到其他的slave
(4)提升一个slave为新的master
(5)使其他的slave连接新的master进行复制
MHA软件由两部分组成:Manager工具包和Node工具包
Manager工具包:

masterha_check_ssh       检查MHA的SSH配置状况
masterha_check_repl       检查MySQL复制状况
masterha_manger         启动MHA
masterha_check_status      检测当前MHA运行状态
masterha_master_monitor     检测master是否宕机
masterha_master_switch     控制故障转移(自动或者手动)
masterha_conf_host       添加或删除配置的server信息

Node工具包(通常由MHA Manager脚本触发,无需人为操作)

save_binary_logs        保存和复制master的二进制日志
apply_diff_relay_logs      识别差异的中继日志事件并将其差异的事件应用于其他的slave
purge_relay_logs        清除中继日志(不会阻塞SQL线程)

2 MHA部署

角色IP地址主机名server_id类型
master/MHA manager192.168.10. 11server0111写入/监控复制组
slave/备选Master192.168.10.102server0222
slave192.168.10.103server0333

其中master对外提供写服务,备选master提供读服务,slave也提供相关读服务,一旦master宕机,将会把备选master提升为新的master,slave指向新的master

2.1 环境准备

[root@server02 ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

(1)三节点配置epel的yum源

[root@server01 yum.repos.d]# yum list | grep epel*
epel-release.noarch                         7-12                       @epel
[root@server01 yum.repos.d]# yum install epel-release
[root@server01 yum.repos.d]# yum install perl-DBD-MySQL  -y

(2)配置hosts文件(三个节点)

[root@server01 ~]# vim /etc/hosts
192.168.10.11 master
192.168.10.102 mysql01
192.168.10.103 mysql03

(3)同步时钟源(三个节点)

[root@server01 ~]# yum -y install ntp ntpdate
[root@server01 ~]# ntpdate cn.pool.ntp.org
[root@server01 ~]# hwclock --systohc

(4)处理防火墙

[root@server01 ~]# systemctl status firewalld
[root@server01 ~]# systemctl disable firewalld
[root@server01 ~]# setenforce 0

2.2 配置主从

(1)初始化master上的数据库

[root@server01 ~]# systemctl stop mysqld
[root@server01 ~]# chkconfig mysqld off
[root@server01 ~]# rm -rf /var/lib/mysql/*

(2)修改配置文件

[root@server01 ~]# cp -p /etc/my.cnf{,bak}
[root@server01 ~]# vim /etc/my.cnf
[mysqld]
server-id = 11
gtid_mode = ON
enforce-gtid-consistency = true
master_info_repository = TABLE
relay_log_info_repository = TABLE
log_slave_updates = ON
log_bin = binlog
binlog_format = ROW
datadoe = /var/lib/mysql
socket = /var/lib/mysql/mysql.sock

log-error = /var/log/mysqld.log
pid-file = /var/run/mysqld/mysqld.pid

default_authentication_plugin = mysql_native_password # 一定要修改密码认证方式

# mysql01和mysql02端只是server_id不同
[root@server01 ~]# scp /etc/my.cnf 192.168.10.102:/etc/
[root@server01 ~]# scp /etc/my.cnf 192.168.10.103:/etc/

(3)主节点配置

# 启动mysql服务
[root@server01 ~]# systemctl restart mysqld
# 初始化
[root@server01 ~]# mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:

Re-enter new password:

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!
# 登录数据库
[root@master ~]# mysql -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.20 MySQL Community Server - GPL

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.
# 查看master文件位置,端口
mysql> show master status;
+---------------+----------+--------------+------------------+------------------------------------------+
| File          | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set                        |
+---------------+----------+--------------+------------------+------------------------------------------+
| binlog.000002 |      825 |              |                  | 336156bd-dd44-11ea-b369-000c296ca965:1-3 |
+---------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)
# 创建登录用户
mysql> create user 'copy'@'%' identified with mysql_native_password by 'ABC123.com';
Query OK, 0 rows affected (0.00 sec)
# 授权
mysql> grant replication slave on *.* to 'copy'@'%';
Query OK, 0 rows affected (0.01 sec)
# 锁表
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)

slave端测试

[root@server02 ~]# mysql -h192.168.10.11 -ucopy -pABC123.com
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.

[root@server03 ~]# mysql -h192.168.10.11 -ucopy -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12

(4)slave端配置

1) server02端配置
# 还原数据库    --- 省略
# 初始化数据库  --- 省略
root@server02 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.20 MySQL Community Server - GPL

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> CHANGE MASTER TO
    -> MASTER_HOST='192.168.10.11',
    -> master_user='copy',
    -> master_password='ABC123.com',
    -> master_log_file='binlog.000002',
    -> master_log_pos=825;
Query OK, 0 rows affected, 2 warnings (1.90 sec)
mysql> start slave;
Query OK, 0 rows affected (0.20 sec)

mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.10.11
                  Master_User: copy
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binlog.000002
          Read_Master_Log_Pos: 1328
               Relay_Log_File: mysql01-relay-bin.000002
                Relay_Log_Pos: 824
        Relay_Master_Log_File: binlog.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              ···
2)server03端配置

和上面相同

mysql> CHANGE MASTER TO
    -> MASTER_HOST='192.168.10.11',
    -> master_user='copy',
    -> master_password='ABC123.com',
    -> master_log_file='binlog.000002',
    -> master_log_pos=825;
Query OK, 0 rows affected, 2 warnings (0.86 sec)

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

mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.10.11
                  Master_User: copy
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: binlog.000002
          Read_Master_Log_Pos: 1328
               Relay_Log_File: mysql02-relay-bin.000002
                Relay_Log_Pos: 824
        Relay_Master_Log_File: binlog.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
            ···

(5) 测试

1)master端创建一个库(server01)
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
mysql> create database test1;
Query OK, 1 row affected (0.00 sec)
2)server02端查看
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test1              |
+--------------------+
5 rows in set (0.26 sec)
3)server03端查看
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test1              |
+--------------------+
5 rows in set (0.26 sec)

2.3 配置免密互信

分别在三个节点执行如下操作

[root@server01 ~]# 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:l7TGsLhentLreaX7vvp2Ofa0I1e9dtJqLb1iJSMW2LE root@master
The key's randomart image is:
+---[RSA 2048]----+
|                 |
|           .     |
|        . + o    |
|       . * E     |
|      . S * .   .|
|       . o o.o .o|
|      ... .o. +=+|
|     ..o.oo .+O**|
|      .o*ooB*=*O=|
+----[SHA256]-----+
# 给自己发送密钥
[root@server01 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.10.11
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.10.11 (192.168.10.11)' can't be established.
ECDSA key fingerprint is SHA256:r7VD2YCy0giwyViGlq6IByoTKbpGg0FwS/wfKfzgIic.
ECDSA key fingerprint is MD5:4a:b3:02:65:e1:c4:29:c9:f8:6d:b4:77:37:cb:fe:39.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/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.10.11's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.10.11'"
and check to make sure that only the key(s) you wanted were added.
# 给mysql01发送密钥
[root@server01 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.10.102
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.10.102 (192.168.10.102)' can't be established.
ECDSA key fingerprint is SHA256:UNKQXWrtav8/Mv6mjRAgETC+tIKWz9MSlg7v09qeF0U.
ECDSA key fingerprint is MD5:e9:89:cd:2f:ed:3f:4d:82:df:d4:0e:66:7c:00:25:47.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/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.10.102's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.10.102'"
and check to make sure that only the key(s) you wanted were added.
# 给mysql02发送密钥
[root@server01 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@192.168.10.103
/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host '192.168.10.103 (192.168.10.103)' can't be established.
ECDSA key fingerprint is SHA256:UNKQXWrtav8/Mv6mjRAgETC+tIKWz9MSlg7v09qeF0U.
ECDSA key fingerprint is MD5:e9:89:cd:2f:ed:3f:4d:82:df:d4:0e:66:7c:00:25:47.
Are you sure you want to continue connecting (yes/no)? yes
/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/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.10.103's password:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'root@192.168.10.103'"
and check to make sure that only the key(s) you wanted were added.

2.4 安装MHA

(1)mysql节点上安装(三个)

[root@server02 ~]# wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@server02 ~]# rpm -ivh epel-release-latest-7.noarch.rpm
[root@server02 ~]# yum install -y perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager
[root@server02 ~]# wget https://qiniu.wsfnk.com/mha4mysql-node-0.58-0.el7.centos.noarch.rpm
[root@server02 ~]# rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch.rpm

(2)manager节点上

[root@server01 ~]# wget https://qiniu.wsfnk.com/mha4mysql-manager-0.58-0.el7.centos.noarch.rpm
[root@server01 ~]# rpm -ivh mha4mysql-manager-0.58-0.el7.centos.noarch.rpm

(3)manager创建MHA工作目录,并创建相关配置

[root@server01 ~]# mkdir -p /etc/masterha
[root@server01 ~]# cd /etc/masterha/
[root@server01 masterha]# vim app1.cnf
[server default]
manager_workdir=/etc/masterha/
manager_log=/etc/masterha/app1.log
master_binlog_dir=/var/lib/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=Cloudbu@123
ping_interval=1
remote_workdir=/tmp
repl_user=copy
repl_password=Cloudbu@123
#report_script=/usr/local/send_report
#secondary_check_script=/usr/local/bin/masterha_secondary_check -s server03 -s server02
#shutdown_script=""
ssh_user=root

[server01]
hostname=192.168.10.11
port=3306

[server02]
hostname=192.168.10.102
port=3306
candidate_master=1
check_repl_delay=0

[server03]
hostname=192.168.10.103
port=3306
#no_master=1

(4)检查MHA Manager到所有MHA Node的ssh连接状态

注意:一定要在三台机器上面测试ssh链接,ssh server01;ssh server02;ssh server03.否则会报错
注:本人因之前设置的master主机名为master(现改为server01),mysql01(现改为server02),mysql02(现改为server03),测试这个的时候一直报错master,mysql01,mysql02是无效的,无奈改了主机名,hosts文件,app1配置文件。这才完成

[root@server01 ~]# masterha_check_ssh --conf=/etc/masterha/app1.cnf
Fri Aug 14 10:55:12 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Fri Aug 14 10:55:12 2020 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Fri Aug 14 10:55:12 2020 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Fri Aug 14 10:55:12 2020 - [info] Starting SSH connection tests..
Fri Aug 14 10:55:15 2020 - [debug]
Fri Aug 14 10:55:12 2020 - [debug]  Connecting via SSH from root@192.168.10.11(192.168.10.11:22) to root@192.168.10.102(192.168.10.102:22)..
Fri Aug 14 10:55:13 2020 - [debug]   ok.
Fri Aug 14 10:55:13 2020 - [debug]  Connecting via SSH from root@192.168.10.11(192.168.10.11:22) to root@192.168.10.103(192.168.10.103:22)..
Fri Aug 14 10:55:15 2020 - [debug]   ok.
Fri Aug 14 10:55:16 2020 - [debug]
Fri Aug 14 10:55:13 2020 - [debug]  Connecting via SSH from root@192.168.10.103(192.168.10.103:22) to root@192.168.10.11(192.168.10.11:22)..
Fri Aug 14 10:55:15 2020 - [debug]   ok.
Fri Aug 14 10:55:15 2020 - [debug]  Connecting via SSH from root@192.168.10.103(192.168.10.103:22) to root@192.168.10.102(192.168.10.102:22)..
Fri Aug 14 10:55:16 2020 - [debug]   ok.
Fri Aug 14 10:55:16 2020 - [debug]
Fri Aug 14 10:55:13 2020 - [debug]  Connecting via SSH from root@192.168.10.102(192.168.10.102:22) to root@192.168.10.11(192.168.10.11:22)..
Fri Aug 14 10:55:14 2020 - [debug]   ok.
Fri Aug 14 10:55:14 2020 - [debug]  Connecting via SSH from root@192.168.10.102(192.168.10.102:22) to root@192.168.10.103(192.168.10.103:22)..
Fri Aug 14 10:55:16 2020 - [debug]   ok.
Fri Aug 14 10:55:16 2020 - [info] All SSH connection tests passed successfully.

(5)给root授权(server01即可)

mysql> create user 'root'@'%' identified by 'ABC123.com';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all on *.* to 'root'@'%' with grant option;
Query OK, 0 rows affected (0.01 sec)

(6)通过masterha_check_repl脚本查看整个集群状态

[root@server01 ~]# masterha_check_repl --conf=/etc/masterha/app1.cnf
Fri Aug 14 11:29:34 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Fri Aug 14 11:29:34 2020 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Fri Aug 14 11:29:34 2020 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Fri Aug 14 11:29:34 2020 - [info] MHA::MasterMonitor version 0.58.
Fri Aug 14 11:29:35 2020 - [info] GTID failover mode = 1
Fri Aug 14 11:29:35 2020 - [info] Dead Servers:
Fri Aug 14 11:29:35 2020 - [info] Alive Servers:
Fri Aug 14 11:29:35 2020 - [info]   192.168.10.11(192.168.10.11:3306)
Fri Aug 14 11:29:35 2020 - [info]   192.168.10.102(192.168.10.102:3306)
Fri Aug 14 11:29:35 2020 - [info]   192.168.10.103(192.168.10.103:3306)
Fri Aug 14 11:29:35 2020 - [info] Alive Slaves:
Fri Aug 14 11:29:35 2020 - [info]   192.168.10.102(192.168.10.102:3306)  Version=8.0.20 (oldest major version between slaves) log-bin:enabled
Fri Aug 14 11:29:35 2020 - [info]     GTID ON
Fri Aug 14 11:29:35 2020 - [info]     Replicating from 192.168.10.11(192.168.10.11:3306)
Fri Aug 14 11:29:35 2020 - [info]     Primary candidate for the new Master (candidate_master is set)
Fri Aug 14 11:29:35 2020 - [info]   192.168.10.103(192.168.10.103:3306)  Version=8.0.20 (oldest major version between slaves) log-bin:enabled
Fri Aug 14 11:29:35 2020 - [info]     GTID ON
Fri Aug 14 11:29:35 2020 - [info]     Replicating from 192.168.10.11(192.168.10.11:3306)
Fri Aug 14 11:29:35 2020 - [info] Current Alive Master: 192.168.10.11(192.168.10.11:3306)
Fri Aug 14 11:29:35 2020 - [info] Checking slave configurations..
Fri Aug 14 11:29:35 2020 - [info]  read_only=1 is not set on slave 192.168.10.102(192.168.10.102:3306).
Fri Aug 14 11:29:35 2020 - [info]  read_only=1 is not set on slave 192.168.10.103(192.168.10.103:3306).
Fri Aug 14 11:29:35 2020 - [info] Checking replication filtering settings..
Fri Aug 14 11:29:35 2020 - [info]  binlog_do_db= , binlog_ignore_db=
Fri Aug 14 11:29:35 2020 - [info]  Replication filtering check ok.
Fri Aug 14 11:29:35 2020 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Fri Aug 14 11:29:35 2020 - [info] Checking SSH publickey authentication settings on the current master..
Fri Aug 14 11:29:36 2020 - [info] HealthCheck: SSH to 192.168.10.11 is reachable.
Fri Aug 14 11:29:36 2020 - [info]
192.168.10.11(192.168.10.11:3306) (current master)
 +--192.168.10.102(192.168.10.102:3306)
 +--192.168.10.103(192.168.10.103:3306)

Fri Aug 14 11:29:36 2020 - [info] Checking replication health on 192.168.10.102..
Fri Aug 14 11:29:36 2020 - [info]  ok.
Fri Aug 14 11:29:36 2020 - [info] Checking replication health on 192.168.10.103..
Fri Aug 14 11:29:36 2020 - [info]  ok.
Fri Aug 14 11:29:36 2020 - [warning] master_ip_failover_script is not defined.
Fri Aug 14 11:29:36 2020 - [warning] shutdown_script is not defined.
Fri Aug 14 11:29:36 2020 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.

2.5 测试

(1)手动切换

1)将server01的master切换到server02上

[root@server01 ~]# masterha_master_switch --conf=/etc/masterha/app1.cnf --master                                                                                  _state=alive --new_master_host=192.168.10.102 --new_master_port=3306 --orig_mast                                                                                  er_is_new_slave
Fri Aug 14 11:31:26 2020 - [info] MHA::MasterRotate version 0.58.
Fri Aug 14 11:31:26 2020 - [info] Starting online master switch..
Fri Aug 14 11:31:26 2020 - [info]
Fri Aug 14 11:31:26 2020 - [info] * Phase 1: Configuration Check Phase..
Fri Aug 14 11:31:26 2020 - [info]
# 所有提示均为yes
···
It is better to execute FLUSH NO_WRITE_TO_BINLOG TABLES on the master before swi                                                                                   tching. Is it ok to execute on 192.168.10.11(192.168.10.11:3306)? (YES/no): yes
Fri Aug 14 11:31:31 2020 - [info] Executing FLUSH NO_WRITE_TO_BINLOG TABLES. Thi                                                                                   s may take long time..
···
Starting master switch from 192.168.10.11(192.168.10.11:3306) to 192.168.10.102(                                                                                   192.168.10.102:3306)? (yes/NO): yes
Fri Aug 14 11:31:35 2020 - [info] Checking whether 192.168.10.102(192.168.10.102                                                                                   :3306) is ok for the new master..
···
master_ip_online_change_script is not defined. If you do not disable writes on t                                                                                   he current master manually, applications keep writing on the current master. Is                                                                                    it ok to proceed? (yes/NO): yes
Fri Aug 14 11:31:37 2020 - [info] Locking all tables on the orig master to rejec                                                                                   t updates from everybody (including root):
···
Fri Aug 14 11:31:40 2020 - [info]  192.168.10.102: Resetting slave info succeede                                                                                   d.
Fri Aug 14 11:31:40 2020 - [info] Switching master to 192.168.10.102(192.168.10.                                                                                   102:3306) completed successfully.

2)在server02端查看已经变成master端
在这里插入图片描述
3)在server01端和server03端查看主端为server02
在这里插入图片描述
在这里插入图片描述
4)在server02端创建数据库test2

mysql> create database test2;
Query OK, 1 row affected (0.03 sec)

5)在server01和server02端查看数据同步

# server01
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test1              |
| test2              |
+--------------------+
6 rows in set (0.01 sec)
# server03
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| test1              |
| test2              |
+--------------------+
6 rows in set (0.01 sec)

(2)自动切换

1)启动进程

[root@server01 ~]# nohup masterha_manager --conf=/etc/masterha/app1.cnf --ignore_last_failover &
[1] 8478
[root@server01 ~]# ls
nohup.out

2)模拟故障

[root@server02 ~]# systemctl stop mysqld

3)在server03上查看
在这里插入图片描述
4)在server01上查看
在这里插入图片描述
#配置完成
------------------------------------------------------------------------------------------------------- 返回目录

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值