为了实现MySQL数据库的高可用性,我使用的是mysqlfailover实用程序。我跑步的时候一切都运转正常
mysqlfailover --master=root:pass@master-host:3306 --slaves=root:pass@slave-host:3306 --rpl-user=slave-user:slave-pass --log=log.txt --force --daemon=start
它产生以下输出
2017-05-15 12:41:06 PM INFO Server 'master-host:3306' is using MySQL version 5.6.36-log.
2017-05-15 12:41:06 PM INFO Server 'slave-host:3306' is using MySQL version 5.6.36-log.
2017-05-15 12:41:06 PM INFO Unregistering instance on master.
2017-05-15 12:41:06 PM INFO Checking privileges.
2017-05-15 12:41:06 PM INFO Unregistering existing instances from slaves.
2017-05-15 12:41:06 PM INFO Registering instance on master.
2017-05-15 12:41:06 PM INFO Failover daemon started.
2017-05-15 12:41:06 PM INFO Failover mode = auto.
2017-05-15 12:41:09 PM INFO Master Information
2017-05-15 12:41:09 PM INFO Binary Log File: mysql-bin.000020, Position: 191, Binlog_Do_DB: N/A, Binlog_Ignore_DB: N/A
2017-05-15 12:41:09 PM INFO GTID Executed Set: 952b004a-3567-11e7-b46e-0a767d02b017:1-10
2017-05-15 12:41:09 PM INFO Getting health for master: master-host:3306.
2017-05-15 12:41:09 PM INFO Health Status:
2017-05-15 12:41:09 PM INFO host: master-host, port: 3306, role: MASTER, state: UP, gtid_mode: ON, health: OK
2017-05-15 12:41:09 PM INFO host: slave-host, port: 3306, role: SLAVE, state: UP, gtid_mode: ON, health: OK
当我停止掌握MySQL守护进程时,输出为
2017-05-15 12:40:01 PM INFO Master may be down. Waiting for 3 seconds.
2017-05-15 12:40:16 PM INFO Failed to reconnect to the master after 3 attemps.
2017-05-15 12:40:16 PM CRITICAL Master is confirmed to be down or unreachable.
2017-05-15 12:40:16 PM INFO Failover starting in 'auto' mode...
2017-05-15 12:40:16 PM INFO Candidate slave slave-host:3306 will become the new master.
2017-05-15 12:40:16 PM INFO Checking slaves status (before failover).
2017-05-15 12:40:16 PM INFO Preparing candidate for failover.
2017-05-15 12:40:16 PM INFO Creating replication user if it does not exist.
2017-05-15 12:40:16 PM INFO Stopping slaves.
2017-05-15 12:40:16 PM INFO Performing STOP on all slaves.
2017-05-15 12:40:16 PM INFO Switching slaves to new master.
2017-05-15 12:40:16 PM INFO Disconnecting new master as slave.
2017-05-15 12:40:16 PM INFO Starting slaves.
2017-05-15 12:40:16 PM INFO Performing START on all slaves.
2017-05-15 12:40:16 PM INFO Checking slaves for errors.
2017-05-15 12:40:16 PM INFO Failover complete.
2017-05-15 12:40:21 PM INFO Unregistering existing instances from slaves.
2017-05-15 12:40:21 PM INFO Registering instance on new master slave-host:3306.
2017-05-15 12:40:22 PM INFO Master Information
2017-05-15 12:40:22 PM INFO Binary Log File: mysql-bin.000003, Position: 191, Binlog_Do_DB: N/A, Binlog_Ignore_DB: N/A
2017-05-15 12:40:22 PM INFO GTID Executed Set: 952b004a-3567-11e7-b46e-0a767d02b017:1-10
2017-05-15 12:40:22 PM INFO Getting health for master: slave-host:3306.
2017-05-15 12:40:22 PM INFO Health Status:
2017-05-15 12:40:22 PM INFO host: slave-host, port: 3306, role: MASTER, state: UP, gtid_mode: ON, health: OK
但是我想在执行切换或故障转移后执行脚本。虽然脚本的目的与我的应用程序的数据库连接有关,但目前我正在运行带有以下内容的示例脚本 exec.sh
#!/bin/bash
echo "creating a new file after failover"
touch troubleshoot.txt
exit 0
现在我正在运行命令
mysqlfailover --master=root:pass@master-host:3306 --slaves=root:pass@slave-host:3306 --rpl-user=slave-user:slave-pass --log=log.txt --force --daemon=start --exec-after="./exec.sh"
停止在取消注册主控上的实例,输出为
2017-05-15 13:04:42 PM INFO Master may be down. Waiting for 3 seconds.
2017-05-15 13:04:57 PM INFO Failed to reconnect to the master after 3 attemps.
2017-05-15 13:04:57 PM CRITICAL Master is confirmed to be down or unreachable.
2017-05-15 13:04:57 PM INFO Failover starting in 'auto' mode...
2017-05-15 13:04:57 PM INFO Candidate slave slave-host:3306 will become the new master.
2017-05-15 13:04:57 PM INFO Checking slaves status (before failover).
2017-05-15 13:04:57 PM INFO Preparing candidate for failover.
2017-05-15 13:04:57 PM INFO Creating replication user if it does not exist.
2017-05-15 13:04:57 PM INFO Spawning external script.
2017-05-15 13:04:57 PM INFO Unregistering instance on master
虽然输出显示"产生外部脚本"但是这一步之后什么也没发生我还检查了脚本是否具有足够的执行权限以及最后的0退出状态。请帮助我找出阻止进一步执行的问题。
答案 0 :(得分:1)
确保提供脚本的完整路径,而不是相对路径。
mysqlfailover --master=root:pass@master-host:3306 --slaves=root:pass@slave-host:3306 --rpl-user=slave-user:slave-pass --log=log.txt --force --daemon=start --exec-after="/full/path/to/exec.sh"