MySQL 故障迁移_MySQL管理工具MySQL Utilities — 自动故障转移(49)

在生产环境中,我们时常要考虑到高可用性的问题,MySQL复制是脆弱的,诸多原因会导致复制停止。有多种方案来解决MySQL高可用性问题,如DRBD、MMM等等。监视复制拓扑,在故障发生时,自动进行切换,最大限度的减少停机时间保持复制运行。

mysqlfailover工具来监视复制拓扑并在需要时自动执行故障转移。当当前的主出现故障时,人工切换主是非常繁琐和容易出现问题的,需要将所有的从指向新的主,确保不丢失任何事务。mysqlfailover 工具能够自动的执行这一全过程。

假设有5台服务器,主server1:3311,从分别是server2:3312, server3:3313, server4:3314, server:3315。

实例

启动mysqlfailover工具

shell> mysqlfailover --master=root@server1:3311 \

--slaves=root@server2:3312,root@server3:3313,root@server4:3314,root@server5:3315 \

--log=log.txt --rpl-user=rpl:rpl

NOTE: Log file 'log.txt' does not exist. Will be created.

# Checking privileges.

MySQL Replication Failover Utility

Failover Mode = auto Next Interval = Fri Jul 26 10:17:52 2013

Master Information

------------------

Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB

master-bin.000001 151

GTID Executed Set

None

Replication Health Status

+----------+-------+---------+--------+------------+---------+

| host | port | role | state | gtid_mode | health |

+----------+-------+---------+--------+------------+---------+

| server1 | 3311 | MASTER | UP | ON | OK |

| server2 | 3312 | SLAVE | UP | ON | OK |

| server3 | 3313 | SLAVE | UP | ON | OK |

| server4 | 3314 | SLAVE | UP | ON | OK |

| server5 | 3315 | SLAVE | UP | ON | OK |

+----------+-------+---------+--------+------------+---------+

Q-quit R-refresh H-health G-GTID Lists U-UUIDs L-log entries

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

shell>mysqlfailover--master=root@server1:3311\

--slaves=root@server2:3312,root@server3:3313,root@server4:3314,root@server5:3315\

--log=log.txt--rpl-user=rpl:rpl

NOTE:Logfile'log.txt'doesnotexist.Willbecreated.

# Checking privileges.

MySQLReplicationFailoverUtility

FailoverMode=autoNextInterval=FriJul2610:17:522013

MasterInformation

------------------

BinaryLogFilePositionBinlog_Do_DBBinlog_Ignore_DB

master-bin.000001151

GTIDExecutedSet

None

ReplicationHealthStatus

+----------+-------+---------+--------+------------+---------+

|host|port|role|state|gtid_mode|health|

+----------+-------+---------+--------+------------+---------+

|server1|3311|MASTER|UP|ON|OK|

|server2|3312|SLAVE|UP|ON|OK|

|server3|3313|SLAVE|UP|ON|OK|

|server4|3314|SLAVE|UP|ON|OK|

|server5|3315|SLAVE|UP|ON|OK|

+----------+-------+---------+--------+------------+---------+

Q-quitR-refreshH-healthG-GTIDListsU-UUIDsL-logentries

主崩溃无法访问,然后在预定的时间间隔后(默认15秒),故障转移将会自动启动

Failover starting in 'auto' mode...

# Candidate slave server2:3312 will become the new master.

# Checking slaves status (before failover).

# Preparing candidate for failover.

# Creating replication user if it does not exist.

# Stopping slaves.

# Performing STOP on all slaves.

# Switching slaves to new master.

# Disconnecting new master as slave.

# Starting slaves.

# Performing START on all slaves.

# Checking slaves for errors.

# Failover complete.

Failover console will restart in 5 seconds.

[...]

MySQL Replication Failover Utility

Failover Mode = auto Next Interval = Fri Jul 26 10:25:17 2013

Master Information

------------------

Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB

master-bin.000001 151

GTID Executed Set

None

Replication Health Status

+----------+-------+---------+--------+------------+---------+

| host | port | role | state | gtid_mode | health |

+----------+-------+---------+--------+------------+---------+

| server2 | 3312 | MASTER | UP | ON | OK |

| server3 | 3313 | SLAVE | UP | ON | OK |

| server4 | 3314 | SLAVE | UP | ON | OK |

| server5 | 3315 | SLAVE | UP | ON | OK |

+----------+-------+---------+--------+------------+---------+

Q-quit R-refresh H-health G-GTID Lists U-UUIDs L-log entries

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

Failoverstartingin'auto'mode...

# Candidate slave server2:3312 will become the new master.

# Checking slaves status (before failover).

# Preparing candidate for failover.

# Creating replication user if it does not exist.

# Stopping slaves.

# Performing STOP on all slaves.

# Switching slaves to new master.

# Disconnecting new master as slave.

# Starting slaves.

# Performing START on all slaves.

# Checking slaves for errors.

# Failover complete.

Failoverconsolewillrestartin5seconds.

[...]

MySQLReplicationFailoverUtility

FailoverMode=autoNextInterval=FriJul2610:25:172013

MasterInformation

------------------

BinaryLogFilePositionBinlog_Do_DBBinlog_Ignore_DB

master-bin.000001151

GTIDExecutedSet

None

ReplicationHealthStatus

+----------+-------+---------+--------+------------+---------+

|host|port|role|state|gtid_mode|health|

+----------+-------+---------+--------+------------+---------+

|server2|3312|MASTER|UP|ON|OK|

|server3|3313|SLAVE|UP|ON|OK|

|server4|3314|SLAVE|UP|ON|OK|

|server5|3315|SLAVE|UP|ON|OK|

+----------+-------+---------+--------+------------+---------+

Q-quitR-refreshH-healthG-GTIDListsU-UUIDsL-logentries

上面的例子说明如何启动mysqlfailover ,检查复制拓扑的健康和故障转移发生时的输出信息。

权限

用户必须要有配置复制的权限。

小技巧

上面的例子是在控制台模式下运行的,可以放在后台,在启动时加上--daemon=start选项。还可以指定--log选项,将日志输出到日志文件中。

还可以指定外部脚本。--exec-fail-check 指定外部检查脚本用于替换默认的检查(主可达并且存活)。--exec-before 指定在故障切换前执行的脚本。--exec-after 在故障切换后执行的脚本。--exec-post-failover在故障转移过程完成后(显示健康报告前)执行的脚本。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值