1、关闭主从库relay_log_purge
mysql> set global relay_log_purge=0;
2、切换脚本
[root@localhost ~]# cat /mha-manager/bin/master_ip_failover
#!/usr/bin/env perl # Copyright (C) 2011 DeNA Co.,Ltd. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ## Note: This is a sample script and is not complete. Modify the script based on your environment. use strict; use warnings FATAL => 'all'; use Getopt::Long; use MHA::DBHelper; my ( $command, $ssh_user, $orig_master_host, $orig_master_ip, $orig_master_port, $new_master_host, $new_master_ip, $new_master_port, $new_master_user, $new_master_password ); my $vip = '172.16.107.30/24'; my $key = '88'; 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, 'new_master_user=s' => \$new_master_user, 'new_master_password=s' => \$new_master_password, ); exit &main(); sub main { print "\n\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\n\n"; if ( $command eq "stop" || $command eq "stopssh" ) { my $exit_code = 1; eval { print "Disabling the VIP on old master: $orig_master_host \n"; &stop_vip(); $exit_code = 0; }; if ($@) { warn "Got Error: $@\n"; 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 \n"; &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 \n"; 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\n"; }
按需修改:my $vip = '172.16.107.30/24'
陪完脚本后配置VIP
ifconfig eth0:88 172.16.107.30/24 ifconfig eth0:88 down
3、修改默认设置[root@localhost ~]# cat /etc/masterha_default.cnf
[server default] user=root password=123456 ssh_user=root repl_user=slave repl_password= 123456 ping_interval=1
4、数据库集群切换配置[root@localhost ~]# cat /mha-manager/etc/app1.cnf
[server default] manager_log=/mha-manager/log/manager.log manager_workdir=/mha-manager/app1 master_ip_failover_script=/mha-manager/bin/master_ip_failover [serverr1] candidate_master=1 check_repl_delay=0 hostname=172.16.107.18 master_binlog_dir=/var/lib/mysql/ port=3306 [server2] candidate_master=1 check_repl_delay=0 hostname=172.16.107.16 master_binlog_dir=/var/lib/mysql/ port=3306 [server3] hostname=172.16.107.20 master_binlog_dir=/var/lib/mysql/ port=3306
5、检查ssh免密登录是否正常,检查主从复制是否正常
1)masterha_check_ssh --conf=/mha-manager/etc/app1.cnf
2)masterha_check_repl --conf=/mha-manager/etc/app1.cnf
6、后台运行masterha_manager,然后检查masterha_manager是否正常
1)nohup masterha_manager --conf=/mha-manager/etc/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /mha-manager/log/manager.log 2>&1 &
2)masterha_check_status --conf=/mha-manager/etc/app1.cnf
7、手动切换(需要关闭masterha_manager)
masterha_master_switch --conf=/mha-manager/etc/app1.cnf --master_state=alive --new_master_host=172.16.107.18 --new_master_port=3306 --orig_master_is_new_slave --running_updates_limit=100
标签:--,配置,mha,manager,exit,master,ssh,new From: https://www.cnblogs.com/xue0123/p/17916730.html