mysql-master-ha 实现mysql master的高可用。

好久没有写技术博客了, 这几天重新把《高可用mysql》 这本书捡起来看一遍,里面提到了用https://launchpad.net/mysql-replicant-python 来提供自动主备复制 , 由此想到了之前看中国数据库技术大会中提到的mysql-master-ha来提供master的高可用方案,在测试集群上做了一下测试。

测试环境:

OS: centos 6.5

mysql: 5.6.27-log

mysql-master-ha: 0.56

和https://code.google.com/p/mysql-master-ha/wiki/TableOfContents?tm=6提供的文档一样,采用了如下mysql测试拓扑结构:

MySQL master(一台 )

mysql slave (2 台 )

mysql-master-ha-manager(一台 )

在所有机器上安装 mysql-master-ha node 节点,安装mysql-master-ha node manager; 安装方法参考这里: https://code.google.com/p/mysql-master-ha/wiki/Tutorial

配置好mysql master 到 MySQL slave 的主从复制关系以后,我们在manger节点启动 masterha_manager

masterha_manager --conf=./app1.conf

然后我们在master节点上killall -9 mysqld mysqld_safe把master杀掉, 观察manager节点上的日志输出 , 来理解mysql-master-ha 是如何做mysql master的高可用的:

[[email protected] mysql-master-ha-conf]# masterha_manager --conf=./app1.conf

Tue Nov 10 10:49:40 2015 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.

Tue Nov 10 10:49:40 2015 - [info] Reading application default configuration from ./app1.conf..

Tue Nov 10 10:49:40 2015 - [info] Reading server configuration from ./app1.conf..

Tue Nov 10 10:49:40 2015 - [info] MHA::MasterMonitor version 0.56.

Tue Nov 10 10:49:40 2015 - [info] GTID failover mode = 0

1\发现old master不可用。

Tue Nov 10 10:49:40 2015 - [info] Dead Servers:

Tue Nov 10 10:49:40 2015 - [info] server7(server7:3307)

Tue Nov 10 10:49:40 2015 - [info] Alive Servers:

Tue Nov 10 10:49:40 2015 - [info] server6(server6:3307)

Tue Nov 10 10:49:40 2015 - [info] server8(server8:3307)

Tue Nov 10 10:49:40 2015 - [info] Alive Slaves:

Tue Nov 10 10:49:40 2015 - [info] server6(server6:3307) Version=5.6.27-log (oldest major version between slaves) log-bin:enabled

Tue Nov 10 10:49:40 2015 - [info] Replicating from server7(server7:3307)

Tue Nov 10 10:49:40 2015 - [info] server8(server8:3307) Version=5.6.27-log (oldest major version between slaves) log-bin:enabled

Tue Nov 10 10:49:40 2015 - [info] Replicating from server7(server7:3307)

Tue Nov 10 10:49:40 2015 - [warning] MySQL master is not currently alive!

2\检查slave配置, 检查master 的ssh连通性,检查master binlog备份脚本的有效性。

检查slave 的ssh联通性: 进入slave检查relay-log 的apply_diff_relay_logs脚本:

Tue Nov 10 10:49:40 2015 - [info] Checking slave configurations..

Tue Nov 10 10:49:40 2015 - [info] read_only=1 is not set on slave server6(server6:3307).

Tue Nov 10 10:49:40 2015 - [warning] relay_log_purge=0 is not set on slave server6(server6:3307).

Tue Nov 10 10:49:40 2015 - [info] read_only=1 is not set on slave server8(server8:3307).

Tue Nov 10 10:49:40 2015 - [info] Checking replication filtering settings..

Tue Nov 10 10:49:40 2015 - [info] Replication filtering check ok.

Tue Nov 10 10:49:40 2015 - [info] GTID (with auto-pos) is not supported

Tue Nov 10 10:49:40 2015 - [info] Starting SSH connection tests..

Tue Nov 10 10:49:41 2015 - [info] All SSH connection tests passed successfully.

Tue Nov 10 10:49:41 2015 - [info] Checking MHA Node version..

