(2)授予远程用户权限 [billy@utils1 ~]$ mysql -h 127.0.0.1 -P3306 -u root -e "grant all on *.* to root@'%' with grant option;"
[billy@utils1 ~]$ mysql -h 127.0.0.1 -P3307 -u root -e "grant all on *.* to root@'%' with grant option;"
[billy@utils2 ~]$ mysql -h 127.0.0.1 -P3306 -u root -e "grant all on *.* to root@'%' with grant option;"
[billy@utils2 ~]$ mysql -h 127.0.0.1 -P3307 -u root -e "grant all on *.* to root@'%' with grant option;"
[billy@utils2 ~]$ mysql -h 127.0.0.1 -P3308 -u root -e "grant all on *.* to root@'%' with grant option;"
MySQL Replication Failover Utility
Failover Mode = auto Next Interval = Wed Aug 15 13:19:30 2012
Master Information
------------------
Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB
util11-bin.000001 2586
Replication Health Status
+---------+-------+---------+--------+------------+---------+
| host | port | role | state | gtid_mode | health |
+---------+-------+---------+--------+------------+---------+
| utils1 | 3306 | MASTER | UP | ON | OK |
| utils1 | 3307 | SLAVE | UP | ON | OK |
| utils2 | 3306 | SLAVE | UP | ON | OK |
| utils2 | 3307 | SLAVE | UP | ON | OK |
| utils2 | 3308 | SLAVE | UP | ON | OK |
+---------+-------+---------+--------+------------+---------+
Q-quit R-refresh H-health G-GTID Lists U-UUIDs
这里Failover Mode = auto 表示故障转移为自动,当master 出现故障的时候,就会从slave池中找到最为先进的slave作为master,当然你也可以根据实际情况绑定自己的故障转移脚本
然后刷新一下 MySQL Replication Failover Utility
Failover Mode = auto Next Interval = Wed Aug 15 13:21:13 2012
Master Information
------------------
Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB
util12-bin.000001 7131
Replication Health Status
+---------+-------+---------+--------+------------+---------+
| host | port | role | state | gtid_mode | health |
+---------+-------+---------+--------+------------+---------+
| utils1 | 3307 | MASTER | UP | ON | OK |
| utils2 | 3306 | SLAVE | UP | ON | OK |
| utils2 | 3307 | SLAVE | UP | ON | OK |
| utils2 | 3308 | SLAVE | UP | ON | OK |
+---------+-------+---------+--------+------------+---------+
Q-quit R-refresh H-health G-GTID Lists U-UUIDs
可以看到 utils1 的 3307 已经上升为master 了
(6)故障恢复 由于现在的master 是utils1:3307 ,所以utils1:3306需要从utils1:3307哪里更新数据 mysqlreplicate --master=root@utils1:3307 --slave=root@utils1:3306
# master on utils1: ... connected.
# slave on utils1: ... connected.
# Checking for binary logging on master...
# Setting up replication...
# ...done.
刷新看下 master-slave 状态 MySQL Replication Failover Utility
Failover Mode = auto Next Interval = Wed Aug 15 13:24:38 2012
Master Information
------------------
Binary Log File Position Binlog_Do_DB Binlog_Ignore_DB
util12-bin.000001 7131
Replication Health Status
+---------+-------+---------+--------+------------+---------+
| host | port | role | state | gtid_mode | health |
+---------+-------+---------+--------+------------+---------+
| utils1 | 3307 | MASTER | UP | ON | OK |
| utils1 | 3306 | SLAVE | UP | ON | OK |
| utils2 | 3306 | SLAVE | UP | ON | OK |
| utils2 | 3307 | SLAVE | UP | ON | OK |
| utils2 | 3308 | SLAVE | UP | ON | OK |
+---------+-------+---------+--------+------------+---------+
# Discovering slaves for master at utils1:3307
# Checking privileges.
# Performing switchover from master at utils1:3307 to slave at utils1:3306.
# Checking candidate slave prerequisites.
# Waiting for slaves to catch up to old master.
# Stopping slaves.
# Performing STOP on all slaves.
# Demoting old master to be a slave to the new master.
# Switching slaves to new master.
# Starting all slaves.
# Performing START on all slaves.
# Checking slaves for errors.
# Switchover complete.
#
# Replication Topology Health:
+---------+-------+---------+--------+------------+---------+
| host | port | role | state | gtid_mode | health |
+---------+-------+---------+--------+------------+---------+
| utils1 | 3306 | MASTER | UP | ON | OK |
| utils1 | 3307 | SLAVE | UP | ON | OK |
| utils2 | 3306 | SLAVE | UP | ON | OK |
| utils2 | 3307 | SLAVE | UP | ON | OK |
| utils2 | 3308 | SLAVE | UP | ON | OK |
+---------+-------+---------+--------+------------+---------+
# ...done.