mha的manager 结点依赖与mha-node软件包、所以在安装mha-manager之前要把mha-node安装上去;再者mha-manger还依赖于perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes
【1】安装perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes
yum -y install perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes
【2】编译安装mha-manager
unzip mha4mysql-manager-master.zip cd mha4mysql-manager-master perl Makefile.PL make make install
【3】mha-manger 安装包下面samples/scripts/目录下有几个脚本文件,如果用这些工具的话可以用cp * /usr/local/bin/
cd /samples/scripts
cp * /usr/local/bin/
【4】创建mha-manger的工作目录
mkdir /var/log/masterha touch /var/log/masterha/app.cnf # 配置文件
【5】配置mha-manger
[server default] manager_workdir=/var/log/masterha/ manager_log=/var/log/masterha/manager.log remote_workdir=/tmp master_binlog_dir=/usr/local/mysql/data/ master_ip_failover_script=/usr/local/bin/master_ip_failover master_ip_online_change_script= /usr/local/bin/master_ip_online_change report_script=/usr/local/bin/send_report shutdown_script="" ping_interval=1 user=mha password=123456 repl_user=repl repl_password=123456 ssh_user=root [server1] hostname=192.168.80.130 port=3306 candidate_master=1 check_repl_delay=0 [server2] hostname=192.168.80.131 port=3306 candidate_master=1 check_repl_delay=0 [server3] hostname=192.168.80.132 port=3306
【6】根据自己的环境修复master_ip_failover;我这里的如下
#!/usr/bin/env perl use strict; use warnings FATAL => 'all'; use Getopt::Long; my ( $command, $ssh_user, $orig_master_host, $orig_master_ip, $orig_master_port, $new_master_host, $new_master_ip, $new_master_port ); my $vip = '192.168.80.100/24'; my $key = '0'; my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip"; my $ssh_stop_vip = "/sbin/ifconfig eth0:$key down"; GetOptions( 'command=s' => $command, 'ssh_user=s' => $ssh_user, 'orig_master_host=s' => $orig_master_host, 'orig_master_ip=s' => $orig_master_ip, 'orig_master_port=i' => $orig_master_port, 'new_master_host=s' => $new_master_host, 'new_master_ip=s' => $new_master_ip, 'new_master_port=i' => $new_master_port, ); exit &main(); sub main { print " IN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip=== "; if ( $command eq "stop" || $command eq "stopssh" ) { my $exit_code = 1; eval { print "Disabling the VIP on old master: $orig_master_host "; &stop_vip(); $exit_code = 0; }; if ($@) { warn "Got Error: $@ "; exit $exit_code; } exit $exit_code; } elsif ( $command eq "start" ) { my $exit_code = 10; eval { print "Enabling the VIP - $vip on the new master - $new_master_host "; &start_vip(); $exit_code = 0; }; if ($@) { warn $@; exit $exit_code; } exit $exit_code; } elsif ( $command eq "status" ) { print "Checking the Status of the script.. OK "; exit 0; } else { &usage(); exit 1; } } sub start_vip() { `ssh $ssh_user@$new_master_host " $ssh_start_vip "`; } sub stop_vip() { return 0 unless ($ssh_user); `ssh $ssh_user@$orig_master_host " $ssh_stop_vip "`; } sub usage { print "Usage: master_ip_failover --command=start|stop|stopssh|status --orig_master_host=host --orig_master_ip=ip --orig_master_port=port --new_master_host=host --new_master_ip=ip --new_master_port=port "; }
只要改一下vip 和ifconfig 和相关网卡信息就行了