Tue Nov 10 10:49:42 2015 - [info] Version check ok.

Tue Nov 10 10:49:42 2015 - [info] Getting current master (maybe dead) info ..

Tue Nov 10 10:49:42 2015 - [info] Identified master is server7(server7:3307).

Tue Nov 10 10:49:42 2015 - [info] Checking SSH publickey authentication settings on the current master..

Tue Nov 10 10:49:42 2015 - [info] HealthCheck: SSH to server7 is reachable.

Tue Nov 10 10:49:43 2015 - [info] Master MHA Node version is 0.56.

Tue Nov 10 10:49:43 2015 - [info] Checking recovery script configurations on server7(server7:3307)..

Tue Nov 10 10:49:43 2015 - [info] Executing command: save_binary_logs --command=test --start_pos=4 --binlog_dir=/var/lib/mysql,/var/log/mysql --output_file=/var/log/masterha/app1/save_binary_logs_test --manager_version=0.56 --start_file=master-bin.000004

Tue Nov 10 10:49:43 2015 - [info] Connecting to [email protected](server7:22)..

Creating /var/log/masterha/app1 if not exists.. ok.

Checking output directory is accessible or not..

ok.

Binlog found at /var/lib/mysql, up to master-bin.000004

Tue Nov 10 10:49:43 2015 - [info] Binlog setting check done.

Tue Nov 10 10:49:43 2015 - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..

Tue Nov 10 10:49:43 2015 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user=‘root‘ --slave_host=server6 --slave_ip=server6 --slave_port=3307 --workdir=/var/log/masterha/app1 --target_version=5.6.27-log --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx

Tue Nov 10 10:49:43 2015 - [info] Connecting to [email protected](server6:22)..

Checking slave recovery environment settings..

Opening /var/lib/mysql/relay-log.info ... ok.

Relay log found at /var/lib/mysql, up to mysqld-relay-bin.000007

Temporary relay log file is /var/lib/mysql/mysqld-relay-bin.000007

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.

Tue Nov 10 10:49:43 2015 - [info] Executing command : apply_diff_relay_logs --command=test --slave_user=‘root‘ --slave_host=server8 --slave_ip=server8 --slave_port=3307 --workdir=/var/log/masterha/app1 --target_version=5.6.27-log --manager_version=0.56 --relay_log_info=/var/lib/mysql/relay-log.info --relay_dir=/var/lib/mysql/ --slave_pass=xxx

Tue Nov 10 10:49:43 2015 - [info] Connecting to [email protected](server8:22)..

Checking slave recovery environment settings..

Opening /var/lib/mysql/relay-log.info ... ok.

Relay log found at /var/lib/mysql, up to slave-relay-bin.000004

Temporary relay log file is /var/lib/mysql/slave-relay-bin.000004

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.

Tue Nov 10 10:49:44 2015 - [info] Slaves settings check done.

Tue Nov 10 10:49:44 2015 - [info]

server7(server7:3307) (current master)

+--server6(server6:3307)

+--server8(server8:3307)

3、确认 old master的mysql不可到达 (ping 3307端口不可用, 建议设置二级检查, 从

多个路由确认old master不可到达。), 连续多次ping old master的3307端口不可到达以后,

准备启动master failover;

----

Tue Nov 10 10:49:44 2015 - [warning] master_ip_failover_script is not defined.

Tue Nov 10 10:49:44 2015 - [warning] shutdown_script is not defined.

Tue Nov 10 10:49:44 2015 - [error][/usr/local/share/perl5/MHA/Server.pm, ln457] Checking slave status failed on server6(server6:3307). err=Got error when executing SHOW SLAVE STATUS. MySQL server has gone away

Tue Nov 10 10:49:44 2015 - [info] Set master ping interval 3 seconds.

Tue Nov 10 10:49:44 2015 - [warning] secondary_check_script is not defined. It is highly recommended setting it to check master reachability from two or more routes.

Tue Nov 10 10:49:44 2015 - [info] Starting ping health check on server7(server7:3307)..

