MySQL之MHA+keepalived方案演示
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL之MHA+keepalived方案演示相关的知识,希望对你有一定的参考价值。
接着上篇博文mysql之MHA+keepalived方案演示(四)中的MySQL的故障切换,当前主库变为了192.168.2.129机器,同时129机器上的keepalived服务被开启。然而192.168.2.128原来的主库被挂掉了,运行的keepalived也被停止了。
重新启动192.168.2.128机器上的mysql,
添加192.168.2.128机器上的mysql作为192.168.2.129新主库的slave从库.
查看 192.168.2.130 机器上的故障切换日志:
grep "MASTER_PASSWORD" /var/log/masterha/app1/manager.log
Sun Jul 1 17:04:32 2018 - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST=‘192.168.2.129‘, MASTER_PORT=3306, MASTER_LOG_FILE=‘mysql-bin.000003‘, MASTER_LOG_POS=154, MASTER_USER=‘repmha‘, MASTER_PASSWORD=‘xxx‘;
直接登陆192.168.2.128上的mysql,执行(切忌不要画蛇添足从129机器上dump出数据恢复到128机器这样的方式来做MySQL同步)
CHANGE MASTER TO MASTER_HOST=‘192.168.2.129‘, MASTER_PORT=3306, MASTER_LOG_FILE=‘mysql-bin.000003‘, MASTER_LOG_POS=154, MASTER_USER=‘repmha‘, MASTER_PASSWORD=‘123456‘;
start slave;
show master statusG
192.168.2.128源主库成功添加为129新主库的slave从库。
手动修改监控机 192.168.2.130配置文件app1.cnf
现在的配置文件如下:
[[email protected] ~]# mkdir -p /etc/masterha
[[email protected] masterha]# cat /etc/masterha/app1.cnf
[server default]
manager_log=/var/log/masterha/app1/manager.log
manager_workdir=/var/log/masterha/app1.log
master_binlog_dir=/data/mysql/logs/bin-log
master_ip_failover_script=/usr/local/bin/master_ip_failover
master_ip_online_change_script=/usr/local/bin/master_ip_online_change
password=123456
ping_interval=1
remote_workdir=/tmp
repl_password=123456
repl_user=repmha
report_script=/usr/local/bin/send_report
secondary_check_script=/usr/local/bin/masterha_secondary_check -s server03 -s server02 --user=root --master_host=server02 --master_ip=192.168.2.128 --master_port=3306
shutdown_script=""
ssh_port=10280
ssh_user=root
user=monitor
[server2]
candidate_master=1
check_repl_delay=0
hostname=192.168.2.129
port=3306
[server3]
hostname=192.168.2.130
port=3306
You have new mail in /var/spool/mail/root
[[email protected] masterha]#
修改后的配置文件如下:
[[email protected] ~]# cat /etc/masterha/app1.cnf
[server default]
manager_log=/var/log/masterha/app1/manager.log
manager_workdir=/var/log/masterha/app1.log
master_binlog_dir=/data/mysql/logs/bin-log
master_ip_failover_script=/usr/local/bin/master_ip_failover
master_ip_online_change_script=/usr/local/bin/master_ip_online_change
password=123456
ping_interval=1
remote_workdir=/tmp
repl_password=123456
repl_user=repmha
report_script=/usr/local/bin/send_report
secondary_check_script=/usr/local/bin/masterha_secondary_check -s server02 -s server03 --user=root --master_host=server03 --master_ip=192.168.2.129 --master_port=3306
shutdown_script=""
ssh_port=10280
ssh_user=root
user=monitor
[server1]
hostname=192.168.2.129
port=3306
[server2]
candidate_master=1
check_repl_delay=0
hostname=192.168.2.128
port=3306
[server3]
hostname=192.168.2.130
port=3306
kill掉原来的监控进程
[[email protected] app1]# ps -ef|grep perl
root 47458 40702 0 15:29 pts/3 00:00:00 perl /usr/local/bin/masterha_manager --conf=/etc/masterha/app1.cnf --remove_dead_master_conf --ignore_last_failover
root 47604 40702 0 15:30 pts/3 00:00:00 grep perl
[[email protected] app1]# kill -9 47458
重新启动masterha_manager
[[email protected] app1]# nohup masterha_manager --conf=/etc/masterha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /var/log/masterha/app1/manager.log 2>&1 &
[1] 47458
到此处128原来的主MySQL成功的添加为129新主库的slave从库
以上是关于MySQL之MHA+keepalived方案演示的主要内容,如果未能解决你的问题,请参考以下文章