站长网 MySql教程 MySQL5.7怎么达成一主两从MHA在线手动平滑切换

MySQL5.7怎么达成一主两从MHA在线手动平滑切换

这篇文章主要介绍MySQL5.7怎么实现一主两从MHA在线手动平滑切换,在日常操作中,相信很多人在MySQL5.7怎么实现一主两从MHA在线手动平滑切换问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答MySQL5.7怎么实现一主两从MHA在线

这篇文章主要介绍“MySQL5.7怎么实现一主两从MHA在线手动平滑切换”,在日常操作中,相信很多人在MySQL5.7怎么实现一主两从MHA在线手动平滑切换问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”MySQL5.7怎么实现一主两从MHA在线手动平滑切换”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
 
一、修改master_ip_online_change内容
 
#!/usr/bin/env perl
#  Copyright (C) 2011 DeNA Co.,Ltd.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  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
use strict;
use warnings FATAL => 'all';
use Getopt::Long qw(:config pass_through);
use Pod::Usage;
use MHA::MasterMonitor;
use MHA::MasterFailover;
use MHA::MasterRotate;
use MHA::ManagerConst;
my $master_state = "";
my $help;
my $version;
$| = 1;
GetOptions(
  'help'           => \$help,
  'version'        => \$version,
  'master_state=s' => \$master_state
);
my $exit_code = 1;
if ($version) {
  print "masterha_master_switch version $MHA::ManagerConst::VERSION.\n";
  exit 0;
}
if ($help) {
  pod2usage(0);
}
if ( $master_state eq "dead" ) {
  $exit_code = MHA::MasterFailover::main(@ARGV);
}
elsif ( $master_state eq "alive" ) {
  $exit_code = MHA::MasterRotate::main(@ARGV);
}
else {
  pod2usage(1);
}
exit $exit_code;
# ############################################################################
# Documentation
# ############################################################################
=pod
=head1 NAME
masterha_master_switch – Switching MySQL master server to one of other slave servers
=head1 SYNOPSIS
# For master failover
masterha_master_switch –master_state=dead –global_conf=/etc/masterha_default.cnf –conf=/usr/local/masterha/conf/app1.cnf –dead_master_host=host1
# For online master switch
masterha_master_switch –master_state=alive –global_conf=/etc/masterha_default.cnf –conf=/usr/local/masterha/conf/app1.cnf
See online reference (http://code.google.com/p/mysql-master-ha/wiki/masterha_master_switch) for details.
=head1 DESCRIPTION
See online reference (http://code.google.com/p/mysql-master-ha/wiki/masterha_master_switch) for details.
[root@manager MHA]#
[root@manager MHA]#
[root@manager MHA]# cat /usr/local/bin/master_ip_online_change
#!/usr/bin/env perl
#  Copyright (C) 2011 DeNA Co.,Ltd.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  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;
use MHA::NodeUtil;
use Time::HiRes qw( sleep gettimeofday tv_interval );
use Data::Dumper;
my $_tstart;
my $_running_interval = 0.1;
my (
  $command,              $orig_master_is_new_slave, $orig_master_host,
  $orig_master_ip,       $orig_master_port,         $orig_master_user,
  $orig_master_password, $orig_master_ssh_user,     $new_master_host,
  $new_master_ip,        $new_master_port,          $new_master_user,
  $new_master_password,  $new_master_ssh_user,
);
GetOptions(
  'command=s'                => \$command,
  'orig_master_is_new_slave' => \$orig_master_is_new_slave,
  'orig_master_host=s'       => \$orig_master_host,
  'orig_master_ip=s'         => \$orig_master_ip,
  'orig_master_port=i'       => \$orig_master_port,
  'orig_master_user=s'       => \$orig_master_user,
  'orig_master_password=s'   => \$orig_master_password,
  'orig_master_ssh_user=s'   => \$orig_master_ssh_user,
  '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,
  'new_master_ssh_user=s'    => \$new_master_ssh_user,
);
exit &main();
sub current_time_us {
  my ( $sec, $microsec ) = gettimeofday();
  my $curdate = localtime($sec);
  return $curdate . " " . sprintf( "%06d", $microsec );
}
sub sleep_until {
  my $elapsed = tv_interval($_tstart);
  if ( $_running_interval > $elapsed ) {
    sleep( $_running_interval – $elapsed );
  }
}
sub get_threads_util {
  my $dbh                    = shift;
  my $my_connection_id       = shift;
  my $running_time_threshold = shift;
  my $type                   = shift;
  $running_time_threshold = 0 unless ($running_time_threshold);
  $type                   = 0 unless ($type);
  my @threads;
  my $sth = $dbh->prepare("SHOW PROCESSLIST");
  $sth->execute();
  while ( my $ref = $sth->fetchrow_hashref() ) {
    my $id         = $ref->{Id};
    my $user       = $ref->{User};
    my $host       = $ref->{Host};
    my $command    = $ref->{Command};
    my $state      = $ref->{State};
    my $query_time = $ref->{Time};
    my $info       = $ref->{Info};
    $info =~ s/^\s*(.*?)\s*$/$1/ if defined($info);
    next if ( $my_connection_id == $id );
    next if ( defined($query_time) && $query_time < $running_time_threshold );
    next if ( defined($command)    && $command eq "Binlog Dump" );
    next if ( defined($user)       && $user eq "system user" );
    next
      if ( defined($command)
      && $command eq "Sleep"
      && defined($query_time)
      && $query_time >= 1 );
    if ( $type >= 1 ) {
      next if ( defined($command) && $command eq "Sleep" );
      next if ( defined($command) && $command eq "Connect" );
    }
    if ( $type >= 2 ) {
      next if ( defined($info) && $info =~ m/^select/i );
      next if ( defined($info) && $info =~ m/^show/i );
    }
    push @threads, $ref;
  }
  return @threads;
}
sub main {
  if ( $command eq "stop" ) {
    ## Gracefully killing connections on the current master
    # 1. Set read_only= 1 on the new master
    # 2. DROP USER so that no app user can establish new connections
    # 3. Set read_only= 1 on the current master
    # 4. Kill current queries
    # * Any database access failure will result in script die.
    my $exit_code = 1;
    eval {
      ## Setting read_only=1 on the new master (to avoid accident)
      my $new_master_handler = new MHA::DBHelper();
      # args: hostname, port, user, password, raise_error(die_on_error)_or_not
      $new_master_handler->connect( $new_master_ip, $new_master_port,
        $new_master_user, $new_master_password, 1 );
      print current_time_us() . " Set read_only on the new master.. ";
      $new_master_handler->enable_read_only();
      if ( $new_master_handler->is_read_only() ) {
        print "ok.\n";
      }
      else {
        die "Failed!\n";
      }
      $new_master_handler->disconnect();
      # Connecting to the orig master, die if any database error happens
      my $orig_master_handler = new MHA::DBHelper();
      $orig_master_handler->connect( $orig_master_ip, $orig_master_port,
        $orig_master_user, $orig_master_password, 1 );
      ## Drop application user so that nobody can connect. Disabling per-session binlog beforehand
      $orig_master_handler->disable_log_bin_local();
      print current_time_us() . " Drpping app user on the orig master..\n";
      #FIXME_xxx_drop_app_user($orig_master_handler);
      ## Waiting for N * 100 milliseconds so that current connections can exit
      my $time_until_read_only = 15;
      $_tstart = [gettimeofday];
      my @threads = get_threads_util( $orig_master_handler->{dbh},
        $orig_master_handler->{connection_id} );
      while ( $time_until_read_only > 0 && $#threads >= 0 ) {
        if ( $time_until_read_only % 5 == 0 ) {
          printf
"%s Waiting all running %d threads are disconnected.. (max %d milliseconds)\n",
            current_time_us(), $#threads + 1, $time_until_read_only * 100;
          if ( $#threads < 5 ) {
            print Data::Dumper->new( [$_] )->Indent(0)->Terse(1)->Dump . "\n"
              foreach (@threads);
          }
        }
        sleep_until();
        $_tstart = [gettimeofday];
        $time_until_read_only–;
        @threads = get_threads_util( $orig_master_handler->{dbh},
          $orig_master_handler->{connection_id} );
      }
      ## Setting read_only=1 on the current master so that nobody(except SUPER) can write
      print current_time_us() . " Set read_only=1 on the orig master.. ";
      $orig_master_handler->enable_read_only();
      if ( $orig_master_handler->is_read_only() ) {
        print "ok.\n";
      }
      else {
        die "Failed!\n";
      }
      ## Waiting for M * 100 milliseconds so that current update queries can complete
      my $time_until_kill_threads = 5;
      @threads = get_threads_util( $orig_master_handler->{dbh},
        $orig_master_handler->{connection_id} );
      while ( $time_until_kill_threads > 0 && $#threads >= 0 ) {
        if ( $time_until_kill_threads % 5 == 0 ) {
          printf
"%s Waiting all running %d queries are disconnected.. (max %d milliseconds)\n",
            current_time_us(), $#threads + 1, $time_until_kill_threads * 100;
          if ( $#threads < 5 ) {
            print Data::Dumper->new( [$_] )->Indent(0)->Terse(1)->Dump . "\n"
              foreach (@threads);
          }
        }
        sleep_until();
        $_tstart = [gettimeofday];
        $time_until_kill_threads–;
        @threads = get_threads_util( $orig_master_handler->{dbh},
          $orig_master_handler->{connection_id} );
      }
      ## Terminating all threads
      print current_time_us() . " Killing all application threads..\n";
      $orig_master_handler->kill_threads(@threads) if ( $#threads >= 0 );
      print current_time_us() . " done.\n";
      $orig_master_handler->enable_log_bin_local();
      $orig_master_handler->disconnect();
      ## After finishing the script, MHA executes FLUSH TABLES WITH READ LOCK
      $exit_code = 0;
    };
    if ($@) {
      warn "Got Error: $@\n";
      exit $exit_code;
    }
    exit $exit_code;
  }
  elsif ( $command eq "start" ) {
    ## Activating master ip on the new master
    # 1. Create app user with write privileges
    # 2. Moving backup script if needed
    # 3. Register new master's ip to the catalog database
# We don't return error even though activating updatable accounts/ip failed so that we don't interrupt slaves' recovery.
# If exit code is 0 or 10, MHA does not abort
    my $exit_code = 10;
    eval {
      my $new_master_handler = new MHA::DBHelper();
      # args: hostname, port, user, password, raise_error_or_not
      $new_master_handler->connect( $new_master_ip, $new_master_port,
        $new_master_user, $new_master_password, 1 );
      ## Set read_only=0 on the new master
      $new_master_handler->disable_log_bin_local();
      print current_time_us() . " Set read_only=0 on the new master.\n";
      $new_master_handler->disable_read_only();
      ## Creating an app user on the new master
      print current_time_us() . " Creating app user on the new master..\n";
      FIXME_xxx_create_app_user($new_master_handler);
      $new_master_handler->enable_log_bin_local();
      $new_master_handler->disconnect();
      ## Update master ip on the catalog database, etc
      $exit_code = 0;
    };
    if ($@) {
      warn "Got Error: $@\n";
      exit $exit_code;
    }
    exit $exit_code;
  }
  elsif ( $command eq "status" ) {
    # do nothing
    exit 0;
  }
  else {
    &usage();
    exit 1;
  }
}
sub usage {
  print
"Usage: master_ip_online_change –command=start|stop|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";
  die;
}
二、停止MHA监控程序
 
masterha_stop –conf=/etc/masterha/app1.cnf
三、进行平滑切换
 
masterha_master_switch –conf=/etc/masterha/app1.cnf –master_state=alive –new_master_host=192.168.8.57 –new_master_port=3306 –orig_master_is_new_slave –running_updates_limit=10000
Fri Oct 26 14:17:08 2018 – [info] MHA::MasterRotate version 0.58.
Fri Oct 26 14:17:08 2018 – [info] Starting online master switch..
Fri Oct 26 14:17:08 2018 – [info]
Fri Oct 26 14:17:08 2018 – [info] * Phase 1: Configuration Check Phase..
Fri Oct 26 14:17:08 2018 – [info]
Fri Oct 26 14:17:08 2018 – [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Fri Oct 26 14:17:08 2018 – [info] Reading application default configuration from /etc/masterha/app1.cnf..
Fri Oct 26 14:17:08 2018 – [info] Reading server configuration from /etc/masterha/app1.cnf..
Fri Oct 26 14:17:09 2018 – [info] GTID failover mode = 1
Fri Oct 26 14:17:09 2018 – [info] Current Alive Master: 192.168.8.58(192.168.8.58:3306)
Fri Oct 26 14:17:09 2018 – [info] Alive Slaves:
Fri Oct 26 14:17:09 2018 – [info]   192.168.8.57(192.168.8.57:3306)  Version=5.7.23-log (oldest major version between slaves) log-bin:enabled
Fri Oct 26 14:17:09 2018 – [info]     GTID ON
Fri Oct 26 14:17:09 2018 – [info]     Replicating from 192.168.8.58(192.168.8.58:3306)
Fri Oct 26 14:17:09 2018 – [info]     Primary candidate for the new Master (candidate_master is set)
Fri Oct 26 14:17:09 2018 – [info]   192.168.8.59(192.168.8.59:3306)  Version=5.7.23-log (oldest major version between slaves) log-bin:enabled
Fri Oct 26 14:17:09 2018 – [info]     GTID ON
Fri Oct 26 14:17:09 2018 – [info]     Replicating from 192.168.8.58(192.168.8.58:3306)
It is better to execute FLUSH NO_WRITE_TO_BINLOG TABLES on the master before switching. Is it ok to execute on 192.168.8.58(192.168.8.58:3306)? (YES/no): yes
Fri Oct 26 14:17:12 2018 – [info] Executing FLUSH NO_WRITE_TO_BINLOG TABLES. This may take long time..
Fri Oct 26 14:17:12 2018 – [info]  ok.
Fri Oct 26 14:17:12 2018 – [info] Checking MHA is not monitoring or doing failover..
Fri Oct 26 14:17:12 2018 – [info] Checking replication health on 192.168.8.57..
Fri Oct 26 14:17:12 2018 – [info]  ok.
Fri Oct 26 14:17:12 2018 – [info] Checking replication health on 192.168.8.59..
Fri Oct 26 14:17:12 2018 – [info]  ok.
Fri Oct 26 14:17:12 2018 – [info] 192.168.8.57 can be new master.
Fri Oct 26 14:17:12 2018 – [info]
From:
192.168.8.58(192.168.8.58:3306) (current master)
 +–192.168.8.57(192.168.8.57:3306)
 +–192.168.8.59(192.168.8.59:3306)
To:
192.168.8.57(192.168.8.57:3306) (new master)
 +–192.168.8.59(192.168.8.59:3306)
 +–192.168.8.58(192.168.8.58:3306)
Starting master switch from 192.168.8.58(192.168.8.58:3306) to 192.168.8.57(192.168.8.57:3306)? (yes/NO): yes
Fri Oct 26 14:17:16 2018 – [info] Checking whether 192.168.8.57(192.168.8.57:3306) is ok for the new master..
Fri Oct 26 14:17:16 2018 – [info]  ok.
Fri Oct 26 14:17:16 2018 – [info] 192.168.8.58(192.168.8.58:3306): SHOW SLAVE STATUS returned empty result. To check replication filtering rules, temporarily executing CHANGE MASTER to a dummy host.
Fri Oct 26 14:17:16 2018 – [info] 192.168.8.58(192.168.8.58:3306): Resetting slave pointing to the dummy host.
Fri Oct 26 14:17:16 2018 – [info] ** Phase 1: Configuration Check Phase completed.
Fri Oct 26 14:17:16 2018 – [info]
Fri Oct 26 14:17:16 2018 – [info] * Phase 2: Rejecting updates Phase..
Fri Oct 26 14:17:16 2018 – [info]
Fri Oct 26 14:17:16 2018 – [info] Executing master ip online change script to disable write on the current master:
Fri Oct 26 14:17:16 2018 – [info]   /usr/local/bin/master_ip_online_change –command=stop –orig_master_host=192.168.8.58 –orig_master_ip=192.168.8.58 –orig_master_port=3306 –orig_master_user='root' –new_master_host=192.168.8.57 –new_master_ip=192.168.8.57 –new_master_port=3306 –new_master_user='root' –orig_master_ssh_user=root –new_master_ssh_user=root   –orig_master_is_new_slave –orig_master_password=xxx –new_master_password=xxx
Fri Oct 26 14:17:16 2018 363856 Set read_only on the new master.. ok.
Fri Oct 26 14:17:16 2018 369994 Drpping app user on the orig master..
Fri Oct 26 14:17:16 2018 375886 Waiting all running 2 threads are disconnected.. (max 1500 milliseconds)
{'Time' => '12692','db' => undef,'Id' => '2','User' => 'repl','State' => 'Master has sent all binlog to slave; waiting for more updates','Command' => 'Binlog Dump GTID','Info' => undef,'Host' => 'master:38252'}
{'Time' => '12637','db' => undef,'Id' => '3','User' => 'repl','State' => 'Master has sent all binlog to slave; waiting for more updates','Command' => 'Binlog Dump GTID','Info' => undef,'Host' => 'slave2:56564'}
Fri Oct 26 14:17:16 2018 874083 Waiting all running 2 threads are disconnected.. (max 1000 milliseconds)
{'Time' => '12693','db' => undef,'Id' => '2','User' => 'repl','State' => 'Master has sent all binlog to slave; waiting for more updates','Command' => 'Binlog Dump GTID','Info' => undef,'Host' => 'master:38252'}
{'Time' => '12638','db' => undef,'Id' => '3','User' => 'repl','State' => 'Master has sent all binlog to slave; waiting for more updates','Command' => 'Binlog Dump GTID','Info' => undef,'Host' => 'slave2:56564'}
Fri Oct 26 14:17:17 2018 375241 Waiting all running 2 threads are disconnected.. (max 500 milliseconds)
{'Time' => '12693','db' => undef,'Id' => '2','User' => 'repl','State' => 'Master has sent all binlog to slave; waiting for more updates','Command' => 'Binlog Dump GTID','Info' => undef,'Host' => 'master:38252'}
{'Time' => '12638','db' => undef,'Id' => '3','User' => 'repl','State' => 'Master has sent all binlog to slave; waiting for more updates','Command' => 'Binlog Dump GTID','Info' => undef,'Host' => 'slave2:56564'}
Fri Oct 26 14:17:17 2018 876317 Set read_only=1 on the orig master.. ok.
Fri Oct 26 14:17:17 2018 878132 Waiting all running 2 queries are disconnected.. (max 500 milliseconds)
{'Time' => '12694','db' => undef,'Id' => '2','User' => 'repl','State' => 'Master has sent all binlog to slave; waiting for more updates','Command' => 'Binlog Dump GTID','Info' => undef,'Host' => 'master:38252'}
{'Time' => '12639','db' => undef,'Id' => '3','User' => 'repl','State' => 'Master has sent all binlog to slave; waiting for more updates','Command' => 'Binlog Dump GTID','Info' => undef,'Host' => 'slave2:56564'}
Fri Oct 26 14:17:18 2018 380824 Killing all application threads..
Fri Oct 26 14:17:18 2018 383181 done.
Fri Oct 26 14:17:18 2018 – [info]  ok.
Fri Oct 26 14:17:18 2018 – [info] Locking all tables on the orig master to reject updates from everybody (including root):
Fri Oct 26 14:17:18 2018 – [info] Executing FLUSH TABLES WITH READ LOCK..
Fri Oct 26 14:17:18 2018 – [info]  ok.
Fri Oct 26 14:17:18 2018 – [info] Orig master binlog:pos is mysql-bin.000011:400.
Fri Oct 26 14:17:18 2018 – [info]  Waiting to execute all relay logs on 192.168.8.57(192.168.8.57:3306)..
Fri Oct 26 14:17:18 2018 – [info]  master_pos_wait(mysql-bin.000011:400) completed on 192.168.8.57(192.168.8.57:3306). Executed 0 events.
Fri Oct 26 14:17:18 2018 – [info]   done.
Fri Oct 26 14:17:18 2018 – [info] Getting new master's binlog name and position..
Fri Oct 26 14:17:18 2018 – [info]  mysql-bin.000012:194
Fri Oct 26 14:17:18 2018 – [info]  All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.8.57', MASTER_PORT=3306, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='xxx';
Fri Oct 26 14:17:18 2018 – [info] Executing master ip online change script to allow write on the new master:
Fri Oct 26 14:17:18 2018 – [info]   /usr/local/bin/master_ip_online_change –command=start –orig_master_host=192.168.8.58 –orig_master_ip=192.168.8.58 –orig_master_port=3306 –orig_master_user='root' –new_master_host=192.168.8.57 –new_master_ip=192.168.8.57 –new_master_port=3306 –new_master_user='root' –orig_master_ssh_user=root –new_master_ssh_user=root   –orig_master_is_new_slave –orig_master_password=xxx –new_master_password=xxx
Fri Oct 26 14:17:18 2018 735339 Set read_only=0 on the new master.
Fri Oct 26 14:17:18 2018 736744 Creating app user on the new master..
Got Error: Undefined subroutine &main::FIXME_xxx_create_app_user called at /usr/local/bin/master_ip_online_change line 246.
Fri Oct 26 14:17:18 2018 – [warning] Proceeding.
Fri Oct 26 14:17:18 2018 – [info]
Fri Oct 26 14:17:18 2018 – [info] * Switching slaves in parallel..
Fri Oct 26 14:17:18 2018 – [info]
Fri Oct 26 14:17:18 2018 – [info] — Slave switch on host 192.168.8.59(192.168.8.59:3306) started, pid: 4255
Fri Oct 26 14:17:18 2018 – [info]
Fri Oct 26 14:17:19 2018 – [info] Log messages from 192.168.8.59 …
Fri Oct 26 14:17:19 2018 – [info]
Fri Oct 26 14:17:18 2018 – [info]  Waiting to execute all relay logs on 192.168.8.59(192.168.8.59:3306)..
Fri Oct 26 14:17:18 2018 – [info]  master_pos_wait(mysql-bin.000011:400) completed on 192.168.8.59(192.168.8.59:3306). Executed 0 events.
Fri Oct 26 14:17:18 2018 – [info]   done.
Fri Oct 26 14:17:18 2018 – [info]  Resetting slave 192.168.8.59(192.168.8.59:3306) and starting replication from the new master 192.168.8.57(192.168.8.57:3306)..
Fri Oct 26 14:17:18 2018 – [info]  Executed CHANGE MASTER.
Fri Oct 26 14:17:18 2018 – [info]  Slave started.
Fri Oct 26 14:17:19 2018 – [info] End of log messages from 192.168.8.59 …
Fri Oct 26 14:17:19 2018 – [info]
Fri Oct 26 14:17:19 2018 – [info] — Slave switch on host 192.168.8.59(192.168.8.59:3306) succeeded.
Fri Oct 26 14:17:19 2018 – [info] Unlocking all tables on the orig master:
Fri Oct 26 14:17:19 2018 – [info] Executing UNLOCK TABLES..
Fri Oct 26 14:17:19 2018 – [info]  ok.
Fri Oct 26 14:17:19 2018 – [info] Starting orig master as a new slave..
Fri Oct 26 14:17:19 2018 – [info]  Resetting slave 192.168.8.58(192.168.8.58:3306) and starting replication from the new master 192.168.8.57(192.168.8.57:3306)..
Fri Oct 26 14:17:19 2018 – [info]  Executed CHANGE MASTER.
Fri Oct 26 14:17:20 2018 – [info]  Slave started.
Fri Oct 26 14:17:20 2018 – [info] All new slave servers switched successfully.
Fri Oct 26 14:17:20 2018 – [info]
Fri Oct 26 14:17:20 2018 – [info] * Phase 5: New master cleanup phase..
Fri Oct 26 14:17:20 2018 – [info]
Fri Oct 26 14:17:20 2018 – [info]  192.168.8.57: Resetting slave info succeeded.
Fri Oct 26 14:17:20 2018 – [info] Switching master to 192.168.8.57(192.168.8.57:3306) completed successfully.
四、查看主从库状态
 
192.168.8.57
 
mysql> show slave status \G
Empty set (0.00 sec)
mysql> show variables like '%read_only%';
+———————–+——-+
| Variable_name         | Value |
+———————–+——-+
| innodb_read_only      | OFF   |
| read_only             | OFF   |
| super_read_only       | OFF   |
| transaction_read_only | OFF   |
| tx_read_only          | OFF   |
+———————–+——-+
该节点已经变成主库,并且read_only已经关闭。

本文来自网络,不代表站长网立场,转载请注明出处:https://www.tzzz.com.cn/html/jc/mysql/2021/1221/41720.html

作者: dawei

【声明】:站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。
联系我们

联系我们

0577-28828765

在线咨询: QQ交谈

邮箱: xwei067@foxmail.com

工作时间:周一至周五,9:00-17:30,节假日休息

返回顶部