Tue Nov 10 10:49:44 2015 - [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at ‘reading initial communication packet‘, system error: 111)

Tue Nov 10 10:49:44 2015 - [warning] Connection failed 1 time(s)..

Tue Nov 10 10:49:44 2015 - [info] Executing SSH check script: save_binary_logs --command=test --start_pos=4 --binlog_dir=/var/lib/mysql,/var/log/mysql --output_file=/var/log/masterha/app1/save_binary_logs_test --manager_version=0.56 --binlog_prefix=master-bin

Creating /var/log/masterha/app1 if not exists.. ok.

Checking output directory is accessible or not..

ok.

Binlog found at /var/lib/mysql, up to master-bin.000004

Tue Nov 10 10:49:44 2015 - [info] HealthCheck: SSH to server7 is reachable.

Tue Nov 10 10:49:47 2015 - [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at ‘reading initial communication packet‘, system error: 111)

Tue Nov 10 10:49:47 2015 - [warning] Connection failed 2 time(s)..

Tue Nov 10 10:49:50 2015 - [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at ‘reading initial communication packet‘, system error: 111)

Tue Nov 10 10:49:50 2015 - [warning] Connection failed 3 time(s)..

Tue Nov 10 10:49:53 2015 - [warning] Got error on MySQL connect: 2013 (Lost connection to MySQL server at ‘reading initial communication packet‘, system error: 111)

Tue Nov 10 10:49:53 2015 - [warning] Connection failed 4 time(s)..

Tue Nov 10 10:49:53 2015 - [warning] Master is not reachable from health checker!

Tue Nov 10 10:49:53 2015 - [warning] Master server7(server7:3307) is not reachable!

Tue Nov 10 10:49:53 2015 - [warning] SSH is reachable.

Tue Nov 10 10:49:53 2015 - [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..

Tue Nov 10 10:49:53 2015 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.

Tue Nov 10 10:49:53 2015 - [info] Reading application default configuration from ./app1.conf..

Tue Nov 10 10:49:53 2015 - [info] Reading server configuration from ./app1.conf..

Tue Nov 10 10:49:53 2015 - [info] GTID failover mode = 0

Tue Nov 10 10:49:53 2015 - [info] Dead Servers:

Tue Nov 10 10:49:53 2015 - [info] server7(server7:3307)

Tue Nov 10 10:49:53 2015 - [info] Alive Servers:

Tue Nov 10 10:49:53 2015 - [info] server6(server6:3307)

Tue Nov 10 10:49:53 2015 - [info] server8(server8:3307)

Tue Nov 10 10:49:53 2015 - [info] Alive Slaves:

Tue Nov 10 10:49:53 2015 - [info] server6(server6:3307) Version=5.6.27-log (oldest major version between slaves) log-bin:enabled

Tue Nov 10 10:49:53 2015 - [info] Replicating from server7(server7:3307)

Tue Nov 10 10:49:53 2015 - [info] server8(server8:3307) Version=5.6.27-log (oldest major version between slaves) log-bin:enabled

Tue Nov 10 10:49:53 2015 - [info] Replicating from server7(server7:3307)

Tue Nov 10 10:49:53 2015 - [info] Checking slave configurations..

Tue Nov 10 10:49:53 2015 - [info] read_only=1 is not set on slave server6(server6:3307).

Tue Nov 10 10:49:53 2015 - [warning] relay_log_purge=0 is not set on slave server6(server6:3307).

Tue Nov 10 10:49:53 2015 - [info] read_only=1 is not set on slave server8(server8:3307).

Tue Nov 10 10:49:53 2015 - [info] Checking replication filtering settings..

Tue Nov 10 10:49:53 2015 - [info] Replication filtering check ok.

Tue Nov 10 10:49:53 2015 - [info] Master is down!

Tue Nov 10 10:49:53 2015 - [info] Terminating monitoring script.

Tue Nov 10 10:49:53 2015 - [info] Got exit code 20 (Master dead).

Tue Nov 10 10:49:53 2015 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.

Tue Nov 10 10:49:53 2015 - [info] Reading application default configuration from ./app1.conf..

Tue Nov 10 10:49:53 2015 - [info] Reading server configuration from ./app1.conf..

Tue Nov 10 10:49:53 2015 - [info] MHA::MasterFailover version 0.56.

4、启动master failover :

1) 阶段1 : 配置检查:

