一、多机互信的步骤

双机互信的步骤

第一步:在master管理服务器上ssh-keygen

在master同一台管理服务器上重新开一个窗口ssh-copy-id 192.168.0.13自己给自己互信

ssh-copy-id 192.168.0.13两台管理服务器登录

第二步:在管理服务器上操作rsync -av .ssh 192.168.0.10:/root/

rsync -av .ssh 192.168.0.11:/root/

rsync -av .ssh 192.168.0.12:/root/将自己的秘钥复制到其他的服务器上

此时所有的服务器可以相互登录

配置了互信,那如果其中服务器的root用户修改了密码,需要重新配置互信吗?不需要

二、MHA实验步骤

1.部署一主两从

第一台服务器

###################################
#MHA
validate_password_policy=0
validate_password_length=4
log-bin=log-bin
server-id=1
skip-name-resolve
##################################

在第二台服务器/etc/my.cnf中添加

#############################
#MHA
validate_password_policy=0
validate_password_length=4
log-bin=log-bin
server-id=2
skip-name-resolve
#############################

并重启服务

第三台同样配置

############################################
#MHA
server-id=3
validate_password_policy=0
validate_password_length=4
log-bin=log-bin
skip-name-resolve
############################################

2.安装MHA

在管理服务器上安装

yum install perl-DBD-Mysql perl-Config-Tiny perl-Log-Dispatch perl-Parallel-G
ForkManager epel-*

yum repolist

yum install epel-* -y

yum localinstall mha4mysql-*.rpm -y

3.在第一主服务器、二从服务器、三从服务器台服务器以及管理服务器上操作:

yum localinstall mha4mysql-node-0.54-0.el6.noarch.rpm

4.在管理服务器上创建一个mha_manager目录

进入目录创建配置文件vim  app1.conf

编写内容

[server default]
manager_workdir=/etc/mha_manager
manager_log=/etc/mha_manager/manager.log
ssh_user=root
ssh_port=22
user=root
password=123456
repl_user=repl
repl_password=123456
[server1]
hostname=192.168.0.10
candidate_master=1
[server2]
hostname=192.168.0.11
candidate_master=1
[server3]
hostname=192.168.0.12

5.[root@localhost mha_manager]# masterha_check_ssh --conf=app.conf

masterha_check_repl --conf=app1.conf检查repl节点、、、报错

在第一台服务器上登录mysql

grant replication slave on *.* to repl@'192.168.0.%'identified by '123456';

grant all on *.* to root@'192.168.0.%'identified by '123456';

flush privileges;

6.在管理服务器上检测

masterha_check_repl --conf=app1.conf

在第一台服务器上/etc/my.cnf修改

###################################
#MHA
validate_password_policy=0
validate_password_length=4
log-bin=/var/lib/mysql/log-bin
server-id=1
skip-name-resolve
##################################并重启

在第一台服务器上重启mysql服务并刷新权限show master  status\G

在第二台服务器上刷新一样的pos节点号

在第三台服务器上刷新一样的pos节点号编写的脚本

mysql -p << EOF
change master to
master_host='192.168.0.10',
master_port=3306,
master_user='repl',
master_password='123456',
master_log_file='log-bin.000005',
master_log_pos=154;
EOF

7.在管理服务器上检测masterha_check_repl --conf=app1.conf

masterha_check_status --conf=app1.conf

masterha_check_manager --conf=app1.conf

在打开一个管理服务器终端

[root@localhost ~]# cd /etc/mha_manager/
[root@localhost mha_manager]# masterha_check_status --conf=app1.conf
app1 (pid:66906) is running(0:PING_OK), master:192.168.0.10配置成功

模拟主数据库宕机关闭mysql服务器service mysql stop

在管理服务器上观看

在第三台从服务器上查看master点换为刚刚设置的服务器了

在此之前MHA搭建完成      7.MHA manager 节点配置

mkdir /etc/mha_manager/建立mha manage工作目录
vim /etc/mha_manager/app1.conf 创建application1 集群
[server default]  # server默认配置
manager_workdir=/etc/mha_manager # 指定mha 工作目录
manager_log=/etc/mha_manager/manager.log #指定 mha 日志
master_ip_failover_script=/etc/mha_manager/master_ip_failover #指定mha 的vip漂移脚本
ssh_user=root #指定ssh user
ssh_port=22 #指定ssh port
user=root #指定mysql root
password=1234 # root密码
repl_user=repl #repl user
repl_password=1234 #repl user passwd
[server1] #指定server mysql
hostname=192.168.50.171 #server ip
candidate_master=1 # 设置此server是否抢占master
[server2]
hostname=192.168.50.4
candidate_master=1
[server3]
hostname=192.168.50.130

8.yum localinstall mha4mysql-master-0.55-0.e16.noarch.rpm

9.master_check_ssh --conf=/etc/m

10.master_check_repl --conf=/etc/m

