一、服务器分布
二、MySQL-MMM 配置
(1)、公共配置【所有DB节点:Master1、Master2、Slave1、Slave2 Monitor节点】
# vim /etc/mysql-mmm/mmm_common.conf
active_master_role writer <host default> cluster_interface eth1 pid_path /var/run/mmm_agentd.pid bin_path /usr/lib/mysql-mmm/ replication_user repl replication_password repl123456 agent_user mmm_agent agent_password 123456 </host> <host db1> ip 10.222.5.10 mode master peer db2 </host> <host db2> ip 10.222.5.225 mode master peer db1 </host> <host db3> ip 172.23.155.22 mode slave </host> <host db4> ip 172.24.18.68 mode slave </host> <role writer> hosts db1,db2 ips 10.222.5.224 mode exclusive </role>
(2)、Agent节点【所有DB节点:Master1、Master2、Slave1、Slave2】
Master1节点:
# vim/etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf this db1
Master2节点:
# vim/etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf this db2
Slave1节点:
# vim/etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf this db3
Slave2节点:
# vim/etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf this db4
(3)、Monitor节点
# vim /etc/mysql-mmm/mmm_mon.conf
include mmm_common.conf <monitor> ip 10.137.23.103 pid_path /var/run/mmm_mond.pid bin_path /usr/lib/mysql-mmm/ status_path /var/lib/misc/mmm_mond.status ping_ips 10.222.5.10, 10.222.5.225,172.23.155.22,172.24.18.68 auto_set_online 10 </monitor> <host default> monitor_user mmm_monitor monitor_password 123456 </host> debug 0
三、问题描述及解决方案
1、问题描述
当Master1发生故障,导致DB不可用时,VIP会自动漂移到Master2上,以实现高可用。但出现了一个问题,由于ARP老化时间过长,导致漂移过去的VIP不可用,也无法ping通。也就是说,MySQL-MMM没有考虑到ARP老化时间过长的情况而采取强刷ARP的方式。
2、解决方案
方法一(手动命令强刷)
获取网关地址:
# arping -I eth1 -c 3 -s10.222.5.224 10.222.0.1
方法二(代码级别修正)
# vim /usr/share/perl5/vendor_perl/MMM/Agent/Helpers/Actions.pm
方法三(SHELL脚本方式)
# vim /data/scripts/refresh_vip.sh
#!/bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/local/sbin MMM_COMM_CONF="/etc/mysql-mmm/mmm_common.conf" ETH_NAME=`awk '/cluster_interface/{print $2}' ${MMM_COMM_CONF}` VIP_ADDR=`grep -A 2 '<role writer>' ${MMM_COMM_CONF} | awk '/ips/{print $2}'` GETWAY_ADDR=`/sbin/route | awk '/default/ {print $2}'` if [[ -n `/sbin/ip addr show ${ETH_NAME} | grep ${VIP_ADDR}` ]]; then /sbin/arping -I ${ETH_NAME} -c 3 -s ${VIP_ADDR} ${GETWAY_ADDR} >/dev/null 2>&1 fi
需要添加的crontab信息【每10秒刷新一次】:
* * * * * sleep 10; /data/scripts/refresh_vip.sh >/dev/null 2>&1
* * * * * sleep 20; /data/scripts/refresh_vip.sh >/dev/null 2>&1
* * * * * sleep 30; /data/scripts/refresh_vip.sh >/dev/null 2>&1
* * * * * sleep 40; /data/scripts/refresh_vip.sh >/dev/null 2>&1
* * * * * sleep 50; /data/scripts/refresh_vip.sh >/dev/null 2>&1