Tue Nov 10 10:49:53 2015 - [info] Starting master failover.

Tue Nov 10 10:49:53 2015 - [info]

Tue Nov 10 10:49:53 2015 - [info] * Phase 1: Configuration Check Phase..

Tue Nov 10 10:49:53 2015 - [info]

Tue Nov 10 10:49:53 2015 - [info] GTID failover mode = 0

Tue Nov 10 10:49:53 2015 - [info] Dead Servers:

Tue Nov 10 10:49:53 2015 - [info] server7(server7:3307)

Tue Nov 10 10:49:53 2015 - [info] Checking master reachability via MySQL(double check)...

Tue Nov 10 10:49:53 2015 - [info] ok.

Tue Nov 10 10:49:53 2015 - [info] Alive Servers:

Tue Nov 10 10:49:53 2015 - [info] server6(server6:3307)

Tue Nov 10 10:49:53 2015 - [info] server8(server8:3307)

Tue Nov 10 10:49:53 2015 - [info] Alive Slaves:

Tue Nov 10 10:49:53 2015 - [info] server6(server6:3307) Version=5.6.27-log (oldest major version between slaves) log-bin:enabled

Tue Nov 10 10:49:53 2015 - [info] Replicating from server7(server7:3307)

Tue Nov 10 10:49:53 2015 - [info] server8(server8:3307) Version=5.6.27-log (oldest major version between slaves) log-bin:enabled

Tue Nov 10 10:49:53 2015 - [info] Replicating from server7(server7:3307)

Tue Nov 10 10:49:53 2015 - [info] Starting Non-GTID based failover.

Tue Nov 10 10:49:53 2015 - [info]

Tue Nov 10 10:49:53 2015 - [info] ** Phase 1: Configuration Check Phase completed.

Tue Nov 10 10:49:53 2015 - [info]

2) 阶段2: 关闭dead master(master_ip_failover_script脚本没有做 , 忽略对deadmaster

的ip 失效,。);

Tue Nov 10 10:49:53 2015 - [info] * Phase 2: Dead Master Shutdown Phase..

Tue Nov 10 10:49:53 2015 - [info]

Tue Nov 10 10:49:53 2015 - [info] Forcing shutdown so that applications never connect to the current master..

Tue Nov 10 10:49:53 2015 - [warning] master_ip_failover_script is not set. Skipping invalidating dead master IP address.

Tue Nov 10 10:49:53 2015 - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.

Tue Nov 10 10:49:53 2015 - [info] * Phase 2: Dead Master Shutdown Phase completed.

Tue Nov 10 10:49:53 2015 - [info]

3) 阶段3 : master恢复阶段:

A:找lastest slave :

show slave status: 得到的Relay_Master_Log_File + Read_Master_Log_Pos 最大的就可以 。

因为server6和server8 的读取master位点一样,所以都是oldest和lastest ;

Tue Nov 10 10:49:53 2015 - [info] * Phase 3: Master Recovery Phase..

Tue Nov 10 10:49:53 2015 - [info]

Tue Nov 10 10:49:53 2015 - [info] * Phase 3.1: Getting Latest Slaves Phase..

Tue Nov 10 10:49:53 2015 - [info]

Tue Nov 10 10:49:53 2015 - [info] The latest binary log file/position on all slaves is master-bin.000004:120

Tue Nov 10 10:49:53 2015 - [info] Latest slaves (Slaves that received relay log files to the latest):

Tue Nov 10 10:49:53 2015 - [info] server6(server6:3307) Version=5.6.27-log (oldest major version between slaves) log-bin:enabled

Tue Nov 10 10:49:53 2015 - [info] Replicating from server7(server7:3307)

Tue Nov 10 10:49:53 2015 - [info] server8(server8:3307) Version=5.6.27-log (oldest major version between slaves) log-bin:enabled

