Mysql 主主复制失败



故障描述

原因描述 因为机柜PDU老化, 导致整个机柜掉电.
故障时间 20160923-10:09
发现时间 20160929-13:56

架构信息

Tomcat Memcache Keepalive Mysql主主复制

节点信息

序号 节点名称 IP地址 报错信息
1 aipprd1 10.66.1.52 Got fatal error 1236 from master when reading data from binary log: ‘binlog truncated in the middle of event; consider out of disk space on master; the first event ‘mysql-bin.000084’ at 91941417, the last event read from ‘/aip/mysql/data/log/mysql-bin.000084’ at 91941783, the last byte read from ‘/aip/mysql/data/log/mysql-bin.000084’ at 91942912.’
2 aipprd2 10.66.1.51 Got fatal error 1236 from master when reading data from binary log: ‘binlog truncated in the middle of event; consider out of disk space on master; the first event ‘mysql-bin.000082’ at 6369026, the last event read from ‘/aip/mysql/data/log/mysql-bin.000082’ at 6369026, the last byte read from ‘/aip/mysql/data/log/mysql-bin.000082’ at 6369280.’

故障分析

  • 由于Zabbix的Mysql监控脚本的缘故, 没有触发事件, 所以直至20160929检查Zabbix日志的时候, 才发现该故障, 当时KeepaliveVIPaipprd1上, 这个节点上, 数据库是对外服务的;
  • 那么首先以aipprd1为主, 先将aipprd2的从环境同步起来;
  • aipprd2从环境同步完成后, 再将aipprd1的从环境同步起来.

同步AIPPRD2的从环境

检查aipprd2的Slave状态 
根据代码区的描述, Last_Errno的错误代码为1062, 需要手动修改Position.

[root@aipprd2 ~]# mysql -uzabbixmoniter -ppassw0rd -hlocalhost -e "show slave status\G;"
*************************** . row ***************************
Slave_IO_State:
Master_Host: 10.66.1.52
Master_User: root
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: mysql-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error: Error 'Duplicate entry '93FF91EF92866D23E80E4A57D55ED538-n1.tomcat604' for key 'PRIMARY'' on query. Default database: 'aipprd'. Query: 'INSERT INTO eahttpsession ( sessionid, username, account, createtime, loginip,userid,explorer,userDomain,computerName,computerUserName) VALUES ('93FF91EF92866D23E80E4A57D55ED538-n1.tomcat604', '李花', 'XS003_4200', '-- ::', , '','MSIE 7.0','','','')'
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error: Got fatal error from master when reading data from binary log: 'binlog truncated in the middle of event; consider out of disk space on master; the first event 'mysql-bin.' at 6369026, the last event read from '/aip/mysql/data/log/mysql-bin.' at 6369026, the last byte read from '/aip/mysql/data/log/mysql-bin.' at 6369280.'
Last_SQL_Errno:
Last_SQL_Error: Error 'Duplicate entry '93FF91EF92866D23E80E4A57D55ED538-n1.tomcat604' for key 'PRIMARY'' on query. Default database: 'aipprd'. Query: 'INSERT INTO eahttpsession ( sessionid, username, account, createtime, loginip,userid,explorer,userDomain,computerName,computerUserName) VALUES ('93FF91EF92866D23E80E4A57D55ED538-n1.tomcat604', '李花', 'XS003_4200', '-- ::', , '','MSIE 7.0','','','')'
Replicate_Ignore_Server_Ids:
Master_Server_Id:

aipprd2上按照Last_IO_Error中的PosfilePos修改. 
按照报错给出的提示PosfilePos修改后, 报错依旧.

mysql> slave stop;
mysql> CHANGE MASTER TO master_host='10.66.1.52', master_port=, master_user='root', master_password='passw0rd', master_log_file='mysql-bin.000082', master_log_pos=;
mysql> slave start;

aipprd2检查Mysql的日志 
Mysql的日志中记录了Crash开始的时间, 并给出了建议,Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.000082' position 6367510

 :: [Note] Starting crash recovery...