11.登录mysql  grant replication slave on *.* to repl@192.168.0.%' identified by '123456';

12.grant all on *.* to root@'192.168.0.%'identified by'123456';

13.flush privileges;

14.master_check_repl --conf=/etc/m

15.在主服务器的/etc/my.cnf下修改log-bin=log-bin修改为log-bin=/var/lib/mysql/log-bin

16.重启数据库

17.master_check_repl --conf=/etc/m

18.主从出错解决方法:重新搭建主从重新在主服务器查看pos点show master status\G

vim /var/lib/mysql/master,info修改pos点然后再数据库中stop  slave  重启slave

重启mysql   登录数据库show status slave\G  重新做主从vim slave.sh  启动mysql

19.master_check_status  --conf=app1.conf

20.master_manager  --conf=app1.conf

21.在第四台查看:masterha_check_statua  --cong=app1.conf

22.模拟master故障直接停止mysql 在第一台上service mysqld stop

23.在第四台上查看    在第三台上查看登录mysql   show slave status\G

24.还可以查看日志vim manager.log

8.3 MHA 搭建

 

操作步骤

1.配置主从

1.1 master
/etc/my.cnf
server-id
log-bin
skip-name-resolve
1.2 master 建立repl用户
grant replication slave on *.* to repl@'192.168.50.%' identied by '1234';
show master status\G
1.3 slave
/etc/my.cnf
server-id
log-bin
skip-name-resolve
read_only
relay_log_purge=0
1.4 star slave
change master to ...

2.多机互信

ssh-keygen
ssh-copy-id 192.168.50.108
ssh root@192.168.50.108
rsync -av .ssh 192.168.50.171:/root/
rsync -av .ssh 192.168.50.130:/root/
rsync -av .ssh 192.168.50.4:/root/

3.MHA node 节点安装

所有MySQL服务器安装:
安装依赖
yum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager epel-* -y
安装软件包
yum localinstall mha4mysql-node-0.54-0.el6.noarch.rpm

4.MHA manager 节点安装

安装依赖
yum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager epel-* -y
安装软件包
yum localinstall mha4mysql-manager-0.55-0.el6.noarch.rpm mha4mysql-node-0.54-0.el6.noarch.rpm

5.MHA manager 节点配置

mkdir /etc/mha_manager/建立mha manage工作目录
vim /etc/mha_manager/app1.conf 创建application1 集群
[server default]  # server默认配置
manager_workdir=/etc/mha_manager # 指定mha 工作目录
manager_log=/etc/mha_manager/manager.log #指定 mha 日志
master_ip_failover_script=/etc/mha_manager/master_ip_failover #指定mha 的vip漂移脚本
ssh_user=root #指定ssh user
ssh_port=22 #指定ssh port
user=root #指定mysql root
password=1234 # root密码
repl_user=repl #repl user
repl_password=1234 #repl user passwd
[server1] #指定server mysql
hostname=192.168.50.171 #server ip
candidate_master=1 # 设置此server是否抢占master
[server2]
hostname=192.168.50.4
candidate_master=1
[server3]
hostname=192.168.50.130
漂移脚本需要更改的地方:
```
my $vip = '192.168.50.60/24'; # Virtual IP
my $key = "1";
my $ssh_start_vip = "/sbin/ifconfig ens33:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig ens33:$key down";
```
主要是vip和网卡名字
完整放在百度 云盘
5.1 授权:
grant all on *.* to root@'192.168.50.%' identified by '1234';
grant replication slave on *.* to repl@'192.168.50.%' identified by '1234';
5.2 检测启动
masterha_check_ssh:检测MHA的ssh配置情况
masterha_check_repl:检测MySQL复制情况
masterha_manager:启动mha
masterha_check_status 检测mha运行状态 masterha_check_ssh --conf=/etc/mha_manager/app1.conf
masterha_check_repl --conf=/etc/mha_manager/app1.conf
masterha_manager --conf=/etc/mha_manager/app1.conf 需要手动将 vip 配置在master上
ifconfig ens33:1 192.168.50.171
5.3 故障切换
关闭master MySQL,查看是否可以自动漂移ip和master是否重新指定即可。
5.4 如何恢复MHA
1.满足搭建MHA的条件
2.删除故障转移文件
rm /etc/mha_manager/app1.failover.complete

6.完整故障切换日志分析

