怎么选举出来一个新主
2017-01-21 23:05
204 查看
一主两从结构中,如果主库挂了,怎么选举出来一个新主
ip 192.168.0.110 3306(主)
ip 192.168.0.110 3307(从)
ip 192.168.0.110 3308(从)
模拟主库挂:
/usr/local/mysql/bin/mysqladmin -uroot -p -S /tmp/mysql3306.sock shutdown
查看状态
s1:show slave status\G;
s2:show slave status\G;
root@localhost [test]>show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Reconnecting after a failed master event read
Master_Host: 192.168.0.110
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 619
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 832
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Connecting
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: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 619
(1)首先s1和s2同步完成(Seconds_Behind_Master: NULL)
判断io_thread与sql_thread是否执行到同一个位置。
执行完成的依据为:
Master_Log_File == Relay_Master_Log_File &&
Read_Master_Log_Pos == Exec_Master_Log_Pos
io_thread:
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 619
sql_thread:
Relay_Master_Log_File: mysql-bin.000001
Exec_Master_Log_Pos: 619
假设Master_Log_File==Relay_Master_Log_File但是
io.Read_Master_Log_Pos >sql.Exec_Master_Log_Pos
说明了什么?
说明relay-log没有应用完。
Slave_SQL_Running: Yes 2-5秒
(2)s1和s2 怎么选举出来一个
谁同步靠前,谁当主。
(-)
s1.Relay_Master_Log_File == s2.Relay_Master_Log_File
s1.Exec_Master_Log_Pos == s2.Exec_Master_Log_Pos 选s1 或者s2都可以
如果s1.Relay_Master_Log_File == s2.Relay_Master_Log_File 但是
s1.Exec_Master_Log_Pos > s2.Exec_Master_Log_Pos 选s1为主
(二)
同样也可以比较
s1.Master_Log_File==s2.Master_Log_File
s1.Read_Master_Log_Pos==s2.Read_Master_Log_Pos
(3)数据有没有差异怎么办?
出现数据不一致:
1、s1-->读和写全部接管,s2作为故障的从,最后用pt-table-checksum/pt-table-sync修复,在加起来。
old_master上的日志有没有安全传到slave上面???? MHA可以解决。
(4)GTID环境里面比较下面即可。
Retrieved_Gtid_Set: 6e5d664c-c7e5-11e6-88b1-000c296ae445:3
Executed_Gtid_Set: 6e5d664c-c7e5-11e6-88b1-000c296ae445:1-3
如果s1.GTID>s2.GTID
选new master为s1;把s2 change 到s1
(5)原来主库怎么办?
变成从库加进去。
主从故障修复 主从一致性检测、修复。
ip 192.168.0.110 3306(主)
ip 192.168.0.110 3307(从)
ip 192.168.0.110 3308(从)
模拟主库挂:
/usr/local/mysql/bin/mysqladmin -uroot -p -S /tmp/mysql3306.sock shutdown
查看状态
s1:show slave status\G;
s2:show slave status\G;
root@localhost [test]>show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Reconnecting after a failed master event read
Master_Host: 192.168.0.110
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 619
Relay_Log_File: relay-bin.000002
Relay_Log_Pos: 832
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Connecting
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: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 619
(1)首先s1和s2同步完成(Seconds_Behind_Master: NULL)
判断io_thread与sql_thread是否执行到同一个位置。
执行完成的依据为:
Master_Log_File == Relay_Master_Log_File &&
Read_Master_Log_Pos == Exec_Master_Log_Pos
io_thread:
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 619
sql_thread:
Relay_Master_Log_File: mysql-bin.000001
Exec_Master_Log_Pos: 619
假设Master_Log_File==Relay_Master_Log_File但是
io.Read_Master_Log_Pos >sql.Exec_Master_Log_Pos
说明了什么?
说明relay-log没有应用完。
Slave_SQL_Running: Yes 2-5秒
(2)s1和s2 怎么选举出来一个
谁同步靠前,谁当主。
(-)
s1.Relay_Master_Log_File == s2.Relay_Master_Log_File
s1.Exec_Master_Log_Pos == s2.Exec_Master_Log_Pos 选s1 或者s2都可以
如果s1.Relay_Master_Log_File == s2.Relay_Master_Log_File 但是
s1.Exec_Master_Log_Pos > s2.Exec_Master_Log_Pos 选s1为主
(二)
同样也可以比较
s1.Master_Log_File==s2.Master_Log_File
s1.Read_Master_Log_Pos==s2.Read_Master_Log_Pos
(3)数据有没有差异怎么办?
出现数据不一致:
1、s1-->读和写全部接管,s2作为故障的从,最后用pt-table-checksum/pt-table-sync修复,在加起来。
old_master上的日志有没有安全传到slave上面???? MHA可以解决。
(4)GTID环境里面比较下面即可。
Retrieved_Gtid_Set: 6e5d664c-c7e5-11e6-88b1-000c296ae445:3
Executed_Gtid_Set: 6e5d664c-c7e5-11e6-88b1-000c296ae445:1-3
如果s1.GTID>s2.GTID
选new master为s1;把s2 change 到s1
(5)原来主库怎么办?
变成从库加进去。
主从故障修复 主从一致性检测、修复。
相关文章推荐
- 我一个图片怎么都显示不出来,是博客程序原因还是其他?
- 刚发现了一个问题,关于vs2005 datagridview的,我发现在设计行标头的HeaderCell.Value的时候要是设置RowTemplate.Height 的值>= 17则行标头的那个黑三角就显示出来了,要是小于17就不能显示了,想问问大家,是怎么回事?
- Android 一个窗口是怎么创建出来的?
- 怎么将两个表中树,拼成一个树(并创造一个顶级节点)还可以正常保存,下次修改的时候值还要正常的带出来?
- 怎么将两个表中树,拼成一个树(并创造一个顶级节点)还可以正常保存,下次修改的时候值还要正常的带出来?
- 怎么搞一个ORM出来用用呢???迷茫中
- 一个著名的日志系统是怎么设计出来的?
- iOS中model出来一个控制器的尺寸怎么设置?
- 怎么用一个程序向另一个程序发送字符并让其显示出来
- 一个项目怎么开发出来
- 一个项目的一个参数,如分页数,颜色等,不用Global 怎么可以只读一次数据库后所有的页面都可以用这次读出来的值呢
- 点一个Button让UIPickerView从下面弹出来是怎么做的?(UISheetView)
- 怎么让一个html文件在另一个html文件中适当的位置直接显示出来
- 怎么把两个布局加入到一个Activity里显示出来?
- 有8个一样的球,其中有一个要重一些。有一个天平,怎么称,才能2次就把重的球找出来?
- 对于一个表中字段保存的是代码,怎么用Struts+Hibernate将名称显示出来
- win7 用无线网络上网怎么共享一个无线出来
- select查询出来的某个值,怎么赋给一个变量呢?
- 哈哈,一个我怎么都没做出来的猜拳游戏,分享大神成果
- 网线从路由器接出来, 再接一个路由器怎么设置?