Tue Nov 10 10:49:53 2015 - [info] Replicating from server7(server7:3307)

Tue Nov 10 10:49:53 2015 - [info] The oldest binary log file/position on all slaves is master-bin.000004:120

Tue Nov 10 10:49:53 2015 - [info] Oldest slaves:

Tue Nov 10 10:49:53 2015 - [info] server6(server6:3307) Version=5.6.27-log (oldest major version between slaves) log-bin:enabled

Tue Nov 10 10:49:53 2015 - [info] Replicating from server7(server7:3307)

Tue Nov 10 10:49:53 2015 - [info] server8(server8:3307) Version=5.6.27-log (oldest major version between slaves) log-bin:enabled

Tue Nov 10 10:49:53 2015 - [info] Replicating from server7(server7:3307)

Tue Nov 10 10:49:53 2015 - [info]

B:保存dead master binlog:

从lastest slave读到的master binlog 的位点开始截取dead master binlog ,加上binlog的文件描述信息。

Tue Nov 10 10:49:53 2015 - [info] * Phase 3.2: Saving Dead Master‘s Binlog Phase..

Tue Nov 10 10:49:53 2015 - [info]

Tue Nov 10 10:49:53 2015 - [info] Fetching dead master‘s binary logs..

Tue Nov 10 10:49:53 2015 - [info] Executing command on the dead master server7(server7:3307): save_binary_logs --command=save --start_file=master-bin.000004 --start_pos=120 --binlog_dir=/var/lib/mysql,/var/log/mysql --output_file=/var/log/masterha/app1/saved_master_binlog_from_server7_3307_20151110104953.binlog --handle_raw_binlog=1 --disable_log_bin=0 --manager_version=0.56

Creating /var/log/masterha/app1 if not exists.. ok.

Concat binary/relay logs from master-bin.000004 pos 120 to master-bin.000004 EOF into /var/log/masterha/app1/saved_master_binlog_from_server7_3307_20151110104953.binlog ..

Binlog Checksum enabled

Dumping binlog format description event, from position 0 to 120.. ok.

No need to dump effective binlog data from /var/lib/mysql/master-bin.000004 (pos starts 120, filesize 120). Skipping.

Binlog Checksum enabled

/var/log/masterha/app1/saved_master_binlog_from_server7_3307_20151110104953.binlog has no effective data events.

Event not exists.

Tue Nov 10 10:49:54 2015 - [info] Additional events were not found from the orig master. No need to save.

C: 选举新的master, 因为所有slave接收到的master位点信息是一样的,所以他们不用再做同步了。

随机找了一台server6 promote成为new master.

Tue Nov 10 10:49:54 2015 - [info]

Tue Nov 10 10:49:54 2015 - [info] * Phase 3.3: Determining New Master Phase..

Tue Nov 10 10:49:54 2015 - [info]

Tue Nov 10 10:49:54 2015 - [info] Finding the latest slave that has all relay logs for recovering other slaves..

Tue Nov 10 10:49:54 2015 - [info] All slaves received relay logs to the same position. No need to resync each other.

Tue Nov 10 10:49:54 2015 - [info] Searching new master from slaves..

Tue Nov 10 10:49:54 2015 - [info] Candidate masters from the configuration file:

Tue Nov 10 10:49:54 2015 - [info] Non-candidate masters:

Tue Nov 10 10:49:54 2015 - [info] New master is server6(server6:3307)

Tue Nov 10 10:49:54 2015 - [info] Starting master failover..

Tue Nov 10 10:49:54 2015 - [info]

From:

server7(server7:3307) (current master)

+--server6(server6:3307)

+--server8(server8:3307)

To:

server6(server6:3307) (new master)

+--server8(server8:3307)

D: 新的master的差异日志生成阶段

new master(server6)已经包含了所有 relay log (就是说dead master 的binlog和new master的 relay log没有差异了--即所谓的deadmaster binlog 和new master relaylog 的差异)

Tue Nov 10 10:49:54 2015 - [info]