Wed Aug 25 22:22:55 2021 - [info] MHA::MasterMonitor version 0.55.
Wed Aug 25 22:22:57 2021 - [info] Dead Servers:
Wed Aug 25 22:22:57 2021 - [info] Alive Servers:
Wed Aug 25 22:22:57 2021 - [info] 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:22:57 2021 - [info] 192.168.50.4(192.168.50.4:3306)
Wed Aug 25 22:22:57 2021 - [info] 192.168.50.130(192.168.50.130:3306)
Wed Aug 25 22:22:57 2021 - [info] Alive Slaves:
Wed Aug 25 22:22:57 2021 - [info] 192.168.50.4(192.168.50.4:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:22:57 2021 - [info] Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:22:57 2021 - [info] Primary candidate for the new Master (candidate_master is set)
Wed Aug 25 22:22:57 2021 - [info] 192.168.50.130(192.168.50.130:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:22:57 2021 - [info] Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:22:57 2021 - [info] Current Alive Master: 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:22:57 2021 - [info] Checking slave configurations..
Wed Aug 25 22:22:57 2021 - [info] Checking replication filtering settings..
Wed Aug 25 22:22:57 2021 - [info] binlog_do_db= , binlog_ignore_db=
Wed Aug 25 22:22:57 2021 - [info] Replication filtering check ok.
Wed Aug 25 22:22:57 2021 - [info] Starting SSH connection tests..
Wed Aug 25 22:22:59 2021 - [info] All SSH connection tests passed successfully.
Wed Aug 25 22:22:59 2021 - [info] Checking MHA Node version..
Wed Aug 25 22:23:00 2021 - [info] Version check ok.
Wed Aug 25 22:23:00 2021 - [info] Checking SSH publickey authentication settings on the current master..
Wed Aug 25 22:23:00 2021 - [info] HealthCheck: SSH to 192.168.50.171 is reachable.
Wed Aug 25 22:23:00 2021 - [info] Master MHA Node version is 0.54.
Wed Aug 25 22:23:00 2021 - [info] Checking recovery script configurations on the current master..
Wed Aug 25 22:23:00 2021 - [info] Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/var/lib/mysql,/var/log/mysql --output_file=/var/tmp/save_binary_logs_test --manager_version=0.55 --start_file=log-bin.000004
Wed Aug 25 22:23:00 2021 - [info] Connecting to root@192.168.50.171(192.168.50.171)..
Creating /var/tmp if not exists.. ok.
Checking output directory is accessible or not..
ok.
Binlog found at /var/lib/mysql, up to log-bin.000004
Wed Aug 25 22:23:01 2021 - [info] Master setting check done.
Wed Aug 25 22:23:01 2021 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Wed Aug 25 22:23:01 2021 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.50.4 --slave_ip=192.168.50.4 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.17-log --manager_version=0.55 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx
Wed Aug 25 22:23:01 2021 - [info] Connecting to root@192.168.50.4(192.168.50.4:22)..
Checking slave recovery environment settings..
Opening /var/lib/mysql/relay-log.info ... ok.
Relay log found at /var/lib/mysql, up to centos7-24-3-relay-bin.000002
Temporary relay log file is /var/lib/mysql/centos7-24-3-relay-bin.000002
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.
Wed Aug 25 22:23:01 2021 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.50.130 --slave_ip=192.168.50.130 --slave_port=3306 --workdir=/var/tmp --target_version=5.7.17-log --manager_version=0.55 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx
Wed Aug 25 22:23:01 2021 - [info] Connecting to root@192.168.50.130(192.168.50.130:22)..
Checking slave recovery environment settings..
Opening /var/lib/mysql/relay-log.info ... ok.
Relay log found at /var/lib/mysql, up to centos7-2-relay-bin.000002
Temporary relay log file is /var/lib/mysql/centos7-2-relay-bin.000002
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.
Wed Aug 25 22:23:02 2021 - [info] Slaves settings check done.
Wed Aug 25 22:23:02 2021 - [info]
192.168.50.171 (current master)
+--192.168.50.4
+--192.168.50.130 Wed Aug 25 22:23:02 2021 - [info] Checking master_ip_failover_script status:
Wed Aug 25 22:23:02 2021 - [info] /etc/mha_manager/master_ip_failover --command=status --ssh_user=root --orig_master_host=192.168.50.171 --orig_master_ip=192.168.50.171 --orig_master_port=3306
Wed Aug 25 22:23:02 2021 - [info] OK.
Wed Aug 25 22:23:02 2021 - [warning] shutdown_script is not defined.
Wed Aug 25 22:23:02 2021 - [info] Set master ping interval 3 seconds.
Wed Aug 25 22:23:02 2021 - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from two or more routes.
Wed Aug 25 22:23:02 2021 - [info] Starting ping health check on 192.168.50.171(192.168.50.171:3306)..
Wed Aug 25 22:23:02 2021 - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond.. #MHA启动日志
################################################################################ Wed Aug 25 22:24:08 2021 - [warning] Got error on MySQL select ping: 2006 (MySQL server has gone away)
Wed Aug 25 22:24:08 2021 - [info] Executing SSH check script: save_binary_logs --command=test --start_pos=4 --binlog_dir=/var/lib/mysql,/var/log/mysql --output_file=/var/tmp/save_binary_logs_test --manager_version=0.55 --binlog_prefix=log-bin
Wed Aug 25 22:24:08 2021 - [info] HealthCheck: SSH to 192.168.50.171 is reachable.
Wed Aug 25 22:24:11 2021 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.50.171' (111))
Wed Aug 25 22:24:11 2021 - [warning] Connection failed 1 time(s)..
Wed Aug 25 22:24:14 2021 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.50.171' (111))
Wed Aug 25 22:24:14 2021 - [warning] Connection failed 2 time(s)..
Wed Aug 25 22:24:17 2021 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.50.171' (111))
Wed Aug 25 22:24:17 2021 - [warning] Connection failed 3 time(s)..
Wed Aug 25 22:24:17 2021 - [warning] Master is not reachable from health checker!
Wed Aug 25 22:24:17 2021 - [warning] Master 192.168.50.171(192.168.50.171:3306) is not reachable!
Wed Aug 25 22:24:17 2021 - [warning] SSH is reachable.
Wed Aug 25 22:24:17 2021 - [info] Connecting to a master server failed. Reading configuration file /etc/masterha_default.cnf and app1.conf again, and trying to connect to all servers to check server status..
Wed Aug 25 22:24:17 2021 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Wed Aug 25 22:24:17 2021 - [info] Reading application default configurations from app1.conf..
Wed Aug 25 22:24:17 2021 - [info] Reading server configurations from app1.conf..
Wed Aug 25 22:24:18 2021 - [info] Dead Servers:
Wed Aug 25 22:24:18 2021 - [info] 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:18 2021 - [info] Alive Servers:
Wed Aug 25 22:24:18 2021 - [info] 192.168.50.4(192.168.50.4:3306)
Wed Aug 25 22:24:18 2021 - [info] 192.168.50.130(192.168.50.130:3306)
Wed Aug 25 22:24:18 2021 - [info] Alive Slaves:
Wed Aug 25 22:24:18 2021 - [info] 192.168.50.4(192.168.50.4:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:18 2021 - [info] Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:18 2021 - [info] Primary candidate for the new Master (candidate_master is set)
Wed Aug 25 22:24:18 2021 - [info] 192.168.50.130(192.168.50.130:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:18 2021 - [info] Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:18 2021 - [info] Checking slave configurations..
Wed Aug 25 22:24:18 2021 - [info] Checking replication filtering settings..
Wed Aug 25 22:24:18 2021 - [info] Replication filtering check ok.
Wed Aug 25 22:24:18 2021 - [info] Master is down!
Wed Aug 25 22:24:18 2021 - [info] Terminating monitoring script.
Wed Aug 25 22:24:18 2021 - [info] Got exit code 20 (Master dead).
Wed Aug 25 22:24:18 2021 - [info] MHA::MasterFailover version 0.55.
###########################################################################
#开始故障转移
Wed Aug 25 22:24:18 2021 - [info] Starting master failover.
Wed Aug 25 22:24:18 2021 - [info]
Wed Aug 25 22:24:18 2021 - [info] * Phase 1: Configuration Check Phase..
Wed Aug 25 22:24:18 2021 - [info]
Wed Aug 25 22:24:19 2021 - [info] Dead Servers:
Wed Aug 25 22:24:19 2021 - [info] 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:19 2021 - [info] Checking master reachability via mysql(double check)..
Wed Aug 25 22:24:19 2021 - [info] ok.
Wed Aug 25 22:24:19 2021 - [info] Alive Servers:
Wed Aug 25 22:24:19 2021 - [info] 192.168.50.4(192.168.50.4:3306)
Wed Aug 25 22:24:19 2021 - [info] 192.168.50.130(192.168.50.130:3306)
Wed Aug 25 22:24:19 2021 - [info] Alive Slaves:
Wed Aug 25 22:24:19 2021 - [info] 192.168.50.4(192.168.50.4:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:19 2021 - [info] Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:19 2021 - [info] Primary candidate for the new Master (candidate_master is set)
Wed Aug 25 22:24:19 2021 - [info] 192.168.50.130(192.168.50.130:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:19 2021 - [info] Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:19 2021 - [info] ** Phase 1: Configuration Check Phase completed.
Wed Aug 25 22:24:19 2021 - [info]
Wed Aug 25 22:24:19 2021 - [info] * Phase 2: Dead Master Shutdown Phase..
Wed Aug 25 22:24:19 2021 - [info]
Wed Aug 25 22:24:19 2021 - [info] Forcing shutdown so that applications never connect to the current master..
Wed Aug 25 22:24:19 2021 - [info] Executing master IP deactivatation script:
Wed Aug 25 22:24:19 2021 - [info] /etc/mha_manager/master_ip_failover --orig_master_host=192.168.50.171 --orig_master_ip=192.168.50.171 --orig_master_port=3306 --command=stopssh --ssh_user=root
Wed Aug 25 22:24:19 2021 - [info] done.
Wed Aug 25 22:24:19 2021 - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.
Wed Aug 25 22:24:19 2021 - [info] * Phase 2: Dead Master Shutdown Phase completed.
Wed Aug 25 22:24:19 2021 - [info]
Wed Aug 25 22:24:19 2021 - [info] * Phase 3: Master Recovery Phase..
Wed Aug 25 22:24:19 2021 - [info]
Wed Aug 25 22:24:19 2021 - [info] * Phase 3.1: Getting Latest Slaves Phase..
Wed Aug 25 22:24:19 2021 - [info]
Wed Aug 25 22:24:19 2021 - [info] The latest binary log file/position on all slaves is log-bin.000004:154
Wed Aug 25 22:24:19 2021 - [info] Latest slaves (Slaves that received relay log files to the latest):
Wed Aug 25 22:24:19 2021 - [info] 192.168.50.4(192.168.50.4:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:19 2021 - [info] Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:19 2021 - [info] Primary candidate for the new Master (candidate_master is set)
Wed Aug 25 22:24:19 2021 - [info] 192.168.50.130(192.168.50.130:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:19 2021 - [info] Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:19 2021 - [info] The oldest binary log file/position on all slaves is log-bin.000004:154
Wed Aug 25 22:24:19 2021 - [info] Oldest slaves:
Wed Aug 25 22:24:19 2021 - [info] 192.168.50.4(192.168.50.4:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:19 2021 - [info] Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:19 2021 - [info] Primary candidate for the new Master (candidate_master is set)
Wed Aug 25 22:24:19 2021 - [info] 192.168.50.130(192.168.50.130:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:19 2021 - [info] Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:19 2021 - [info]
Wed Aug 25 22:24:19 2021 - [info] * Phase 3.2: Saving Dead Master's Binlog Phase..
Wed Aug 25 22:24:19 2021 - [info]
Wed Aug 25 22:24:20 2021 - [info] Fetching dead master's binary logs..
Wed Aug 25 22:24:20 2021 - [info] Executing command on the dead master 192.168.50.171(192.168.50.171:3306): save_binary_logs --command=save --start_file=log-bin.000004 --start_pos=154 --binlog_dir=/var/lib/mysql,/var/log/mysql --output_file=/var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog --handle_raw_binlog=1 --disable_log_bin=0 --manager_version=0.55
Creating /var/tmp if not exists.. ok.
Concat binary/relay logs from log-bin.000004 pos 154 to log-bin.000004 EOF into /var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog ..
Dumping binlog format description event, from position 0 to 123.. ok.
Dumping effective binlog data from /var/lib/mysql/log-bin.000004 position 154 to tail(177).. ok.
Concat succeeded.
Wed Aug 25 22:24:20 2021 - [info] scp from root@192.168.50.171:/var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog to local:/etc/mha_manager/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog succeeded.
Wed Aug 25 22:24:21 2021 - [info] HealthCheck: SSH to 192.168.50.4 is reachable.
Wed Aug 25 22:24:22 2021 - [info] HealthCheck: SSH to 192.168.50.130 is reachable.
Wed Aug 25 22:24:22 2021 - [info]
Wed Aug 25 22:24:22 2021 - [info] * Phase 3.3: Determining New Master Phase..
Wed Aug 25 22:24:22 2021 - [info]
Wed Aug 25 22:24:22 2021 - [info] Finding the latest slave that has all relay logs for recovering other slaves..
Wed Aug 25 22:24:22 2021 - [info] All slaves received relay logs to the same position. No need to resync each other.
######################################################################
#选举新的master
Wed Aug 25 22:24:22 2021 - [info] Searching new master from slaves..
Wed Aug 25 22:24:22 2021 - [info] Candidate masters from the configuration file:
Wed Aug 25 22:24:22 2021 - [info] 192.168.50.4(192.168.50.4:3306) Version=5.7.17-log (oldest major version between slaves) log-bin:enabled
Wed Aug 25 22:24:22 2021 - [info] Replicating from 192.168.50.171(192.168.50.171:3306)
Wed Aug 25 22:24:22 2021 - [info] Primary candidate for the new Master (candidate_master is set)
Wed Aug 25 22:24:22 2021 - [info] Non-candidate masters:
Wed Aug 25 22:24:22 2021 - [info] Searching from candidate_master slaves which have received the latest relay log events..
Wed Aug 25 22:24:22 2021 - [info] New master is 192.168.50.4(192.168.50.4:3306)
Wed Aug 25 22:24:22 2021 - [info] Starting master failover..
Wed Aug 25 22:24:22 2021 - [info]
From:
192.168.50.171 (current master)
+--192.168.50.4
+--192.168.50.130 To:
192.168.50.4 (new master)
+--192.168.50.130
Wed Aug 25 22:24:22 2021 - [info]
Wed Aug 25 22:24:22 2021 - [info] * Phase 3.3: New Master Diff Log Generation Phase..
Wed Aug 25 22:24:22 2021 - [info]
Wed Aug 25 22:24:22 2021 - [info] This server has all relay logs. No need to generate diff files from the latest slave.
Wed Aug 25 22:24:22 2021 - [info] Sending binlog..
Wed Aug 25 22:24:23 2021 - [info] scp from local:/etc/mha_manager/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog to root@192.168.50.4:/var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog succeeded.
Wed Aug 25 22:24:23 2021 - [info]
Wed Aug 25 22:24:23 2021 - [info] * Phase 3.4: Master Log Apply Phase..
Wed Aug 25 22:24:23 2021 - [info]
Wed Aug 25 22:24:23 2021 - [info] *NOTICE: If any error happens from this phase, manual recovery is needed.
Wed Aug 25 22:24:23 2021 - [info] Starting recovery on 192.168.50.4(192.168.50.4:3306)..
Wed Aug 25 22:24:23 2021 - [info] Generating diffs succeeded.
Wed Aug 25 22:24:23 2021 - [info] Waiting until all relay logs are applied.
Wed Aug 25 22:24:23 2021 - [info] done.
Wed Aug 25 22:24:23 2021 - [info] Getting slave status..
Wed Aug 25 22:24:23 2021 - [info] This slave(192.168.50.4)'s Exec_Master_Log_Pos equals to Read_Master_Log_Pos(log-bin.000004:154). No need to recover from Exec_Master_Log_Pos.
Wed Aug 25 22:24:23 2021 - [info] Connecting to the target slave host 192.168.50.4, running recover script..
Wed Aug 25 22:24:23 2021 - [info] Executing command: apply_diff_relay_logs --command=apply --slave_user='root' --slave_host=192.168.50.4 --slave_ip=192.168.50.4 --slave_port=3306 --apply_files=/var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog --workdir=/var/tmp --target_version=5.7.17-log --timestamp=20210825222418 --handle_raw_binlog=1 --disable_log_bin=0 --manager_version=0.55 --slave_pass=xxx
Wed Aug 25 22:24:23 2021 - [info]
MySQL client version is 5.7.17. Using --binary-mode.
Applying differential binary/relay log files /var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog on 192.168.50.4:3306. This may take long time...
Applying log files succeeded.
Wed Aug 25 22:24:23 2021 - [info] All relay logs were successfully applied.
Wed Aug 25 22:24:23 2021 - [info] Getting new master's binlog name and position..
Wed Aug 25 22:24:23 2021 - [info] log-bin.000005:154
Wed Aug 25 22:24:23 2021 - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.50.4', MASTER_PORT=3306, MASTER_LOG_FILE='log-bin.000005', MASTER_LOG_POS=154, MASTER_USER='repl', MASTER_PASSWORD='xxx';
Wed Aug 25 22:24:23 2021 - [info] Executing master IP activate script:
Wed Aug 25 22:24:23 2021 - [info] /etc/mha_manager/master_ip_failover --command=start --ssh_user=root --orig_master_host=192.168.50.171 --orig_master_ip=192.168.50.171 --orig_master_port=3306 --new_master_host=192.168.50.4 --new_master_ip=192.168.50.4 --new_master_port=3306 --new_master_user='root' --new_master_password='1234'
Set read_only=0 on the new master.
Creating app user on the new master..
Wed Aug 25 22:24:24 2021 - [info] OK.
Wed Aug 25 22:24:24 2021 - [info] ** Finished master recovery successfully.
Wed Aug 25 22:24:24 2021 - [info] * Phase 3: Master Recovery Phase completed.
Wed Aug 25 22:24:24 2021 - [info]
Wed Aug 25 22:24:24 2021 - [info] * Phase 4: Slaves Recovery Phase..
Wed Aug 25 22:24:24 2021 - [info]
Wed Aug 25 22:24:24 2021 - [info] * Phase 4.1: Starting Parallel Slave Diff Log Generation Phase..
Wed Aug 25 22:24:24 2021 - [info]
Wed Aug 25 22:24:24 2021 - [info] -- Slave diff file generation on host 192.168.50.130(192.168.50.130:3306) started, pid: 80982. Check tmp log /etc/mha_manager/192.168.50.130_3306_20210825222418.log if it takes time..
Wed Aug 25 22:24:25 2021 - [info]
Wed Aug 25 22:24:25 2021 - [info] Log messages from 192.168.50.130 ...
Wed Aug 25 22:24:25 2021 - [info]
Wed Aug 25 22:24:24 2021 - [info] This server has all relay logs. No need to generate diff files from the latest slave.
Wed Aug 25 22:24:25 2021 - [info] End of log messages from 192.168.50.130.
Wed Aug 25 22:24:25 2021 - [info] -- 192.168.50.130(192.168.50.130:3306) has the latest relay log events.
Wed Aug 25 22:24:25 2021 - [info] Generating relay diff files from the latest slave succeeded.
Wed Aug 25 22:24:25 2021 - [info]
Wed Aug 25 22:24:25 2021 - [info] * Phase 4.2: Starting Parallel Slave Log Apply Phase..
Wed Aug 25 22:24:25 2021 - [info]
Wed Aug 25 22:24:25 2021 - [info] -- Slave recovery on host 192.168.50.130(192.168.50.130:3306) started, pid: 80984. Check tmp log /etc/mha_manager/192.168.50.130_3306_20210825222418.log if it takes time..
Wed Aug 25 22:24:27 2021 - [info]
Wed Aug 25 22:24:27 2021 - [info] Log messages from 192.168.50.130 ...
Wed Aug 25 22:24:27 2021 - [info]
Wed Aug 25 22:24:25 2021 - [info] Sending binlog..
Wed Aug 25 22:24:25 2021 - [info] scp from local:/etc/mha_manager/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog to root@192.168.50.130:/var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog succeeded.
Wed Aug 25 22:24:25 2021 - [info] Starting recovery on 192.168.50.130(192.168.50.130:3306)..
Wed Aug 25 22:24:25 2021 - [info] Generating diffs succeeded.
Wed Aug 25 22:24:25 2021 - [info] Waiting until all relay logs are applied.
Wed Aug 25 22:24:25 2021 - [info] done.
Wed Aug 25 22:24:25 2021 - [info] Getting slave status..
Wed Aug 25 22:24:25 2021 - [info] This slave(192.168.50.130)'s Exec_Master_Log_Pos equals to Read_Master_Log_Pos(log-bin.000004:154). No need to recover from Exec_Master_Log_Pos.
Wed Aug 25 22:24:25 2021 - [info] Connecting to the target slave host 192.168.50.130, running recover script..
Wed Aug 25 22:24:25 2021 - [info] Executing command: apply_diff_relay_logs --command=apply --slave_user='root' --slave_host=192.168.50.130 --slave_ip=192.168.50.130 --slave_port=3306 --apply_files=/var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog --workdir=/var/tmp --target_version=5.7.17-log --timestamp=20210825222418 --handle_raw_binlog=1 --disable_log_bin=0 --manager_version=0.55 --slave_pass=xxx
Wed Aug 25 22:24:26 2021 - [info]
MySQL client version is 5.7.17. Using --binary-mode.
Applying differential binary/relay log files /var/tmp/saved_master_binlog_from_192.168.50.171_3306_20210825222418.binlog on 192.168.50.130:3306. This may take long time...
Applying log files succeeded.
Wed Aug 25 22:24:26 2021 - [info] All relay logs were successfully applied.
Wed Aug 25 22:24:26 2021 - [info] Resetting slave 192.168.50.130(192.168.50.130:3306) and starting replication from the new master 192.168.50.4(192.168.50.4:3306)..
Wed Aug 25 22:24:26 2021 - [info] Executed CHANGE MASTER.
Wed Aug 25 22:24:26 2021 - [info] Slave started.
Wed Aug 25 22:24:27 2021 - [info] End of log messages from 192.168.50.130.
Wed Aug 25 22:24:27 2021 - [info] -- Slave recovery on host 192.168.50.130(192.168.50.130:3306) succeeded.
Wed Aug 25 22:24:27 2021 - [info] All new slave servers recovered successfully.
Wed Aug 25 22:24:27 2021 - [info]
Wed Aug 25 22:24:27 2021 - [info] * Phase 5: New master cleanup phase..
Wed Aug 25 22:24:27 2021 - [info]
Wed Aug 25 22:24:27 2021 - [info] Resetting slave info on the new master..
Wed Aug 25 22:24:27 2021 - [info] 192.168.50.4: Resetting slave info succeeded.
Wed Aug 25 22:24:27 2021 - [info] Master failover to 192.168.50.4(192.168.50.4:3306) completed successfully.
Wed Aug 25 22:24:27 2021 - [info] ----- Failover Report ----- app1: MySQL Master failover 192.168.50.171 to 192.168.50.4 succeeded Master 192.168.50.171 is down! Check MHA Manager logs at centos7-24-4:/etc/mha_manager/manager.log for details. Started automated(non-interactive) failover.
Invalidated master IP address on 192.168.50.171.
The latest slave 192.168.50.4(192.168.50.4:3306) has all relay logs for recovery.
Selected 192.168.50.4 as a new master.
192.168.50.4: OK: Applying all logs succeeded.
192.168.50.4: OK: Activated master IP address.
192.168.50.130: This host has the latest relay log events.
Generating relay diff files from the latest slave succeeded.
192.168.50.130: OK: Applying all logs succeeded. Slave started, replicating from 192.168.50.4.
192.168.50.4: Resetting slave info succeeded.
Master failover to 192.168.50.4(192.168.50.4:3306) completed successfully.

数据库的高可用MHA实验步骤的更多相关文章

  1. mysql数据库的高可用方法总结

    高可用架构对于互联网服务基本是标配,无论是应用服务还是数据库服务都需要做到高可用.虽然互联网服务号称7*24小时不间断服务,但多多少少有一 些时候服务不可用,比如某些时候网页打不开,百度不能搜索或者无 ...

  2. MySQL数据库的高可用方案总结

    高可用架构对于互联网服务基本是标配,无论是应用服务还是数据库服务都需要做到高可用.虽然互联网服务号称7*24小时不间断服务,但多多少少有一些时候服务不可用,比如某些时候网页打不开,百度不能搜索或者无法 ...

  3. MHA高可用 MHA+Keepalive

    MHA高可用 MHA简介 MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebo ...

  4. Mysql 高可用(MHA)-读写分离(Atlas)-分布式架构(Mycat)

    Mysql 高可用(MHA)-读写分离(Atlas) 1. 搭建主从复制(一主两从) 1.1 准备环境 1 主库:10.0.0.51/db01 2 从库:10.0.0.52/db02,10.0.0.5 ...

  5. MySQL数据库的优化(下)MySQL数据库的高可用架构方案

    MySQL数据库的优化(下)MySQL数据库的高可用架构方案 2011-03-09 08:53 抚琴煮酒 51CTO 字号:T | T 在上一篇MySQL数据库的优化中,我们跟随笔者学习了单机MySQ ...

  6. 利用keepalive+mysql replication 实现数据库的高可用

    利用keepalive+mysql replication 实现数据库的高可用 http://www.xuchanggang.cn/archives/866.html

  7. MHA+atlas(数据库的高可用与读写分离)

    学习完了mycat的高可用还是复习一下MHA+atlas吧,个人感觉还是比mycat好用,毕竟MHA有数据补全和切换主从的机制 1 MHA是什么? MHA(Master High Availabili ...

  8. MySQL之高可用MHA部署

    先说一下大概原理 虚拟机A  ip为10.0.3.92           作为master 虚拟机B  ip为10.0.3.102  作为slave1 虚拟机C  ip为10.0.3.103  作为 ...

  9. MySQL高可用MHA实战

    MySQL高可用架构MHA介绍 简介: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职 ...

随机推荐

  1. Oracle基本用法(一)

    一.简介 数据库:Oracle数据库的概念和其他数据库不一样,这里的数据库是一个操作系统只有一个库,可以看做Oracle就是一个大的数据库. 实例:一个Oracle实例有一系列的后台进程和内存结构组成 ...

  2. bt面板安装邮局系统

    前些日子阿里云优惠就顺便买了个服务器,今天想在阿里云的服务器上试着安装一个邮件服务,突然发现之前安装的好好的邮件服务插件不能正常安装了,一直报错. 点击该链接享受本文章的纯净无广告版 查看了下出错的地 ...

  3. SprngCloud微服务框架搭建(一)

    参照来源 :https://blog.csdn.net/forezp/article/details/70148833 1.简介 目前来说,SpringCloud是比较完整的微服务解决方案框架.不像其 ...

  4. Ubuntu中配置tomcat

    1.从网上下载的tomcat配置失败后,servername那一栏写不了,必须要删除工作空间的配置文件 sudo rm /home/{username}/workspace/.metadata/.pl ...

  5. Java - 记录01_开发环境搭建

    时间:2017-07-04 记录:byzqy 一.什么是JDK JDK(Java Development Kit):Java开发工具集,即Java语言的软件开发工具包. SDK(Software De ...

  6. Ubuntu 16.04 + Win10双系统 启动Ubuntu进入命令行 无界面

    Ubuntu 16.04 + Win10双系统,启动Ubuntu时候报错,并入命令行(无界面). 原因:可能是双系统兼容性问题 解决办法: 重启系统,进入Win10 然后在Win10中重启电脑. 重启 ...

  7. Linux从头学10:三级跳过程详解-从 bootloader 到 操作系统,再到应用程序

    作 者:道哥,10+年的嵌入式开发老兵. 公众号:[IOT物联网小镇],专注于:C/C++.Linux操作系统.应用程序设计.物联网.单片机和嵌入式开发等领域. 公众号回复[书籍],获取 Linux. ...

  8. 提交Spark作业遇到的NoSuchMethodError问题总结

    测试应用说明 测试的Spark应用实现了同步hive表到kafka的功能.具体处理流程: 从 ETCD 获取 SQL 语句和 Kafka 配置信息 使用 SparkSQL 读取 Hive 数据表 把 ...

  9. noip模拟47

    原版在 \(linux\) 本地写完没保存关机给没了-- 再简单写一下 \(t2\) 用 \(dp\) 转移 \(f[i]=\sum _ {j=last[a[i]]}^{i-1} f[j]\) 用前缀 ...

  10. 网络游戏逆向分析-6-使用背包物品call

    网络游戏逆向分析-6-使用背包物品call 首先,大家在处理网络游戏的时候,一定得利用好发包函数,因为他就是整个网络游戏的关键. 处理办法: 这里还是直接给发包打断点来处理. 就像我们之前处理喊话函数 ...