mysql高可用研究(一) 主从+MHA架构
最近在研究mysql的高可用架构,自己想总结下常用的高可用方案都有哪些、有哪些优缺点以及应用的场景?搞得是头昏脑涨,天昏地暗,看了诸多资料,每次都觉得公说公有理婆说婆有理。其实嘛,大家说的都有一定的道理,只不过适合自己的才是最正确的。今天就从比较常用的主从+MHA说起。
学习一种新的架构还是软件,最好还是先从了解它的原理开始,这样才能在应用时扬长避短。
一、【MHA原理】
相较于其它HA软件,MHA的目的在于维持MySQL Replication中Master库的高可用性,其最大特点是可以修复多个Slave之间的差异日志,最终使所有Slave保持数据一致,然后从中选择一个充当新的Master,并将其它Slave指向它。
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
filter_mysqlbinlog 去除不必要的ROLLBACK事件(MHA已不再使用这个工具)
purge_relay_logs 清除中继日志(不会阻塞SQL线程)
基本工作流程大致如下:
(1) Manager定期监控Master,监控时间间隔由参数ping_interval决定,缺省为3秒钟一次;可利用其自身的监控功能,也可调用第三方软件来监控;MHA自身提供了两种监控方式:SELECT(执行SELECT 1)和CONNECT(创建连接/断开连接),
主要由ping_type参数决定,默认是select方式。
(2) 当监测到Master故障时,调用SSH脚本对所有Node执行一次检查,包括如下几个方面:
――MySQL实例是否可以连接;
――Master服务器是否可以SSH连通;
――检查SQL Thread的状态;
――检查哪些Server死掉了,哪些Server是活动的,以及活动的Slave实例;
――检查Slave实例的配置及复制过滤规则;
――最后退出监控脚本并返回代表特殊意义代码。
(3) 开始Master故障切换,包括如下几个子阶段:
――Phase 1: Configuration Check Phase
在这个阶段,若某个Slave实例的SQL Thread停止了,则会自动启动它;并再次确认活动的Servers及Slaves。
――Phase 2: Dead Master Shutdown Phase
在这个阶段,首先调用master_ip_failover_script,若HA是基于VIP实现的,则关闭VIP,若是基于目录数据库实现的,则修改映射记录。然后调用shutdown_script脚本强制关闭主机,以避免服务重启时,发生脑裂。
――Phase 3: Master Recovery Phase
又包括如下3个子阶段:
Phase 3.1: Getting Latest Slaves Phase
检查各个Slave,获取最近的和最旧的binary log file和position,并检查各个Slave成为Master的优先级,依赖于candidate_master、no_master、 [server_xxx]顺序、binary log差异量等因素。
Phase 3.2: Saving Dead Master's Binlog Phase
若dead master所在服务器依然可以通过SSH连通,则提取dead master的binary log,提取日志的起点就是上一步获取的最新的binary log file和position,直到最后一条事件日志,并在dead master本地的工作目录(由参数remote_workdir决定)中
创建文件保存这些提取到的日志,然后将该文件拷贝到Manager服务器的工作 目录下(由参数manager_workdir决定)。若dead master系统就无法连接,也就不存在差异的binary log了。MHA还要对各个Slave节点进行健康检查,主要是SSH连通性。
Phase 3.3: Determining New Master Phase
接下来调用apply_diff_relay_logs命令恢复Slave的差异日志,这个差异日志指的是各个Slave之间的relay log。恢复完成后,所有的Slave数据是一致的,此时就可以根据优先级选择New Master了。
Phase 3.4: New Master Diff Log Generation Phase
这里是生成dead master和new master之间的差异日志,即将Phase 3.2保存的binary log拷贝到New Master的工作目录中(remote_workdir)。
Phase 3.5: Master Log Apply Phase
将上一步拷贝的差异日志恢复到New Master上,若发生错误,也可手动恢复。然后获取New Master的binlog name和position,以便其它Slave从这个新的binlog name和position开始复制。最后会开启New Master的写权限,即将read_only参数设置为0。
――Phase 4: Slaves Recovery Phase
Phase 4.1: Starting Parallel Slave Diff Log Generation Phase
生成Slave与New Slave之间的差异日志,并将该日志拷贝到各Slave的工作目录下,这部分日志dead master和new master之间差异的那部分日志,因为各个Slave在Phase 3.3阶段已经同步了。
Phase 4.2: Starting Parallel Slave Log Apply Phase
在各个Slave上应用这部分差异日志,然后通过CHANGE MASTER TO命令将这些Slave指向新的New Master,最后开始复制(start slave)。
――Phase 5: New master cleanup phase
清理New Master其实就是重置slave info,即取消原来的Slave信息。至此整个Master故障切换过程完成。
二、【实验部分】
1、【环境说明】:默认三台机器上都已安装mysql5.6,且主从复制已经配置完成。
角色 主机名 ip地址 功能
主库 node1 192.168.245.129 (w/r)
candidate_master node2 192.168.245.131 (r)
从库 node3 192.168.245.132 (r)
vip: 192.168.245.100
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAARwAAAC2CAIAAACEZqWLAAASrElEQVR4nO2dL2zjSBuHDVcfCgxcYqngQKQjAQaFy64+tLCSycECg7JFVmGJpSMnFfikkpXujBYOLLF06FQZHXNggEHhfOCXvp2M/9RxnDiNfw9yHduxZ+fZd2Yy49fRhOzOYrFwSB2LxcIZ+1+HfEgchzWnHodFQ/rBmtMEpSI9Yc1pglKRnrDmNEGpSE9Yc5qgVKQnrDlNUCrSE9acJigV6QlrThOUivSENacJSkV6chI1pyzHvoMaKBXpycA1Jwx1kug810mi47j+GN/XWbbZLkudZTqKhryHgaBUpCcD15woehNGNrqcdXpQKtKTQ0klnqSpTlOt1OZPpWoUMvco9XZ8nuso0mW5CX3mBYtisx2Guiw3OweFUpGeDC9VHOsk0b6vtdZxrPN8sx8a6Lq4ZBoInaCW1pvrFMXG1SDYHIn9WmvP27QzxbqBoFSkJ8eIVEmig+CtNdgilagi29BShPE8nec6z3UY1pwyKJSK9OSAfSqtdRi+OdZPqqLQYfg25lFViFKRU+OwUvn+Zrgco4JyTPUsoNTGnzh+64b5/lvTUSyVq1EqcmoMXHOy7E0AoNRGA+xH7wgdLa03gxDmnqLQSbJ1EflILihjEta5g0KpSE9Yc5qgVKQnrDlNUCrSE9acJigV6QlrThOUivSENacJSkV6wprTBKUiPWHNaYJSkZ6w5jRBqUhPWHOaoFSkJ6w5TVAq0hPWnCYoFenJbDbbIRPGlJjNZpSK7Isz7f+a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S6Lr6s9RSllnoLj4zjuOKuDUpHB+Ihz/w4BpSKDQakApSKDQakApSKDQakApSKDQakApSKDQakApSKDQakApSKDQakApSKDQakApSKDQakApSKDQakApSKDQakApSKDQakApSKDQakApSKDQakApSKDQakApSKDQakApSKDMZvNqu+vnSCz2UzK5P8ChLMVAjPMrAAAAABJRU5ErkJggg==" alt="" width="367" height="235" />
129为主库,对外提供读写服务,而131和132机器对外提供读服务,需要设置为只读状态,不建议将它写入配置文件,因为从库随时会切换为主库。如下:
set global read_only=
2、配置三台机器之间的信任机制(省)
目的:机器之间能够无需输入密码进行访问。
3、安装mha软件
- rpm安装:每台机器都要安装node,manager节点建议安装到单独的一台机器上或者一个不用切换为主的从库上
#安装可能需要的依赖包
[root@node1 software]# yum install perl-DBD-MySQL
[root@node1 software]# yum install perl-Config-Tiny
[root@node1 software]# yum install perl-Parallel-ForkManager*.rpm
[root@node1 software]# yum install perl-Mail-Sender*.rpm
[root@node1 software]# yum install perl-Mail-Sendmail*.rpm
[root@node1 software]# yum install perl-Log-Dispatch*.rpm
#安装mha,这里用rpm包安装,默认在/usr/bin
[root@node1 software]# yum install mha4mysql-node-0.56-.el6.noarch.rpm
[root@node1 software]# yum install mha4mysql-manager-0.56-.el6.noarch.rpm
- 二进制包安装
#node安装
wget http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.53.tar.gz
tar xf mha4mysql-node-0.53.tar.gz
cd mha4mysql-node-0.53
perl Makefile.PL
make && make install #manager安装
wget http://mysql-master-ha.googlecode.com/files/mha4mysql-manager-0.53.tar.gz
tar xf mha4mysql-manager-0.53.tar.gz
cd mha4mysql-manager-0.53
perl Makefile.PL
make && make install
4、手工配置主库服务器的vip并测试
这里通过脚本手动创建vip,如下:
[root@node1 scripts]# cat init_vip.sh
vip="192.168.245.100/32"
/sbin/ip addr add $vip dev eth0
【测试】
绑定完成后,可以用以下命令查看绑定情况:
[root@node2 etc]# ip addr show
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UP qlen
link/ether :0c::d7:0f:4a brd ff:ff:ff:ff:ff:ff
inet 192.168.245.131/ brd 192.168.245.255 scope global eth0
inet 192.168.245.100/32 scope global eth0
inet6 fe80::20c:29ff:fed7:f4a/ scope link
valid_lft forever preferred_lft forever
到任意从库ssh 192.168.245.100 --看是否连上vip或者mysql -h 192.168.245.100 -udarren -pdarren --是否连上vip数据库. 如果都能够连接上,表示vip设置成功了。
5、配置mha及启动
(1)创建mha监控用户(在主库执行,这样每个服务器都有这个用户了)
mysql> grant all privileges on *.* to 'root'@'%' identified by '';
Query OK, rows affected (0.00 sec) mysql> flush privileges;
Query OK, rows affected (0.01 sec)
(2)关闭purge_relay_logs:
- 在修改配置文件前,注意一个知识点,须将从库上的relay log自动清除设置为OFF,因为MySQL数据库主从复制在缺省情况下从库的relay logs会在SQL线程执行完毕后被自动删除,但是对于MHA场景下,对于某些滞后从库的恢复依赖于其他从库的relay log,因此采取禁用自动删除功能以及定期清理的办法。对于清理过多过大的relay log需要注意引起的复制延迟资源开销等。MHA可通过purge_relay_logs脚本及配合cronjob来完成此项任务。
purge_relay_logs的主要功能:
a、为relay日志创建硬链接(最小化批量删除大文件导致的性能问题)
b、SET GLOBAL relay_log_purge=1; FLUSH LOGS; SET GLOBAL relay_log_purge=0;
c、删除relay log(rm –f /path/to/archive_dir/*)
purge_relay_logs的用法及相关参数
purge_relay_logs --help
Usage:
purge_relay_logs --user=root --password=rootpass --host=127.0.0.1 参数描述
--user 用户名,缺省为root
--password 密码
--port 端口号
--host 主机名,缺省为127.0.0.
--workdir 指定创建relay log的硬链接的位置,默认是/var/tmp,成功执行脚本后,硬链接的中继日志文件被删除,由于系统不同分区创建硬链接文件会失败,故需要执行硬链接具体位置,建议指定为relay log相同的分区
--disable_relay_log_purge 默认情况下,如果参数relay_log_purge=,脚本不做任何处理,自动退出.设定该参数,脚本会将relay_log_purge设置为0,当清理relay log之后,最后将参数设置为OFF()
定制清理relay log cronjob
pureg_relay_logs脚本在不阻塞SQL线程的情况下自动清理relay log。对于不断产生的relay log直接将该脚本部署到crontab以实现按天或按小时定期清理。
$ crontab -l
# purge relay logs at 5am
* * * app /usr/bin/purge_relay_logs --user=root --password=PASSWORD --disable_relay_log_purge >> /var/log/masterha/purge_relay_logs.log >&
- 在我们的两个从库上设置relaylog为OFF:
(product)root@127.0.0.1 [(none)]> set global relay_log_purge=;
Query OK, rows affected (0.00 sec)
- 然后通过定时任务,每隔一天定时清除relaylog:
#清除脚本
#!/bin/bash
user=root
passwd=root
port=
log_dir='/data/masterha/log'
work_dir='/data'
purge='/usr/bin/purge_relay_logs' if [ ! -d $log_dir ]
then
mkdir $log_dir -p
fi $purge --user=$user --password=$passwd --disable_relay_log_purge --port=$port --workdir=$work_dir >> $log_dir/purge_relay_logs.log >& #定时任务
crontab -e
#每天早上5点10分执行
* * * sh /data/scripts/purge_relay_log.sh
(3)修改配置文件:
到manager节点的/etc下面新建masterha目录,并将mha需要的配置初始化文件拷贝到该目录下:
[root@node3 ~]# cd /etc
[root@node3 etc]# mkdir masterha
#创建以下mha日志目录,没有则报错
[root@node3 etc]#mkdir -p /var/log/masterha/app1
[root@node3 mastermha]# ll
total 32
-rw-r--r--. 1 root root 503 Nov 9 01:26 app1.conf
-rwxr-xr-x. 1 root root 55 Nov 9 01:26 drop_vip.sh
-rwxr-xr-x. 1 root root 55 Nov 9 01:26 init_vip.sh
-rw-r--r--. 1 root root 357 Nov 9 01:26 masterha_default.conf
-rwxr-xr-x. 1 root root 3888 Nov 9 01:26 master_ip_failover
-rwxr-xr-x. 1 root root 10298 Nov 9 01:26 master_ip_online_change
然后修改vip的值:在masterha目录下执行grep "vip" *,将会列出所有文件中vip变量,然后一一修改为192.168.245.100。
修改app1.conf文件:
[server default]
manager_log=/var/log/masterha/app1/app1.log
manager_workdir=/var/log/masterha/app1
master_ip_failover_script="/etc/masterha/master_ip_failover"
master_ip_online_change_script="/etc/masterha/master_ip_online_change"
password=root
ping_interval=1
remote_workdir=/var/log/masterha/app1
repl_password=repl4slave
repl_user=repl
report_script="/etc/masterha/send_mail"
shutdown_script=""
ssh_user=root
user=root [server1]
candidate_master=1
check_repl_delay=0
hostname=192.168.245.129
master_binlog_dir=/data/mysql/mysql_3306/logs [server3]
hostname=192.168.245.132
port=3306
(4)检查mha环境并启动
#检查MHA Manger到所有MHA Node的SSH连接状态:
[root@node3 masterha]# /usr/bin/masterha_check_ssh --conf=/etc/masterha/app1.conf
Mon Nov :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Nov :: - [info] Reading application default configuration from /etc/masterha/app1.conf..
Mon Nov :: - [info] Reading server configuration from /etc/masterha/app1.conf..
Mon Nov :: - [info] Starting SSH connection tests..
Mon Nov :: - [debug]
Mon Nov :: - [debug] Connecting via SSH from root@192.168.245.129(192.168.245.129:) to root@192.168.245.131(192.168.245.131:)..
Mon Nov :: - [debug] ok.
Mon Nov :: - [debug] Connecting via SSH from root@192.168.245.129(192.168.245.129:) to root@192.168.245.132(192.168.245.132:)..
Mon Nov :: - [debug] ok.
Mon Nov :: - [debug]
Mon Nov :: - [debug] Connecting via SSH from root@192.168.245.131(192.168.245.131:) to root@192.168.245.129(192.168.245.129:)..
Mon Nov :: - [debug] ok.
Mon Nov :: - [debug] Connecting via SSH from root@192.168.245.131(192.168.245.131:) to root@192.168.245.132(192.168.245.132:)..
Mon Nov :: - [debug] ok.
Mon Nov :: - [debug]
Mon Nov :: - [debug] Connecting via SSH from root@192.168.245.132(192.168.245.132:) to root@192.168.245.129(192.168.245.129:)..
Mon Nov :: - [debug] ok.
Mon Nov :: - [debug] Connecting via SSH from root@192.168.245.132(192.168.245.132:) to root@192.168.245.131(192.168.245.131:)..
Mon Nov :: - [debug] ok.
Mon Nov :: - [info] All SSH connection tests passed successfully.
#检查主从复制环境
[root@node3 masterha]# /usr/bin/masterha_check_repl --conf=/etc/masterha/app1.conf
Mon Nov :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Nov :: - [info] Reading application default configuration from /etc/masterha/app1.conf..
Mon Nov :: - [info] Reading server configuration from /etc/masterha/app1.conf..
Mon Nov :: - [info] MHA::MasterMonitor version 0.56.
Mon Nov :: - [info] GTID failover mode =
Mon Nov :: - [info] Dead Servers:
Mon Nov :: - [info] Alive Servers:
Mon Nov :: - [info] 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] 192.168.245.131(192.168.245.131:)
Mon Nov :: - [info] 192.168.245.132(192.168.245.132:)
Mon Nov :: - [info] Alive Slaves:
Mon Nov :: - [info] 192.168.245.131(192.168.245.131:) Version=5.6.-log (oldest major version between slaves) log-bin:enabled
Mon Nov :: - [info] Replicating from 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Mon Nov :: - [info] 192.168.245.132(192.168.245.132:) Version=5.6.-log (oldest major version between slaves) log-bin:enabled
Mon Nov :: - [info] Replicating from 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] Current Alive Master: 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] Checking slave configurations..
Mon Nov :: - [info] read_only= is not set on slave 192.168.245.131(192.168.245.131:).
Mon Nov :: - [info] read_only= is not set on slave 192.168.245.132(192.168.245.132:).
Mon Nov :: - [info] Checking replication filtering settings..
Mon Nov :: - [info] binlog_do_db= , binlog_ignore_db=
Mon Nov :: - [info] Replication filtering check ok.
Mon Nov :: - [info] GTID (with auto-pos) is not supported
Mon Nov :: - [info] Starting SSH connection tests..
Mon Nov :: - [info] All SSH connection tests passed successfully.
Mon Nov :: - [info] Checking MHA Node version..
Mon Nov :: - [info] Version check ok.
Mon Nov :: - [info] Checking SSH publickey authentication settings on the current master..
Mon Nov :: - [info] HealthCheck: SSH to 192.168.245.129 is reachable.
Mon Nov :: - [info] Master MHA Node version is 0.56.
Mon Nov :: - [info] Checking recovery script configurations on 192.168.245.129(192.168.245.129:)..
Mon Nov :: - [info] Executing command: save_binary_logs --command=test --start_pos= --binlog_dir=/data/mysql/mysql_3306/logs --output_file=/var/log/masterha/app1/save_binary_logs_test --manager_version=0.56 --start_file=mysql-bin.
Mon Nov :: - [info] Connecting to root@192.168.245.129(192.168.245.129:)..
Creating /var/log/masterha/app1 if not exists.. ok.
Checking output directory is accessible or not..
ok.
Binlog found at /data/mysql/mysql_3306/logs, up to mysql-bin.
Mon Nov :: - [info] Binlog setting check done.
Mon Nov :: - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Mon Nov :: - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.245.131 --slave_ip=192.168.245.131 --slave_port= --workdir=/var/log/masterha/app1 --target_version=5.6.-log --manager_version=0.56 --relay_log_info=/data/mysql/mysql_3306/data/relay-log.info --relay_dir=/data/mysql/mysql_3306/data/ --slave_pass=xxx
Mon Nov :: - [info] Connecting to root@192.168.245.131(192.168.245.131:)..
Checking slave recovery environment settings..
Opening /data/mysql/mysql_3306/data/relay-log.info ... ok.
Relay log found at /data/mysql/mysql_3306/data, up to relay-bin.
Temporary relay log file is /data/mysql/mysql_3306/data/relay-bin.
Testing mysql connection and privileges..Warning: Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Mon Nov :: - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='root' --slave_host=192.168.245.132 --slave_ip=192.168.245.132 --slave_port= --workdir=/var/log/masterha/app1 --target_version=5.6.-log --manager_version=0.56 --relay_log_info=/data/mysql/data/relay-log.info --relay_dir=/data/mysql/data/ --slave_pass=xxx
Mon Nov :: - [info] Connecting to root@192.168.245.132(192.168.245.132:)..
Checking slave recovery environment settings..
Opening /data/mysql/data/relay-log.info ... ok.
Relay log found at /data/mysql/data, up to node3-relay-bin.
Temporary relay log file is /data/mysql/data/node3-relay-bin.
Testing mysql connection and privileges..Warning: Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Mon Nov :: - [info] Slaves settings check done.
Mon Nov :: - [info]
192.168.245.129(192.168.245.129:) (current master)
+--192.168.245.131(192.168.245.131:)
+--192.168.245.132(192.168.245.132:) Mon Nov :: - [info] Checking replication health on 192.168.245.131..
Mon Nov :: - [info] ok.
Mon Nov :: - [info] Checking replication health on 192.168.245.132..
Mon Nov :: - [info] ok.
Mon Nov :: - [warning] master_ip_failover_script is not defined.
Mon Nov :: - [warning] shutdown_script is not defined.
Mon Nov :: - [info] Got exit code (Not master dead). MySQL Replication Health is OK.
如果遇到这个报错:
Can't exec "mysqlbinlog": No such file or directory at /usr/share/perl5/vendor_perl/MHA/BinlogManager.pm line 106.
mysqlbinlog version command failed with rc :, please verify PATH, LD_LIBRARY_PATH, and client options
at /usr/bin/apply_diff_relay_logs line
Mon Nov :: - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln205] Slaves settings check failed!
Mon Nov :: - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln413] Slave configuration failed.
Mon Nov :: - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln424] Error happened on checking configurations. at /usr/bin/masterha_check_repl line
Mon Nov :: - [error][/usr/share/perl5/vendor_perl/MHA/MasterMonitor.pm, ln523] Error happened on monitoring servers.
Mon Nov :: - [info] Got exit code (Not master dead). MySQL Replication Health is NOT OK!
解决方法如下,添加软连接(所有节点)
ln -s /usr/local/mysql/bin/mysqlbinlog /usr/local/bin/mysqlbinlog
ln -s /usr/local/mysql/bin/mysql /usr/local/bin/mysql
到此为止,都没问题了,开始启动manager节点进行监控,一般启动我们都使用nohup方式,但是当出现故障成功切换后,manager监控也会关闭,所以建议使用daemontools方式在后台运行。
- nohup方式启动
nohup /usr/bin/masterha_manager --conf=/etc/masterha/app1.conf --remove_dead_master_conf --ignore_last_failover &
#关闭mha监控
/usr/bin/masterha_stop --conf=/etc/masterha/app1.conf
- daemontools方式启动:
#下载daemontools工具
wget http://cr.yp.to/daemontools/daemontools-0.76.tar.gz
#安装
cd /home/software/daemontools/admin/daemontools-0.76
vim src/conf-cc #在第一行最后空一格后添加 -include /usr/include/errno.h 避免编译时报错
package/install #安装
#在/etc/init/创建svscan.conf文件并添加如下内容:
vim /etc/init/svscan.conf
start on runlevel []
respawn
exec /command/svscanboot
#在/etc/init目录下重新加载并启动
[root@node3 init]# initctl reload-configuration
[root@node3 init]# initctl start svscan
svscan start/running, process
使用daemon启动mha监控:
[root@node3 init]# mkdir -p /service/masterha_app
[root@node3 ~]# cd /service/masterha_app/
[root@node3 masterha_app]# pwd
/service/masterha_app
#在/service/masterha_app/创建run脚本并增加执行权限,内容如下
[root@node3 masterha_app]# cat /service/masterha_app/run
#!/bin/bash
exec /usr/bin/masterha_manager --conf=/etc/masterha/app1.conf --remove_dead_master_conf --ignore_last_failover
[root@node3 masterha_app]# chmod +x /service/masterha_app/run
#停止监控
svc -d /service/masterha_app
#开启监控
svc -u /service/masterha_app
另起一个session,查看启动日志:
[root@node3 app1]# tail -f app1.log
192.168.245.129(192.168.245.129:) (current master)
+--192.168.245.131(192.168.245.131:)
+--192.168.245.132(192.168.245.132:) Mon Nov :: - [warning] master_ip_failover_script is not defined.
Mon Nov :: - [warning] shutdown_script is not defined.
Mon Nov :: - [info] Set master ping interval seconds.
Mon Nov :: - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from two or more routes.
Mon Nov :: - [info] Starting ping health check on 192.168.245.129(192.168.245.129:)..
Mon Nov :: - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond..
当看到最后一句“Ping(SELECT) succeeded, waiting until MySQL doesn't respond..”表示mha已经启动起来了。当然,你或许在一台机子上希望监控多套master-salve复制,这非常容易,只要为第二套集群创建一个新的配置文件并启动manager
# masterha_manager --conf=/etc/conf/masterha/app1.cnf
# masterha_manager --conf=/etc/conf/masterha/app2.cnf
如果你在app1和app2上有一些共有的参数,可在全局配置文件中配置。
启动参数介绍:
--remove_dead_master_conf 该参数表示当发生主从切换后,老的主库的ip将会从配置文件中移除。如果故障机器修复好了,需要手工添加ip信息到配置文件中
--manger_log 日志存放位置
--ignore_last_failover 在缺省情况下,如果MHA检测到连续发生宕机,且两次宕机间隔不足8小时的话,则不会进行Failover,之所以这样限制是为了避免ping-pong效应。该参数代表忽略上次MHA触发切换产生的文件, 默认情况下,MHA发生切换后会在日志目录,也就是上面我设置的/data产生app1.failover.complete文件,下次再次切换的时候如 果发现该目录下存在该文件将不允许触发切换,除非在第一次切换后收到删除该文件,为了方便,这里设置为--ignore_last_failover。
查看MHA Manager监控是否正常:
[root@node3 app1]# /usr/bin/masterha_check_status --conf=/etc/masterha/app1.conf
app1 (pid:) is running(:PING_OK), master:192.168.245.129
6、模拟测试
(1)自动Failover测试
- 首先用sysbench工具模拟主库业务的写入。
#下载sysbench
http://dev.mysql.com/downloads/benchmarks.html
#安装sysbench
yum install libtool -y #依赖包
tar zxvf sysbench-0.4.12.7.tar.gz
cd sysbench-0.4.12.7
./configure && make && make install
在主库执行,创建sysbench测试表:
(product)root@127.0.0.1 [(none)]> create database sbtest;
Query OK, row affected (0.00 sec) [root@node1 sysbench-0.4.12.7]# /usr/local/bin/sysbench --test=oltp --oltp-table-size= --oltp-read-only=off --init-rng=on --num-threads= --max-requests= --oltp-dist-type=uniform --max-time= --mysql-user=root --mysql-socket=/tmp/mysql_3306.sock --mysql-password=root --mysql-host=192.168.245.129 --db-driver=mysql --mysql-table-engine=innodb --oltp-test-mode=complex prepare
sysbench 0.4.12.6: multi-threaded system evaluation benchmark Creating table 'sbtest'...
Creating records in table 'sbtest'...
- 停止接管主库那个从库的io_thread线程:
(product)root@127.0.0.1 [(none)]> stop slave io_thread;
Query OK, rows affected (0.01 sec)
- 向主库插入数据:
[root@node1 sysbench-0.4.12.7]# /usr/local/bin/sysbench --test=oltp --oltp-table-size= --oltp-read-only=off --init-rng=on --num-threads= --max-requests= --oltp-dist-type=uniform --max-time= --mysql-user=root --mysql-socket=/tmp/mysql_3306.sock --mysql-password=root --mysql-host=192.168.245.129 --db-driver=mysql --mysql-table-engine=innodb --oltp-test-mode=complex run
sysbench 0.4.12.6: multi-threaded system evaluation benchmark Running the test with following options:
Number of threads:
Initializing random number generator from timer. Random number generator seed is and will be ignored Doing OLTP test.
Running mixed OLTP test
Using Uniform distribution
Using "BEGIN" for starting transactions
Using auto_inc on the id column
Using test tables
Threads started!
Time limit exceeded, exiting...
(last message repeated times)
Done. OLTP test statistics:
queries performed:
read:
write:
other:
total:
transactions: (194.05 per sec.)
deadlocks: (0.00 per sec.)
read/write requests: (3686.93 per sec.)
other operations: (388.10 per sec.) Test execution summary:
total time: .0317s
total number of events:
total time taken by event execution: 719.7722
per-request statistics:
min: .47ms
avg: .60ms
max: .43ms
approx. percentile: .17ms Threads fairness:
events (avg/stddev): 8733.7500/260.92
execution time (avg/stddev): 179.9430/0.01
然后启动从库上io_thread:
(product)root@127.0.0.1 [(none)]> start slave io_thread;
Query OK, rows affected, warning (0.00 sec)
- kill主库的mysqld:
pkill - mysqld
最后,查看mha日志,这时已经接管过来了!
Mon Nov :: - [warning] master_ip_failover_script is not defined.
Mon Nov :: - [warning] shutdown_script is not defined.
Mon Nov :: - [info] Set master ping interval seconds.
Mon Nov :: - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from two or more routes.
Mon Nov :: - [info] Starting ping health check on 192.168.245.129(192.168.245.129:)..
Mon Nov :: - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond..
Mon Nov :: - [warning] Got error on MySQL select ping: (MySQL server has gone away)
Mon Nov :: - [info] Executing SSH check script: save_binary_logs --command=test --start_pos= --binlog_dir=/data/mysql/mysql_3306/logs --output_file=/var/log/masterha/app1/save_binary_logs_test --manager_version=0.56 --binlog_prefix=mysql-bin
Mon Nov :: - [info] HealthCheck: SSH to 192.168.245.129 is reachable.
Mon Nov :: - [warning] Got error on MySQL connect: (Lost connection to MySQL server at 'reading initial communication packet', system error: )
Mon Nov :: - [warning] Connection failed time(s)..
Mon Nov :: - [warning] Got error on MySQL connect: (Lost connection to MySQL server at 'reading initial communication packet', system error: )
Mon Nov :: - [warning] Connection failed time(s)..
Mon Nov :: - [warning] Got error on MySQL connect: (Lost connection to MySQL server at 'reading initial communication packet', system error: )
Mon Nov :: - [warning] Connection failed time(s)..
Mon Nov :: - [warning] Master is not reachable from health checker!
Mon Nov :: - [warning] Master 192.168.245.129(192.168.245.129:) is not reachable!
Mon Nov :: - [warning] SSH is reachable.
Mon Nov :: - [info] Connecting to a master server failed. Reading configuration file /etc/masterha_default.cnf and /etc/masterha/app1.conf again, and trying to connect to all servers to check server status..
Mon Nov :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Nov :: - [info] Reading application default configuration from /etc/masterha/app1.conf..
Mon Nov :: - [info] Reading server configuration from /etc/masterha/app1.conf..
Mon Nov :: - [info] GTID failover mode =
Mon Nov :: - [info] Dead Servers:
Mon Nov :: - [info] 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] Alive Servers:
Mon Nov :: - [info] 192.168.245.131(192.168.245.131:)
Mon Nov :: - [info] 192.168.245.132(192.168.245.132:)
Mon Nov :: - [info] Alive Slaves:
Mon Nov :: - [info] 192.168.245.131(192.168.245.131:) Version=5.6.-log (oldest major version between slaves) log-bin:enabled
Mon Nov :: - [info] Replicating from 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Mon Nov :: - [info] 192.168.245.132(192.168.245.132:) Version=5.6.-log (oldest major version between slaves) log-bin:enabled
Mon Nov :: - [info] Replicating from 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] Checking slave configurations..
Mon Nov :: - [info] read_only= is not set on slave 192.168.245.131(192.168.245.131:).
Mon Nov :: - [info] read_only= is not set on slave 192.168.245.132(192.168.245.132:).
Mon Nov :: - [info] Checking replication filtering settings..
Mon Nov :: - [info] Replication filtering check ok.
Mon Nov :: - [info] Master is down!
Mon Nov :: - [info] Terminating monitoring script.
Mon Nov :: - [info] Got exit code (Master dead).
Mon Nov :: - [info] MHA::MasterFailover version 0.56.
Mon Nov :: - [info] Starting master failover.
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase : Configuration Check Phase..
Mon Nov :: - [info]
Mon Nov :: - [info] GTID failover mode =
Mon Nov :: - [info] Dead Servers:
Mon Nov :: - [info] 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] Checking master reachability via MySQL(double check)...
Mon Nov :: - [info] ok.
Mon Nov :: - [info] Alive Servers:
Mon Nov :: - [info] 192.168.245.131(192.168.245.131:)
Mon Nov :: - [info] 192.168.245.132(192.168.245.132:)
Mon Nov :: - [info] Alive Slaves:
Mon Nov :: - [info] 192.168.245.131(192.168.245.131:) Version=5.6.-log (oldest major version between slaves) log-bin:enabled
Mon Nov :: - [info] Replicating from 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Mon Nov :: - [info] 192.168.245.132(192.168.245.132:) Version=5.6.-log (oldest major version between slaves) log-bin:enabled
Mon Nov :: - [info] Replicating from 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] Starting Non-GTID based failover.
Mon Nov :: - [info]
Mon Nov :: - [info] ** Phase : Configuration Check Phase completed.
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase : Dead Master Shutdown Phase..
Mon Nov :: - [info]
Mon Nov :: - [info] Forcing shutdown so that applications never connect to the current master..
Mon Nov :: - [warning] master_ip_failover_script is not set. Skipping invalidating dead master IP address.
Mon Nov :: - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.
Mon Nov :: - [info] * Phase : Dead Master Shutdown Phase completed.
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase : Master Recovery Phase..
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase 3.1: Getting Latest Slaves Phase..
Mon Nov :: - [info]
Mon Nov :: - [info] The latest binary log file/position on all slaves is mysql-bin.:
Mon Nov :: - [info] Latest slaves (Slaves that received relay log files to the latest):
Mon Nov :: - [info] 192.168.245.131(192.168.245.131:) Version=5.6.-log (oldest major version between slaves) log-bin:enabled
Mon Nov :: - [info] Replicating from 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Mon Nov :: - [info] 192.168.245.132(192.168.245.132:) Version=5.6.-log (oldest major version between slaves) log-bin:enabled
Mon Nov :: - [info] Replicating from 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] The oldest binary log file/position on all slaves is mysql-bin.:
Mon Nov :: - [info] Oldest slaves:
Mon Nov :: - [info] 192.168.245.131(192.168.245.131:) Version=5.6.-log (oldest major version between slaves) log-bin:enabled
Mon Nov :: - [info] Replicating from 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Mon Nov :: - [info] 192.168.245.132(192.168.245.132:) Version=5.6.-log (oldest major version between slaves) log-bin:enabled
Mon Nov :: - [info] Replicating from 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase 3.2: Saving Dead Master's Binlog Phase..
Mon Nov :: - [info]
Mon Nov :: - [info] Fetching dead master's binary logs..
Mon Nov :: - [info] Executing command on the dead master 192.168.245.129(192.168.245.129:): save_binary_logs --command=save --start_file=mysql-bin. --start_pos= --binlog_dir=/data/mysql/mysql_3306/logs --output_file=/var/log/masterha/app
/saved_master_binlog_from_192.168.245.129_3306_20151116030215.binlog --handle_raw_binlog= --disable_log_bin= --manager_version=0.56
Creating /var/log/masterha/app1 if not exists.. ok.
Concat binary/relay logs from mysql-bin. pos to mysql-bin. EOF into /var/log/masterha/app1/saved_master_binlog_from_192.168.245.129_3306_20151116030215.binlog ..
Binlog Checksum enabled
Dumping binlog format description event, from position to .. ok.
No need to dump effective binlog data from /data/mysql/mysql_3306/logs/mysql-bin. (pos starts , filesize ). Skipping.
Binlog Checksum enabled
/var/log/masterha/app1/saved_master_binlog_from_192.168.245.129_3306_20151116030215.binlog has no effective data events.
Event not exists.
Mon Nov :: - [info] Additional events were not found from the orig master. No need to save.
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase 3.3: Determining New Master Phase..
Mon Nov :: - [info]
Mon Nov :: - [info] Finding the latest slave that has all relay logs for recovering other slaves..
Mon Nov :: - [info] All slaves received relay logs to the same position. No need to resync each other.
Mon Nov :: - [info] Searching new master from slaves..
Mon Nov :: - [info] Candidate masters from the configuration file:
Mon Nov :: - [info] 192.168.245.131(192.168.245.131:) Version=5.6.-log (oldest major version between slaves) log-bin:enabled
Mon Nov :: - [info] Replicating from 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Mon Nov :: - [info] Non-candidate masters:
Mon Nov :: - [info] Searching from candidate_master slaves which have received the latest relay log events..
Mon Nov :: - [info] New master is 192.168.245.131(192.168.245.131:)
Mon Nov :: - [info] Starting master failover..
Mon Nov :: - [info]
From:
192.168.245.129(192.168.245.129:) (current master)
+--192.168.245.131(192.168.245.131:)
+--192.168.245.132(192.168.245.132:) To:
192.168.245.131(192.168.245.131:) (new master)
+--192.168.245.132(192.168.245.132:)
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase 3.3: New Master Diff Log Generation Phase..
Mon Nov :: - [info]
Mon Nov :: - [info] This server has all relay logs. No need to generate diff files from the latest slave.
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase 3.4: Master Log Apply Phase..
Mon Nov :: - [info]
Mon Nov :: - [info] *NOTICE: If any error happens from this phase, manual recovery is needed.
Mon Nov :: - [info] Starting recovery on 192.168.245.131(192.168.245.131:)..
Mon Nov :: - [info] This server has all relay logs. Waiting all logs to be applied..
Mon Nov :: - [info] done.
Mon Nov :: - [info] All relay logs were successfully applied.
Mon Nov :: - [info] Getting new master's binlog name and position..
Mon Nov :: - [info] mysql-bin.:
Mon Nov :: - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.245.131', MASTER_PORT=, MASTER_LOG_FILE='mysql-bin.000013', MASTER_LOG_POS=, MASTER_USER='repl', MASTER_PASSWOR
D='xxx';
Mon Nov :: - [warning] master_ip_failover_script is not set. Skipping taking over new master IP address.
Mon Nov :: - [info] ** Finished master recovery successfully.
Mon Nov :: - [info] * Phase : Master Recovery Phase completed.
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase : Slaves Recovery Phase..
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase 4.1: Starting Parallel Slave Diff Log Generation Phase..
Mon Nov :: - [info]
Mon Nov :: - [info] -- Slave diff file generation on host 192.168.245.132(192.168.245.132:) started, pid: . Check tmp log /var/log/masterha/app1/192.168..132_3306_20151116030215.log if it takes time..
Mon Nov :: - [info]
Mon Nov :: - [info] Log messages from 192.168.245.132 ...
Mon Nov :: - [info]
Mon Nov :: - [info] This server has all relay logs. No need to generate diff files from the latest slave.
Mon Nov :: - [info] End of log messages from 192.168.245.132.
Mon Nov :: - [info] -- 192.168.245.132(192.168.245.132:) has the latest relay log events.
Mon Nov :: - [info] Generating relay diff files from the latest slave succeeded.
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase 4.2: Starting Parallel Slave Log Apply Phase..
Mon Nov :: - [info]
Mon Nov :: - [info] -- Slave recovery on host 192.168.245.132(192.168.245.132:) started, pid: . Check tmp log /var/log/masterha/app1/192.168..132_3306_20151116030215.log if it takes time..
Mon Nov :: - [info]
Mon Nov :: - [info] Log messages from 192.168.245.132 ...
Mon Nov :: - [info]
Mon Nov :: - [info] Starting recovery on 192.168.245.132(192.168.245.132:)..
Mon Nov :: - [info] This server has all relay logs. Waiting all logs to be applied..
Mon Nov :: - [info] done.
Mon Nov :: - [info] All relay logs were successfully applied.
Mon Nov :: - [info] Resetting slave 192.168.245.132(192.168.245.132:) and starting replication from the new master 192.168.245.131(192.168.245.131:)..
Mon Nov :: - [info] Executed CHANGE MASTER.
Mon Nov :: - [info] Slave started.
Mon Nov :: - [info] End of log messages from 192.168.245.132.
Mon Nov :: - [info] -- Slave recovery on host 192.168.245.132(192.168.245.132:) succeeded.
Mon Nov :: - [info] All new slave servers recovered successfully.
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase : New master cleanup phase..
Mon Nov :: - [info]
Mon Nov :: - [info] Resetting slave info on the new master..
Mon Nov :: - [info] 192.168.245.131: Resetting slave info succeeded.
Mon Nov :: - [info] Master failover to 192.168.245.131(192.168.245.131:) completed successfully.
Mon Nov :: - [info] Deleted server1 entry from /etc/masterha/app1.conf .
Mon Nov :: - [info] ----- Failover Report ----- app1: MySQL Master failover 192.168.245.129(192.168.245.129:) to 192.168.245.131(192.168.245.131:) succeeded Master 192.168.245.129(192.168.245.129:) is down! Check MHA Manager logs at node3:/var/log/masterha/app1/app1.log for details. Started automated(non-interactive) failover.
The latest slave 192.168.245.131(192.168.245.131:) has all relay logs for recovery.
Selected 192.168.245.131(192.168.245.131:) as a new master.
192.168.245.131(192.168.245.131:): OK: Applying all logs succeeded.
192.168.245.132(192.168.245.132:): This host has the latest relay log events.
Generating relay diff files from the latest slave succeeded.
192.168.245.132(192.168.245.132:): OK: Applying all logs succeeded. Slave started, replicating from 192.168.245.131(192.168.245.131:)
192.168.245.131(192.168.245.131:): Resetting slave info succeeded.
Master failover to 192.168.245.131(192.168.245.131:) completed successfully.
)
(2)修复故障master
通常情况下自动切换以后,待原master主机修复后,如果数据完整的情况下,可能想把原来master重新作为新主库的slave,这时我们可以借助当时自动切换时刻的MHA日志来完成对原master的修复。下面是提取相关日志的命令:
[root@node3 masterha]# grep -i "All other slaves should start" /var/log/masterha/app1/app1.log
Mon Nov :: - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.245.131', MASTER_PORT=, MASTER_LOG_FILE='mysql-bin.000013', MASTER_LOG_POS=, MASTER_USER='repl', MASTER_PASSWORD='xxx';
将change master to拿到原master上执行,那么就作为新master的slave了。
(3)在线切换测试
在许多情况下, 需要将现有的主服务器迁移到另外一台服务器上。 比如主服务器硬件故障,RAID 控制卡需要重建,将主服务器移到性能更好的服务器上等等。 MHA 提供快速切换和优雅的阻塞写入,这个切换过程只需要 0.5-2s 的时间,这段时间内数据是无法写入的。在很多情况下,0.5-2s 的阻塞写入是可以接受的。因此切换主服务器不需要计划分配维护时间窗口。
MHA在线切换的大概过程:
1.检测复制设置和确定当前主服务器
2.确定新的主服务器
3.阻塞写入到当前主服务器
4.等待所有从服务器赶上复制
5.授予写入到新的主服务器
6.重新设置从服务器
注意,在线切换的时候应用架构需要考虑以下两个问题:
1.自动识别master和slave的问题(master的机器可能会切换),如果采用了vip的方式,基本可以解决这个问题。
2.负载均衡的问题(可以定义大概的读写比例,每台机器可承担的负载比例,当有机器离开集群时,需要考虑这个问题)
为了保证数据完全一致性,在最快的时间内完成切换,MHA的在线切换必须满足以下条件才会切换成功,否则会切换失败。
1.所有slave的IO线程都在运行
2.所有slave的SQL线程都在运行
3.所有的show slave
status的输出中Seconds_Behind_Master参数小于或者等于running_updates_limit秒,如果在切换过程中不指
定running_updates_limit,那么默认情况下running_updates_limit为1秒。
4.在master端,通过show processlist输出,没有一个更新花费的时间大于running_updates_limit秒。
在线切换步骤如下:
首先,停掉MHA监控:
[root@node3 app1]# svc -d /service/masterha_app
[root@node3 app1]# checkstatus
app1 is stopped(:NOT_RUNNING).
其次,进行在线切换操作(模拟在线切换主库操作,原主库192.168.245.129变为slave,192.168.245.131提升为新的主库)
[root@node3 masterha]# /usr/bin/masterha_master_switch --conf=/etc/masterha/app1.conf --master_state=alive --new_master_host=192.168.245.131 --new_master_port= --orig_master_is_new_slave --running_updates_limit=
Mon Nov :: - [info] MHA::MasterRotate version 0.56.
Mon Nov :: - [info] Starting online master switch..
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase : Configuration Check Phase..
Mon Nov :: - [info]
Mon Nov :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Nov :: - [info] Reading application default configuration from /etc/masterha/app1.conf..
Mon Nov :: - [info] Reading server configuration from /etc/masterha/app1.conf..
Mon Nov :: - [info] GTID failover mode =
Mon Nov :: - [info] Current Alive Master: 192.168.245.129(192.168.245.129:)
Mon Nov :: - [info] Alive Slaves:
Mon Nov :: - [info] 192.168.245.132(192.168.245.132:) Version=5.6.-log (oldest major version between slaves) log-bin:enabled
Mon Nov :: - [info] Replicating from 192.168.245.129(192.168.245.129:) It is better to execute FLUSH NO_WRITE_TO_BINLOG TABLES on the master before switching. Is it ok to execute on 192.168.245.129(192.168.245.129:)? (YES/no): yes
Mon Nov :: - [info] Executing FLUSH NO_WRITE_TO_BINLOG TABLES. This may take long time..
Mon Nov :: - [info] ok.
Mon Nov :: - [info] Checking MHA is not monitoring or doing failover..
Mon Nov :: - [info] Checking replication health on 192.168.245.132..
Mon Nov :: - [info] ok.
Mon Nov 16 21:47:35 2015 - [error][/usr/share/perl5/vendor_perl/MHA/ServerManager.pm, ln1218] 192.168.245.131 is not alive!
Mon Nov 16 21:47:35 2015 - [error][/usr/share/perl5/vendor_perl/MHA/MasterRotate.pm, ln232] Failed to get new master!
Mon Nov 16 21:47:35 2015 - [error][/usr/share/perl5/vendor_perl/MHA/ManagerUtil.pm, ln177] Got ERROR: at /usr/bin/masterha_master_switch line 53
这里怎么会报错呢?意思是131这个机器not alive,可是我去检查下没有问题啊,主从也ok的,后来发现了问题所在,原因是:之前启动的manager脚本中加上了--remove_dead_master_conf参数,导致appl.conf中没有131机器的配置。
然后到app1.conf中加上131机器的配置信息,再次执行:
[root@node3 masterha]# /usr/bin/masterha_master_switch --conf=/etc/masterha/app1.conf --master_state=alive --new_master_host=192.168.245.129 --new_master_port= --orig_master_is_new_slave --running_updates_limit=
Mon Nov :: - [info] MHA::MasterRotate version 0.56.
Mon Nov :: - [info] Starting online master switch..
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase : Configuration Check Phase..
Mon Nov :: - [info]
Mon Nov :: - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Mon Nov :: - [info] Reading application default configuration from /etc/masterha/app1.conf..
Mon Nov :: - [info] Reading server configuration from /etc/masterha/app1.conf..
Mon Nov :: - [info] GTID failover mode =
Mon Nov :: - [info] Current Alive Master: 192.168.245.131(192.168.245.131:)
Mon Nov :: - [info] Alive Slaves:
Mon Nov :: - [info] 192.168.245.129(192.168.245.129:) Version=5.6.-log (oldest major version between slaves) log-bin:enabled
Mon Nov :: - [info] Replicating from 192.168.245.131(192.168.245.131:)
Mon Nov :: - [info] Primary candidate for the new Master (candidate_master is set)
Mon Nov :: - [info] 192.168.245.132(192.168.245.132:) Version=5.6.-log (oldest major version between slaves) log-bin:enabled
Mon Nov :: - [info] Replicating from 192.168.245.131(192.168.245.131:) It is better to execute FLUSH NO_WRITE_TO_BINLOG TABLES on the master before switching. Is it ok to execute on 192.168.245.131(192.168.245.131:)? (YES/no): yes
Mon Nov :: - [info] Executing FLUSH NO_WRITE_TO_BINLOG TABLES. This may take long time..
Mon Nov :: - [info] ok.
Mon Nov :: - [info] Checking MHA is not monitoring or doing failover..
Mon Nov :: - [info] Checking replication health on 192.168.245.129..
Mon Nov :: - [info] ok.
Mon Nov :: - [info] Checking replication health on 192.168.245.132..
Mon Nov :: - [info] ok.
Mon Nov :: - [info] 192.168.245.129 can be new master.
Mon Nov :: - [info]
From:
192.168.245.131(192.168.245.131:) (current master)
+--192.168.245.129(192.168.245.129:)
+--192.168.245.132(192.168.245.132:) To:
192.168.245.129(192.168.245.129:) (new master)
+--192.168.245.132(192.168.245.132:)
+--192.168.245.131(192.168.245.131:) Starting master switch from 192.168.245.131(192.168.245.131:) to 192.168.245.129(192.168.245.129:)? (yes/NO): yes
Mon Nov :: - [info] Checking whether 192.168.245.129(192.168.245.129:) is ok for the new master..
Mon Nov :: - [info] ok.
Mon Nov :: - [info] 192.168.245.131(192.168.245.131:): SHOW SLAVE STATUS returned empty result. To check replication filtering rules, temporarily executing CHANGE MASTER to a dummy host.
Mon Nov :: - [info] 192.168.245.131(192.168.245.131:): Resetting slave pointing to the dummy host.
Mon Nov :: - [info] ** Phase : Configuration Check Phase completed.
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase : Rejecting updates Phase..
Mon Nov :: - [info]
Mon Nov :: - [info] Executing master ip online change script to disable write on the current master:
Mon Nov :: - [info] /etc/masterha/master_ip_online_change --command=stop --orig_master_host=192.168.245.131 --orig_master_ip=192.168.245.131 --orig_master_port= --orig_master_user='root' --orig_master_password='root' --new_master_host=192.168.245.129 --new_master_ip=192.168.245.129 --new_master_port= --new_master_user='root' --new_master_password='root' --orig_master_ssh_user=root --new_master_ssh_user=root --orig_master_is_new_slave
Unknown option: orig_master_password
Unknown option: new_master_password
Unknown option: orig_master_ssh_user
Unknown option: new_master_ssh_user
Unknown option: orig_master_is_new_slave
Mon Nov :: Set read_only on the new master.. ok.
Mon Nov :: Set read_only= on the orig master.. ok.
Disabling the VIP on old master: 192.168.245.131
Mon Nov :: Killing all application threads..
Mon Nov :: done.
Mon Nov :: - [info] ok.
Mon Nov :: - [info] Locking all tables on the orig master to reject updates from everybody (including root):
Mon Nov :: - [info] Executing FLUSH TABLES WITH READ LOCK..
Mon Nov :: - [info] ok.
Mon Nov :: - [info] Orig master binlog:pos is mysql-bin.:.
Mon Nov :: - [info] Waiting to execute all relay logs on 192.168.245.129(192.168.245.129:)..
Mon Nov :: - [info] master_pos_wait(mysql-bin.:) completed on 192.168.245.129(192.168.245.129:). Executed events.
Mon Nov :: - [info] done.
Mon Nov :: - [info] Getting new master's binlog name and position..
Mon Nov :: - [info] mysql-bin.:
Mon Nov :: - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.245.129', MASTER_PORT=, MASTER_LOG_FILE='mysql-bin.000024', MASTER_LOG_POS=, MASTER_USER='repl', MASTER_PASSWORD='xxx';
Mon Nov :: - [info] Executing master ip online change script to allow write on the new master:
Mon Nov :: - [info] /etc/masterha/master_ip_online_change --command=start --orig_master_host=192.168.245.131 --orig_master_ip=192.168.245.131 --orig_master_port= --orig_master_user='root' --orig_master_password='root' --new_master_host=192.168.245.129 --new_master_ip=192.168.245.129 --new_master_port= --new_master_user='root' --new_master_password='root' --orig_master_ssh_user=root --new_master_ssh_user=root --orig_master_is_new_slave
Unknown option: orig_master_password
Unknown option: new_master_password
Unknown option: orig_master_ssh_user
Unknown option: new_master_ssh_user
Unknown option: orig_master_is_new_slave
Mon Nov :: Set read_only= on the new master.
Enabling the VIP - 192.168.245.100/ on the new master - 192.168.245.129
Mon Nov :: - [info] ok.
Mon Nov :: - [info]
Mon Nov :: - [info] * Switching slaves in parallel..
Mon Nov :: - [info]
Mon Nov :: - [info] -- Slave switch on host 192.168.245.132(192.168.245.132:) started, pid:
Mon Nov :: - [info]
Mon Nov :: - [info] Log messages from 192.168.245.132 ...
Mon Nov :: - [info]
Mon Nov :: - [info] Waiting to execute all relay logs on 192.168.245.132(192.168.245.132:)..
Mon Nov :: - [info] master_pos_wait(mysql-bin.:) completed on 192.168.245.132(192.168.245.132:). Executed events.
Mon Nov :: - [info] done.
Mon Nov :: - [info] Resetting slave 192.168.245.132(192.168.245.132:) and starting replication from the new master 192.168.245.129(192.168.245.129:)..
Mon Nov :: - [info] Executed CHANGE MASTER.
Mon Nov :: - [info] Slave started.
Mon Nov :: - [info] End of log messages from 192.168.245.132 ...
Mon Nov :: - [info]
Mon Nov :: - [info] -- Slave switch on host 192.168.245.132(192.168.245.132:) succeeded.
Mon Nov :: - [info] Unlocking all tables on the orig master:
Mon Nov :: - [info] Executing UNLOCK TABLES..
Mon Nov :: - [info] ok.
Mon Nov :: - [info] Starting orig master as a new slave..
Mon Nov :: - [info] Resetting slave 192.168.245.131(192.168.245.131:) and starting replication from the new master 192.168.245.129(192.168.245.129:)..
Mon Nov :: - [info] Executed CHANGE MASTER.
Mon Nov :: - [info] Slave started.
Mon Nov :: - [info] All new slave servers switched successfully.
Mon Nov :: - [info]
Mon Nov :: - [info] * Phase : New master cleanup phase..
Mon Nov :: - [info]
Mon Nov :: - [info] 192.168.245.129: Resetting slave info succeeded.
Mon Nov :: - [info] Switching master to 192.168.245.129(192.168.245.129:) completed successfully.
其中参数的意思:
--orig_master_is_new_slave 切换时加上此参数是将原 master 变为 slave 节点,如果不加此参数,原来的 master 将不启动
--running_updates_limit=10000,故障切换时,候选master 如果有延迟的话, mha 切换不能成功,加上此参数表示延迟在此时间范围内都可切换(单位为s),但是切换的时间长短是由recover 时relay 日志的大小决定
(4)切换时发送邮件:
需要创建一个send_mail脚本,然后将脚本路径写入app1.conf中即可。
#!/usr/bin/perl # Copyright (C) DeNA Co.,Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc.,
# Franklin Street, Fifth Floor, Boston, MA - USA ## Note: This is a sample script and is not complete. Modify the script based on your environment. use strict;
use warnings FATAL => 'all';
use Mail::Sender;
use Getopt::Long; #new_master_host and new_slave_hosts are set only when recovering master succeeded
my ( $dead_master_host, $new_master_host, $new_slave_hosts, $subject, $body );
my $smtp='smtp.163.com';
my $mail_from='xxxx';
my $mail_user='xxxxx';
my $mail_pass='xxxxx';
my $mail_to=['xxxx','xxxx'];
GetOptions(
'orig_master_host=s' => \$dead_master_host,
'new_master_host=s' => \$new_master_host,
'new_slave_hosts=s' => \$new_slave_hosts,
'subject=s' => \$subject,
'body=s' => \$body,
); mailToContacts($smtp,$mail_from,$mail_user,$mail_pass,$mail_to,$subject,$body); sub mailToContacts {
my ( $smtp, $mail_from, $user, $passwd, $mail_to, $subject, $msg ) = @_;
open my $DEBUG, "> /tmp/monitormail.log"
or die "Can't open the debug file:$!\n";
my $sender = new Mail::Sender {
ctype => 'text/plain; charset=utf-8',
encoding => 'utf-8',
smtp => $smtp,
from => $mail_from,
auth => 'LOGIN',
TLS_allowed => '',
authid => $user,
authpwd => $passwd,
to => $mail_to,
subject => $subject,
debug => $DEBUG
}; $sender->MailMsg(
{ msg => $msg,
debug => $DEBUG
}
) or print $Mail::Sender::Error;
return ;
} # Do whatever you want here exit ;
至此,mysql mha部分就搞定了,下面将会结合mha这个架构加入代理层,从而实现读写分离功能,主要采用360公司的Atlas,敬请期待。。。
mysql高可用研究(一) 主从+MHA架构的更多相关文章
- mysql高可用研究(一) 主从+MHA架构 (转)
最近在研究mysql的高可用架构,自己想总结下常用的高可用方案都有哪些.有哪些优缺点以及应用的场景?搞得是头昏脑涨,天昏地暗,看了诸多资料,每次都觉得公说公有理婆说婆有理.其实嘛,大家说的都有一定的道 ...
- mysql高可用研究(二) 主从+MHA+Atlas
关于Atlas的详细介绍请访问:https://github.com/Qihoo360/Atlas/blob/master/README_ZH.md 为什么要使用Atlas?应用程序直连数据库不好吗? ...
- 优酷土豆资深工程师:MySQL高可用之MaxScale与MHA
本文根据DBAplus社群第67期线上分享整理而成 本次分享主要包括以下内容: 1.MySQL高可用方案 2.为什么选择MHA 3.读写分离方案的寻找以及为什么选择Maxscale 一.MySQL ...
- (5.9)mysql高可用系列——正常主从切换测试
[0]实验环境 操作系统:CentOS linux 7.5 数据库版本:5.7.24 数据库架构:主从复制,主库用于生产,从库用于数据容灾和主库备机,采用默认传统的异步复制. 主库IP:192.168 ...
- MySQL高可用架构之MHA
简介: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是 ...
- MySQL高可用架构-MHA环境部署记录
一.MHA介绍 MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司) ...
- MySQL高可用架构之基于MHA的搭建
一.MySQL MHA架构介绍: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Fa ...
- 转一下大师兄的"MySQL高可用架构之MHA"
简介: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是 ...
- (转)MySQL高可用架构之MHA
MySQL高可用架构之MHA 原文:http://www.cnblogs.com/gomysql/p/3675429.html 简介: MHA(Master High Availability)目前 ...
随机推荐
- Ffmpeg音频转码 卡顿(MP2转AAC)
最好经手一个小的功能将mp2实时流转成AAC并发布成rtmp音频流,本身不是很难的一个需求, 一个晚上就能将功能开发好.功能开发完毕后,找来一音频文件利用Ffmpeg命令将音视频文件推成 实时udp格 ...
- window.location网页URL信息
window.location属性 描述 hash 设置或获取 href 属性中在井号“#”后面的分段. host 设置或获取 location 或 URL 的 hostname 和 port 号码. ...
- sql2000实现row_number
一.以PersonID,classid,dt_ClassData为条件进行分组,每个小组加序号,row_number在sql2005中不可用 方法一.sql2000及以上版本--以PersonID,c ...
- java笔记之static&final&abstract
知识需要不断回顾和重新认识 一:static static类型变量初始值只能被赋值一次,它的整个生命周期是源程序,程序结束前变量都不会被释放. 例如: for(int i = 0; i<10; ...
- Spring事务管理之声明式事务管理-基于AspectJ的XML方式
© 版权声明:本文为博主原创文章,转载请注明出处 案例 - 利用Spring的声明式事务(AspectJ)管理模拟转账过程 数据库准备 -- 创建表 CREATE TABLE `account`( ` ...
- 【cocos2dx开发技巧10】cocosStudio的集成以及c++11的新特性
转发.请保持地址:http://blog.csdn.net/stalendp/article/details/38880997 非常长时间没有碰cocos2dx了,近期又用起来了.花了好几个小时又一次 ...
- ipmi 最新和MegaCli 监控磁盘和raid信息
集群监控之 —— ipmi操作指南 原创 2010年03月23日 16:45:00 标签: 集群 / 服务器 / command / callback / user / interface 12224 ...
- grep -rl tttt /data/ 命令在 /data 目录下面搜寻包含tttt字符的命令
grep --help -R, -r, --recursive equivalent to --directories=recurse -l, --files-with-matches print o ...
- vue实践---vue结合 promise 封装原生ajax
有时候不想使用axios这样的外部依赖,想自己封装ajax,这里有两种方法 方法一,在单个页面内使用 封装的代码如下: beforeCreate () { this.$http = (() => ...
- Android中打包JAR时获取资源ID的方法
前言:在打包android源码的时,有的时候源码中包含了资源文件,但是jar包中不包含,所以会异常,解决的方案就是不用系统的提供的id名,而是直接 获取id,如反射. 1.系统提供的方法: /** * ...