您的位置:首页 > 其它

怎么选举出来一个新主

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)原来主库怎么办?
变成从库加进去。
主从故障修复 主从一致性检测、修复。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  怎么 选举 出来
相关文章推荐