Tue Nov 10 10:49:54 2015 - [info] * Phase 3.3: New Master Diff Log Generation Phase..

Tue Nov 10 10:49:54 2015 - [info]

Tue Nov 10 10:49:54 2015 - [info] This server has all relay logs. No need to generate diff files from the latest slave.

Tue Nov 10 10:49:54 2015 - [info]

E: 新的master log应用阶段,即把 new master的relay log和dead master的binlog差异在new master做一次重放。

然后获取到new master的binlog 文件和位点信息(master-bin.000003, pos=120)至此 ,dead master和new master已经同步了。

Tue Nov 10 10:49:54 2015 - [info] * Phase 3.4: Master Log Apply Phase..

Tue Nov 10 10:49:54 2015 - [info]

Tue Nov 10 10:49:54 2015 - [info] *NOTICE: If any error happens from this phase, manual recovery is needed.

Tue Nov 10 10:49:54 2015 - [info] Starting recovery on server6(server6:3307)..

Tue Nov 10 10:49:54 2015 - [info] This server has all relay logs. Waiting all logs to be applied..

Tue Nov 10 10:49:54 2015 - [info] done.

Tue Nov 10 10:49:54 2015 - [info] All relay logs were successfully applied.

Tue Nov 10 10:49:54 2015 - [info] Getting new master‘s binlog name and position..

Tue Nov 10 10:49:54 2015 - [info] master-bin.000003:120

Tue Nov 10 10:49:54 2015 - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST=‘server6 or server6‘, MASTER_PORT=3307, MASTER_LOG_FILE=‘master-bin.000003‘, MASTER_LOG_POS=120, MASTER_USER=‘repl_user‘, MASTER_PASSWORD=‘xxx‘;

Tue Nov 10 10:49:54 2015 - [warning] master_ip_failover_script is not set. Skipping taking over new master IP address.

Tue Nov 10 10:49:54 2015 - [info] ** Finished master recovery successfully.

Tue Nov 10 10:49:54 2015 - [info] * Phase 3: Master Recovery Phase completed.

Tue Nov 10 10:49:54 2015 - [info]

阶段4: 并行操作,对每一个slave .比较它和new master的relay log的位点差异,

然后把这个差异在slave 补全, 最后做change master to new master;

启动slave;

Tue Nov 10 10:49:54 2015 - [info] * Phase 4: Slaves Recovery Phase..

Tue Nov 10 10:49:54 2015 - [info]

Tue Nov 10 10:49:54 2015 - [info] * Phase 4.1: Starting Parallel Slave Diff Log Generation Phase..

Tue Nov 10 10:49:54 2015 - [info]

Tue Nov 10 10:49:54 2015 - [info] -- Slave diff file generation on host server8(server8:3307) started, pid: 34574. Check tmp log /var/log/masterha/app1/server8_3307_20151110104953.log if it takes time..

Tue Nov 10 10:49:54 2015 - [info]

Tue Nov 10 10:49:54 2015 - [info] Log messages from server8 ...

Tue Nov 10 10:49:54 2015 - [info]

Tue Nov 10 10:49:54 2015 - [info] This server has all relay logs. No need to generate diff files from the latest slave.

Tue Nov 10 10:49:54 2015 - [info] End of log messages from server8.

Tue Nov 10 10:49:54 2015 - [info] -- server8(server8:3307) has the latest relay log events.

Tue Nov 10 10:49:54 2015 - [info] Generating relay diff files from the latest slave succeeded.

Tue Nov 10 10:49:54 2015 - [info]

Tue Nov 10 10:49:54 2015 - [info] * Phase 4.2: Starting Parallel Slave Log Apply Phase..

Tue Nov 10 10:49:54 2015 - [info]

Tue Nov 10 10:49:54 2015 - [info] -- Slave recovery on host server8(server8:3307) started, pid: 34576. Check tmp log /var/log/masterha/app1/server8_3307_20151110104953.log if it takes time..

Tue Nov 10 10:49:54 2015 - [info]

Tue Nov 10 10:49:54 2015 - [info] Log messages from server8 ...

