注意该脚本需要依赖于IO::Socket::INET Perl包,Perl v5.6.0中默认已经包括。而该脚本允许连接任何一个远程服务器,所以需要配置SSH public key。并且,该脚本尝试建立远程服务器到master的tcp连接,意味着如果tcp连接成功,则mysql配置文件中的max_connections设置不受影响,而aborts_connects的值会自动加1
master_ip_failover_script
HA方案中,很多情况下人们会在master上绑定一个虚拟IP。当master崩溃的时候,软件比如Keepalived会将虚拟IP重新指向正常的Server。
通用的方法就是创建一个全局的目录库,在库中存放着所有应用和IP地址之间的映射关系,用以取代VIP。在这种方案下,如果master崩溃,那么你就需要修改这个目录库。
都各有优缺点,MHA不会强制使用哪一种,允许用户使用任何的ip漂移技术。master_ip_failover_script 脚本能用于该目的。换句话说,你需要自己写脚本实现应用层连接到新的master,并且必须定义master_ip_failover_script 脚本参数,下面是使用范例
master_ip_failover_script= /usr/local/sample/bin/master_ip_failover
MHA Manager需要调用3次该脚本,第一次是在启动监控master之前(检查脚本是否可用),,第二次是在调用shutdown_script脚本之前,而第三次是在新的Master应用完所有的
relay logs之后。MHA Manager会传递如下参数(这些参数不需要你自己配置):
Checking phase --command=status --ssh_user=(current master's ssh username) --orig_master_host=(current master's hostname) --orig_master_ip=(current master's ip address) --orig_master_port=(current master's port number) Current master shutdown phase --command=stop or stopssh --ssh_user=(dead master's ssh username, if reachable via ssh) --orig_master_host=(current(dead) master's hostname) --orig_master_ip=(current(dead) master's ip address) --orig_master_port=(current(dead) master's port number) New master activation phase --command=start --ssh_user=(new master's ssh username) --orig_master_host=(dead master's hostname) --orig_master_ip=(dead master's ip address) --orig_master_port=(dead master's port number) --new_master_host=(new master's hostname) --new_master_ip=(new master's ip address) --new_master_port(new master's port number) --new_master_user=(new master's user) --new_master_password(new master's password)
如果你在master上使用了VIP,当master关闭阶段你可能不需要做任何事,只要你能够让VIP漂移到新的master。如果你使用的目录库方案,你可能需要删除或更新在master上的记录。在新的master激活阶段,你可以在新的master上插入/更新一条记录。并且,你可以做任何事使得应用层能够向新master中插入数据,比如设置read_only=0,创建用户的写权限等。
MHA manager会检查这个脚本返回的运行结果,如果返回0或10,则MHA manager继续运行。如果返回的不是0或10,mangaer就会终止。默认参数空置,所以MHA manager不会做任何事。
master_ip_online_change_script
这个和master_ip_failover_script参数相似,但它并不是用在master故障切换上,而是用在master在线手动切换命令上,传递参数过程如下
?
Current master write freezing phase --command=stop or stopssh --orig_master_host=(current master's hostname) --orig_master_ip=(current master's ip address) --orig_master_port=(current master's port number) --orig_master_user=(current master's user) --orig_master_password=(current master's password) --orig_master_ssh_user=(from 0.56, current master's ssh user) --orig_master_is_new_slave=(from 0.56, notifying whether the orig master will be new slave or not) New master granting write phase --command=start --orig_master_host=(orig master's hostname) --orig_master_ip=(orig master's ip address) --orig_master_port=(orig master's port number) --new_master_host=(new master's hostname) --new_master_ip=(new master's ip address) --new_master_port(new master's port number) --new_master_user=(new master's user) --new_master_password=(new master's password) --new_master_ssh_user=(from 0.56, new master's ssh user)
shutdown_script
你或许希望强制关闭master所在的服务器,这样就可以防止灾难扩散,以下是范例
shutdown_script= /usr/local/sample/bin/power_manager
MHA manager包中有一个范例脚本,在调用该命令前,MHA内部会检查master能否通过SSH连接。如果可连接