00:10:57] OK
db1 rep_threads [last change:2015/04/14 00:10:57] OK
db1 rep_backlog [last change: 2015/04/1400:10:57] OK: Backlog is null
?
[root@oraclem1 mysql-mmm]#
?
8.3 查看mmm_control日志
[root@oraclem1 mysql-mmm]# tail -f/var/log/mysql-mmm/mmm_mond.log
2015/04/14 00:55:29 FATAL Admin changedstate of 'db1' from AWAITING_RECOVERY to ONLINE
2015/04/14 00:55:29 INFO Orphaned role 'writer(192.168.52.120)'has been assigned to 'db1'
2015/04/14 00:55:29 INFO Orphaned role 'reader(192.168.52.131)'has been assigned to 'db1'
2015/04/14 00:55:29 INFO Orphaned role 'reader(192.168.52.129)'has been assigned to 'db1'
2015/04/14 00:55:29 INFO Orphaned role 'reader(192.168.52.128)'has been assigned to 'db1'
2015/04/14 00:58:15 FATAL Admin changedstate of 'db2' from AWAITING_RECOVERY to ONLINE
2015/04/14 00:58:15 INFO Moving role 'reader(192.168.52.131)'from host 'db1' to host 'db2'
2015/04/14 00:58:15 INFO Moving role 'reader(192.168.52.129)'from host 'db1' to host 'db2'
2015/04/14 00:58:18 FATAL Admin changedstate of 'db3' from AWAITING_RECOVERY to ONLINE
2015/04/14 00:58:18 INFO Moving role 'reader(192.168.52.131)'from host 'db2' to host 'db3'
?
8.4 mmm_control的命令
[root@oraclem1 ~]# mmm_control --help
Invalid command '--help'
Valid commands are:
help - show this message
ping - ping monitor
show - show status
checks [
|all [
|all]] - show checks status
set_online
- set host
online
set_offline
- set host
offline
mode - print current mode.
set_active - switch into active mode.
set_manual - switch into manual mode.
set_passive - switch into passive mode.
move_role [--force]
- move exclusive role
to host
(Only use --force if you know what you are doing!)
set_ip
- set role with ip
to host
[root@oraclem1 ~]#
?
?
9,测试切换操作
9.1 mmm切换原理
slave agent收到new master发送的set_active_master信息后如何进行切换主库
源码 Agent\Helpers\Actions.pm
set_active_master($new_master)
Try to catch up with the old master as faras possible and change the master to the new host.
(Syncs to the master log if the old masteris reachable. Otherwise syncs to the relay log.)
?
?
(1)、获取同步的binlog和position
先获取new master的show slavestatus中的 Master_Log_File、Read_Master_Log_Pos
wait_log=Master_Log_File, wait_pos=Read_Master_Log_Pos
?
如果old master可以连接,再获取oldmaster的show master status中的File、Position
wait_log=File, wait_pos=Position # 覆盖new master的slave信息,以old master 为准
?
(2)、slave追赶old master的同步位置
SELECT MASTER_POS_WAIT('wait_log', wait_pos);
?
#停止同步
STOP SLAVE;
?
(3)、设置new master信息
#此时 new master已经对外提供写操作。
#(在main线程里new master先接收到激活的消息,new master 转换(包含vip操作)完成后,然后由_distribute_roles将master变动同步到slave上)
#在new master转换完成后,如果能执行flush logs,更方便管理
#获取new master的binlog数据。
SHOW MASTER STATUS;
?
#从配置文件/etc/mysql-mmm/mmm_common.conf 读取同步帐户、密码
replication_user、replication_password
?
#设置新的同步位置
CHANGE MASTER TO MASTER_HOST='$new_peer_host',MASTER_PORT=$new_peer_port
,MASTER_USER='$repl_user', MASTER_PASSWORD='$repl_password'
,MASTER_LOG_FILE='$master_log', MASTER_LOG_POS=$master_pos;
?
#开启同步
START SLAVE;
?
9.2 停止db1,看write是否会自动切换到db2
(1)在db1上执行service mysqlstop;
[root@data01 ~]# service mysql stop;
Shutting down MySQL..... SUCCESS!
[root@data01 ~]#
?
(2)在monitor用mmm_control查看状态
[root@oraclem1 ~]# mmm_control show
db1(192.168.52.129) master