Tue Nov 10 10:49:54 2015 - [info]

Tue Nov 10 10:49:54 2015 - [info] Starting recovery on server8(server8:3307)..

Tue Nov 10 10:49:54 2015 - [info] This server has all relay logs. Waiting all logs to be applied..

Tue Nov 10 10:49:54 2015 - [info] done.

Tue Nov 10 10:49:54 2015 - [info] All relay logs were successfully applied.

Tue Nov 10 10:49:54 2015 - [info] Resetting slave server8(server8:3307) and starting replication from the new master server6(server6:3307)..

Tue Nov 10 10:49:54 2015 - [info] Executed CHANGE MASTER.

Tue Nov 10 10:49:54 2015 - [info] Slave started.

Tue Nov 10 10:49:54 2015 - [info] End of log messages from server8.

Tue Nov 10 10:49:54 2015 - [info] -- Slave recovery on host server8(server8:3307) succeeded.

Tue Nov 10 10:49:54 2015 - [info] All new slave servers recovered successfully.

Tue Nov 10 10:49:54 2015 - [info]

阶段5: : 重置new master上的slave info ., 启动new master;

Tue Nov 10 10:49:54 2015 - [info] * Phase 5: New master cleanup phase..

Tue Nov 10 10:49:54 2015 - [info]

Tue Nov 10 10:49:54 2015 - [info] Resetting slave info on the new master..

Tue Nov 10 10:49:54 2015 - [info] server6: Resetting slave info succeeded.

Tue Nov 10 10:49:54 2015 - [info] Master failover to server6(server6:3307) completed successfully.

Tue Nov 10 10:49:54 2015 - [info]

阶段6: 故障转移报告:

----- Failover Report -----

app1: MySQL Master failover server7(server7:3307) to server6(server6:3307) succeeded

Master server7(server7:3307) is down!

Check MHA Manager logs at server9 for details.

Started automated(non-interactive) failover.

The latest slave server6(server6:3307) has all relay logs for recovery.

Selected server6(server6:3307) as a new master.

server6(server6:3307): OK: Applying all logs succeeded.

server8(server8:3307): This host has the latest relay log events.

Generating relay diff files from the latest slave succeeded.

server8(server8:3307): OK: Applying all logs succeeded. Slave started, replicating from server6(server6:3307)

server6(server6:3307): Resetting slave info succeeded.

Master failover to server6(server6:3307) completed successfully.

时间: 2024-10-13 02:21:54

mysql-master-ha 实现mysql master的高可用。的相关文章

使用MHA对mysql主从架构中的主节点做高可用

