码迷,mamicode.com
首页 > 数据库 > 详细

MySQL之MHA+keepalived方案演示(五)

时间:2018-07-15 12:02:35      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:monitor   nohup   moni   HERE   local   remove   int   delay   监控进程   

接着上篇博文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 status\G

192.168.2.128源主库成功添加为129新主库的slave从库。

手动修改监控机 192.168.2.130配置文件app1.cnf
现在的配置文件如下:

[root@server03 ~]#  mkdir -p /etc/masterha
[root@server03 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
[root@server03 masterha]# 

修改后的配置文件如下:

[root@server03 ~]# 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掉原来的监控进程

[root@server03 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
[root@server03 app1]# kill -9    47458

重新启动masterha_manager

[root@server03 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方案演示(五)

标签:monitor   nohup   moni   HERE   local   remove   int   delay   监控进程   

原文地址:http://blog.51cto.com/wujianwei/2142654

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!