:: [Note] Crash recovery finished.
:: [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.000082' position

aipprd2上按照日志中建议的PosfilePos修改. 
按照日志中建议的PosfilePos修改后, 报错依旧.

mysql> slave stop;
mysql> CHANGE MASTER TO master_host='10.66.1.52', master_port=, master_user='root', master_password='passw0rd', master_log_file='mysql-bin.000082', master_log_pos=;
mysql> slave start;

aipprd1上检查posfile
首先检查show slave status\G;中给出的pos, 发现日志中根本不存在.

[root@aipprd1 log]# mysqlbinlog --no-defaults --start-position= mysql-bin.
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/; # at # :: server id end_log_pos Start: binlog v , server v 5.5.-log created :: at startup ROLLBACK/*!*/;
BINLOG '
47HkVw8BAAAAZwAAAGsAAAAAAAQANS41LjI0LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAADjseRXEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA==
'/*!*/;
ERROR: Error in Log_event::read_log_event(): 'read error', data_len: , event_type:
ERROR: Could not read entry at offset : Error in log format or read error.
DELIMITER # End of log file ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;

此后检查Mysql日志中建议的pos, 发现posfile中是存在此记录的, 而此posfile的最后一个pos6368660, 而show slave status\G;pos6369026, 显然不存在日志文件中.

[root@aipprd1 log]# mysqlbinlog --no-defaults  --start-position= mysql-bin.
/*!40019 SET @@session.max_insert_delayed_threads=0*/;
/*!50003 SET @OLD_COMPLETION_TYPE=@@COMPLETION_TYPE,COMPLETION_TYPE=0*/;
DELIMITER /*!*/; # at # :: server id end_log_pos Start: binlog v , server v 5.5.-log created :: at startup # Warning: this binlog is either in use or was not closed properly. ROLLBACK/*!*/;
BINLOG '
05XkVw8BAAAAZwAAAGsAAAABAAQANS41LjI0LWxvZwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAADTleRXEzgNAAgAEgAEBAQEEgAAVAAEGggAAAAICAgCAA==
'/*!*/;
# at
# at
# at
# at
# at
# at
# at
# at
# at
# at
# at
# End of log file
ROLLBACK /* added by mysqlbinlog */;
/*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/;

最后在mysql-bin.000083中检查show slave status\G;提示pos:6369026, 也不存在.

[root@aipprd1 log]# mysqlbinlog --no-defaults  --start-position= mysql-bin. 

aipprd2上重新发起修改posfilepos操作 
检查aipprd1上的日志, 既然mysql-bin.000082日志末不存在pos:6369026, 且mysql-bin.000083为下一个日志, 那么重新发起修改posfilepos的操作.

[root@aipprd1 log]# ll
total
-rw-rw---- mysql mysql Sep : mysql-bin.
-rw-rw---- mysql mysql Sep : mysql-bin.
-rw-rw---- mysql mysql Sep : mysql-bin.
-rw-rw---- mysql mysql Sep : mysql-bin.
-rw-rw---- mysql mysql Sep : mysql-bin.
-rw-rw---- mysql mysql Sep : mysql-bin.
-rw-rw---- mysql mysql Sep : mysql-bin.
-rw-rw---- mysql mysql Sep : mysql-bin.
-rw-rw---- mysql mysql Sep : mysql-bin.log.index
-rw-rw---- mysql mysql Sep : mysql-relay-bin.
-rw-rw---- mysql mysql Sep : mysql-relay-bin.index

重新修改posfilemysql-bin.000083pos0, 启动Slave后, 现在同步正常.

mysql> slave stop;
mysql> CHANGE MASTER TO master_host='10.66.1.52', master_port=, master_user='root', master_password='passw0rd', master_log_file='mysql-bin.000083', master_log_pos=;
mysql> slave start;
mysql> show slave status\G;
*************************** . row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 10.66.1.52
Master_User: root
Master_Port:
Connect_Retry:
Master_Log_File: mysql-bin.
Read_Master_Log_Pos:
Relay_Log_File: mysql-relay-bin.
Relay_Log_Pos:
Relay_Master_Log_File: mysql-bin.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno:
Last_Error:
Skip_Counter:
Exec_Master_Log_Pos:
Relay_Log_Space:
Until_Condition: None
Until_Log_File:
Until_Log_Pos:
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master:
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno:
Last_IO_Error:
Last_SQL_Errno:
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id:
row in set (0.00 sec)
  • 在同步的过程中, 发现有几个Last_SQL_Error: Error ‘Duplicate entry 1026SQL Error, 这个是因为重复主键导致Slave停止工作, 执行以下操作解决(如果有多条重复的主键, 需要执行多次):

    mysql> slave stop;
    mysql> set GLOBAL SQL_SLAVE_SKIP_COUNTER=;
    mysql> slave start;
  • 还有另一种办法就是修改mysql配置文件/etc/my.cnf[mysqld]下加一行slave_skip_errors = 1062 ,保存后重启mysql,mysql slave可以正常同步了.


同步AIPPRD1的从环境

  • 检查aipprd1的Slave状态

    mysql> show slave status\G;
    *************************** . row ***************************
    Slave_IO_State:
    Master_Host: 10.66.1.51
    Master_User: root
    Master_Port:
    Connect_Retry:
    Master_Log_File: mysql-bin.
    Read_Master_Log_Pos:
    Relay_Log_File: mysql-relay-bin.
    Relay_Log_Pos:
    Relay_Master_Log_File: mysql-bin.
    Slave_IO_Running: No
    Slave_SQL_Running: Yes
    Replicate_Do_DB:
    Replicate_Ignore_DB:
    Replicate_Do_Table:
    Replicate_Ignore_Table:
    Replicate_Wild_Do_Table:
    Replicate_Wild_Ignore_Table:
    Last_Errno:
    Last_Error:
    Skip_Counter:
    Exec_Master_Log_Pos:
    Relay_Log_Space:
    Until_Condition: None
    Until_Log_File:
    Until_Log_Pos:
    Master_SSL_Allowed: No
    Master_SSL_CA_File:
    Master_SSL_CA_Path:
    Master_SSL_Cert:
    Master_SSL_Cipher:
    Master_SSL_Key:
    Seconds_Behind_Master: NULL
    Master_SSL_Verify_Server_Cert: No
    Last_IO_Errno:
    Last_IO_Error: Got fatal error from master when reading data from binary log: 'binlog truncated in the middle of event; consider out of disk space on master; the first event 'mysql-bin.' at 91941417, the last event read from '/aip/mysql/data/log/mysql-bin.' at 91941783, the last byte read from '/aip/mysql/data/log/mysql-bin.' at 91942912.'
    Last_SQL_Errno:
    Last_SQL_Error:
    Replicate_Ignore_Server_Ids:
    Master_Server_Id:
    row in set (0.00 sec)
  • aipprd2上检查日志文件 
    aipprd1上检查show slave status\G;后, 提示需要修改posfile为mysql-bin.000084pos91942912, 因为在aipprd2同步完成后, 实际同步的数据是从aipprd1过来的, 这些数据在aipprd1上本身就存在的.

    [root@aipprd2 log]# ll
    total
    -rw-rw---- mysql mysql Sep : mysql-bin.
    -rw-rw---- mysql mysql Sep : mysql-bin.
    -rw-rw---- mysql mysql Sep : mysql-bin.
    -rw-rw---- mysql mysql Sep : mysql-bin.
    -rw-rw---- mysql mysql Sep : mysql-bin.
    -rw-rw---- mysql mysql Sep : mysql-bin.
    -rw-rw---- mysql mysql Sep : mysql-bin.
    -rw-rw---- mysql mysql Sep : mysql-bin.log.index
    -rw-rw---- mysql mysql Sep : mysql-relay-bin.
    -rw-rw---- mysql mysql Sep : mysql-relay-bin.
    -rw-rw---- mysql mysql Sep : mysql-relay-bin.
    -rw-rw---- mysql mysql Sep : mysql-relay-bin.
    -rw-rw---- mysql mysql Sep : mysql-relay-bin.
    -rw-rw---- mysql mysql Sep : mysql-relay-bin.index
  • aipprd2上检查show master status;后, 记录Posfilemysql-bin.000089, 既然aipprd1的数据为最新的, 且aipprd2已经从aipprd1后同步完成了(通过检查show slave status\G;中的Seconds_Behind_Master:, 如果此项值很小, 应该是同步完成了.), 那么两边的数据应该差不多的.

    mysql> show master status;
    +------------------+-----------+--------------+------------------+
    | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+-----------+--------------+------------------+
    | mysql-bin. | | | |
    +------------------+-----------+--------------+------------------+
    row in set (0.00 sec)
  • aipprd1上发起修改posfilepos操作 
    所以在此用posfilemysql-bin.000089pos0来修改, 启动Slave后, 开始同步.

    mysql> slave stop;
    Query OK, rows affected (0.11 sec)
    mysql> CHANGE MASTER TO master_host='10.66.1.51', master_port=, master_user='root', master_password='passw0rd', master_log_file='mysql-bin.000089', master_log_pos=;
    Query OK, rows affected (0.06 sec)
    mysql> slave start;
    Query OK, rows affected (0.00 sec)
    mysql> show slave status\G;
    *************************** . row ***************************
    Slave_IO_State: Waiting for master to send event
    Master_Host: 10.66.1.51
    Master_User: root
    Master_Port:
    Connect_Retry:
    Master_Log_File: mysql-bin.
    Read_Master_Log_Pos:
    Relay_Log_File: mysql-relay-bin.
    Relay_Log_Pos:
    Relay_Master_Log_File: mysql-bin.
    Slave_IO_Running: Yes
    Slave_SQL_Running: Yes
    Replicate_Do_DB:
    Replicate_Ignore_DB:
    Replicate_Do_Table:
    Replicate_Ignore_Table:
    Replicate_Wild_Do_Table:
    Replicate_Wild_Ignore_Table:
    Last_Errno:
    Last_Error:
    Skip_Counter:
    Exec_Master_Log_Pos:
    Relay_Log_Space:
    Until_Condition: None
    Until_Log_File:
    Until_Log_Pos:
    Master_SSL_Allowed: No
    Master_SSL_CA_File:
    Master_SSL_CA_Path:
    Master_SSL_Cert:
    Master_SSL_Cipher:
    Master_SSL_Key:
    Seconds_Behind_Master:
    Master_SSL_Verify_Server_Cert: No
    Last_IO_Errno:
    Last_IO_Error:
    Last_SQL_Errno:
    Last_SQL_Error:
    Replicate_Ignore_Server_Ids:
    Master_Server_Id:
    row in set (0.00 sec)

转自

Mysql 主主复制失败 - bluetom520的博客 - CSDN博客
http://blog.csdn.net/bluetom520/article/details/54893183

Mysql 主主复制失败恢复【转】的更多相关文章

  1. MySQL灾备恢复在线主从复制变成主主复制及多源复制【转】

    生产主主复制(A<--->B),和灾备主从复制(B--->C).当生产出现问题时,数据写入切换到灾备数据库,待生产恢复后,将灾备回写到生产.步骤如下: 1.灾备与生产其中一台建立主主 ...

  2. MySQL数据的主从复制、半同步复制和主主复制详解

    一.MySQL复制概述 ⑴.MySQL数据的复制的基本介绍 目前MySQL数据库已经占去数据库市场上很大的份额,其一是由于MySQL数据的开源性和高性能,当然还有重要的一条就是免费~不过不知道还能免费 ...

  3. MySQL数据的主从复制、半同步复制和主主复制详解-转

    一.MySQL复制概述 ⑴.MySQL数据的复制的基本介绍 目前MySQL数据库已经占去数据库市场上很大的份额,其一是由于MySQL数据的开源性和高性能,当然还有重要的一条就是免费~不过不知道还能免费 ...

  4. keepalived+mysql双主复制高可用方案

    MySQL双主复制,即互为Master-Slave(只有一个Master提供写操作),可以实现数据库服务器的热备,但是一个Master宕机后不能实现动态切换.而Keepalived通过虚拟IP,实现了 ...

  5. MySQL主从复制,主主复制,半同步复制

    实验环境: 系统:CentOS Linux release 7.4.1708 (Core) mariadb:mariadb-server-5.5.56-2.el7.x86_64 node1:172.1 ...

  6. mysql+mycat搭建稳定高可用集群,负载均衡,主备复制,读写分离

    数据库性能优化普遍采用集群方式,oracle集群软硬件投入昂贵,今天花了一天时间搭建基于mysql的集群环境. 主要思路 简单说,实现mysql主备复制-->利用mycat实现负载均衡. 比较了 ...

  7. mysql 主主复制(双主复制)+ 配置KEEPALIVED实现热备

    binlog-do-db和replicate-do-db表示需要同步的数据库 binlog-ignore-db和replicate-ignore-db表示不需要同步的数据库 云端服务器为master配 ...

  8. mysql主从复制 主主复制 读写分离

    首先是mysql的主从复制很简单 主主复制也就是互相主从最麻烦的最难的就是日志恢复,增量恢复什么的比较复杂 首先如果你不会安装mysql版本最好一样,或者往上的版本,因为mysql是向下兼容 请注意不 ...

  9. MYSQL的主从和主主复制模式

    一.复制介绍 MySQL支持单向.异步复制,复制过程中一个服务器充当主服务器,而一个或多个其它服务器充当从服务器.主服务器将更新写入二进制日志文件,并维护文件的一个索引以跟踪日志循环.这些日志可以记录 ...

随机推荐

  1. RxSwift基本使用(一)

    备注:本文参考自田腾飞博文 [RxSwift入坑解读-你所需要知道的各种概念] (http://www.codertian.com/2016/11/27/RxSwift-ru-keng-ji-read ...

  2. bzoj2253纸箱堆叠(动态规划+cdq分治套树状数组)

    Description P 工厂是一个生产纸箱的工厂.纸箱生产线在人工输入三个参数 n p a , 之后,即可自动化生产三边边长为 (a mod P,a^2 mod p,a^3 mod P) (a^4 ...

  3. Golden Tiger Claw UVA - 11383(km原理)

    这题使我对km多了一些看法 写给自己看.. km结束后bx[i] + by[j] == w[i][j], 所以所有bx与by的和即为w的和 而且记住bx[i] + by[j] >= w[i][j ...

  4. EVE-NG FAQ

    EVE-NG FAQ How to install EVE on bare box using Ubuntuoriginal ISO distro. Get Ubuntu ISO: https://w ...

  5. 具体数学斯特林数-----致敬Kunth

    注意这里讲的是斯特林数而非斯特林公式. 斯特林数分两类:第一类斯特林数 和 第二类斯特林数. 分别记为. 首先描述第二类斯特林数. 描述为:将一个有n件物品的集合划分成k个非空子集的方法数. 比如集合 ...

  6. Java 工作2年后需要达到怎么样的技术水平

    有人回答说这只能是大企业或者互联网企业的工程师才能拿到.也许是的,小公司或者非互联网企业拿两万的不太可能是码农了,应该是已经转管理后才有可能.还有区域问题,这个不在我的考虑范围内,因为除了北上广深杭, ...

  7. 【Treeview】遍历本地磁盘

    一.前言 Treeview控件常用于遍历本地文件信息,通常与Datagridview与ImageList搭配.ImageList控件用于提供小图片给TreeView控件,DatagridView通常显 ...

  8. Unity3D for VR 学习(6): 再次温故知新-3D数学

    一年前,系统学习过3D数学,并记录了一篇博客<C#程序员整理的Unity 3D笔记(十):Unity3D的位移.旋转的3D数学模型>. 一年后,再次温习之. 坐标系:Unity3D使用左手 ...

  9. 《Java程序设计》第8周学习总结 20165218 2017-2018-1

    20165218 2017-2018-1 <Java程序设计>第8周学习总结 教材学习内容总结 第12章 java多线程机制 java中的线程 计算机在任何给定时刻只能执行一个线程,多线程 ...

  10. 代码收藏系列--jquery--筛选器、事件绑定技巧

    Jquery筛选器的一些常用技巧,比如过滤属性等 /* 过滤获取没有含data-xsui-grid-colspan的节点 */$(this).find('.xsui-grid-cell:not([da ...