MHA:Master HA(主从结构的高可用方案)只是实现了对主节点高可用,它是建构在mysql主从复制结构之上的,也就是说需要事先把mysq配置成传统的复制集群. MHA在监控到master节点故障时,会提升其中拥有最新数据的slave节点称为新的master,在此期间,MHA会通过其它从节点获取额外信息来避免一致性方面的问题.MHA还提供了master节点在线切换的功能,即按需切换master/salve节点. MHA服务有两种角色,MHA Manager(管理节点)和MHA Node(数据

Keepalived+MySQL主主互备模式实现高可用      

MySQL的高可用方案很多,这是一个配置简单而且实用的高可用解决方案. 实验架构图: 修改DB1配置文件增加以下几项: [mysqld] log-bin=mysql-bin relay-log=mysql-relay-bin server-id=1 replicate-wild-ignore-table=mysql.% replicate-wild-ignore-table=test.% replicate-wild-ignore-table=information_schema.% 修改DB2

RHEL6搭建 keepalived (HA) 任意单故障节点的高可用集群

搭建 keepalived (HA) 任意单故障节点的高可用集群 实验拓扑图: 实验要求: 使用Keepalived实现web服务器的高可用 Web服务器IP地址分别为192.168.4.53和192.168.4.54 Web服务器53 为主服务器,Web服务器54为备服务器 Web服务器的VIP地址为192.168.4.251 客户端通过访问VIP地址访问Web页面 实验步骤: 实验准备 配置yum源 # service iptables stop            //关闭防火墙 # c

MySQL+Heartbeat+DRBD+LVS+keepalived实现数据库高可用群集

DRBD  概述 一.DRBD简介          DRBD 的全称为:Distributed ReplicatedBlock Device(DRBD)分布式块设备复制,DRBD 是由内核模块和相关脚本而组成,用来构建数据的高可用性集群.其实现方式是通过网络来镜像整个磁盘设备(数据).你可以把它看作是一种基于网络的 RAID1.它允许用户在远程机器上建立一个本地块设备的实时镜像. 二.DRBD工作原理          (DRBD Primary)负责接收数据,把数据写到本地磁盘并发送给另一台

Mysql双主热备+LVS+Keepalived高可用操作记录

MySQL复制能够保证数据的冗余的同时可以做读写分离来分担系统压力,如果是主主复制还可以很好的避免主节点的单点故障.然而MySQL主主复制存在一些问题无法满足我们的实际需要:未提供统一访问入口来实现负载均衡,如果其中master宕掉的话需要手动切换到另外一个master,而不能自动进行切换.前面介绍了Mysql+Keepalived双主热备高可用方案记录,那篇文档里没有使用到LVS(实现负载均衡),而下面要介绍的就是如何通过Keepalived+LVS方式来是实现MySQL的高可用性,利用LVS

MySQL(三):MHA实现MySQL主从架构中主服务器的高可用,zabbix完成manager重启

MHA(Master High Availability)是目前在MySQL高可用方面相对成熟的一个解决方案,MHA在监控到master节点故障时,会提升其中拥有最新数据的slave节点成为新的master节点,在此期间,MHA会通过于其它从节点获取额外信息来避免一致性方面的问题.MHA还提供了master节点的在线切换功能. MHA 服务有两种角色,MHA Manager(管理节点)和 MHA Node(数据节点): MHA Manager:通常单独部署在一台独立机器上管理多个 master/

inotify+rsync+mysql主主复制+keepalived实现zabbix高可用

思路:主备机通过inotify+rsync实现文件同步,通过mysql主主复制实现数据同步,同一时刻只有一台服务器能对外提供zabbix服务,web端登陆虚ip访问,被监控主机通过配置虚ip来完成监控. 配置: 主机 ip 操作系统 zabbix版本 mysql版本 inotify版本 rsync版本 备注 zabbix-server01 172.27.9.80 Centos7.3.1611 zabbix_server (Zabbix) 3.4.10 5.7.22 3.14 3.1.2 关闭防火

MySQL入门篇(五)之高可用架构MHA

一.MHA原理 1.简介: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是一套优秀的作为MySQL高可用性环境下故障切换和主从提升的高可用软件.在MySQL故障切换过程中,MHA能做到在0~30秒之内自动完成数据库的故障切换操作,并且在进行故障切换的过程中,MHA能在最大程度上保证数据的一致性,以达到真正意义上的高可用. 该软件由两部分组成:MHA M

【MySQL进阶】Keepalived1.4.0结合MySQL 5.7.19实现主备高可用

1.基本环境 数据库安装及主备同步接上一篇文章:http://blog.51cto.com/13946719/2309514JDK 1.8_171MySQL 5.7.19CentOS 7.4Keepalived 1.4.0DB1:192.168.200.180DB2:192.168.200.181VIP: 192.168.200.99 2.下载安装Keepalived 2.1.keepalived下载 下载地址:wget http://www.keepalived.org/software/ke

高可用群集HA介绍与LVS+keepalived高可用群集

一.Keepalived介绍 通常使用keepalived技术配合LVS对director和存储进行双机热备,防止单点故障,keepalived专为LVS和HA设计的一款健康检查工具,但演变为后来不仅仅为LVS提供方案,Keepaliced支持故障自动切换(Failover),支持节点健康状态检查(Health Checking),官方网站http://www.keepalived.org/ Keepalived采用VRRP的热备份协议实现Linux服务器的多机热备功能,VRRP,虚拟路由冗余协