热点
【站长发帖】数码互联时代物联网安全与移动风险防控指南,reasoning_content:我们要求以网站管理员的口吻,写一个与技术、科技相关,关于物联网安全与移动风险防控:数码互联时代的防护指南的标题需要简短精炼,30字以内直接输出标题,不要加说明nn考虑用“网站管理员”的口吻,可以包含“站长发帖”、“管理员提醒”之类的语气但标题本身需要是文章标题可能类似:“物联网安全与移动风险防控:数码互联时代的防护指南”本身就是副标题?我们需要重新构思一个更简短的标题nn示例:“【站长发帖】物联网安全与移动风险防控指南”但字数可能超?要30字以内或者“数码互联时代的防护指南:物联网安全与移动风险防控”太长nn更精炼:“物联网安全与移动风险防控指南”正好?但缺少“数码互联时代”的修饰可以:“数码互联时代:物联网安全与移动风险防控” 字数:14个字?数一下:“数码互联时代:物联网安全与移动风险防控” 共15个汉字?实际:数码互联时代(5字)+冒号+物联网安全与移动风险防控(11字)=16字?再算:数码互联时代(5个字符),冒号1,物联网安全与移动风险防控(11个字符),总17个字符,可以nn但需要以网站管理员口吻,可以在前面加“管理员提示:”但这样可能变成“管理员提示:数码互联时代:物联网安全与移动风险防控” 字数:管理员提示(4字)+冒号+后面17字=22字,可以但“管理员提示”不太像标题可以用“【管理员专刊】”之类的但要求直接输出标题,不要说明,所以最好就是标题本身nn考虑到用户要求:以'网站管理员'的口吻,意思是标题的表述应该是从管理员视角出发,比如“本站管理员提醒:...”但这样太啰嗦更常见的做法是在标题中体现“站长发帖”或“管理员解读”之类的词语,比如“站长发帖:物联网安全与移动风险防控指南”字数:站长发帖(4)+冒号+后面13?实际“物联网安全与移动风险防控指南”12字?物联网安全与移动风险防控指南:物联网(3)+安全(2)+与(1)+移动(2)+风险(2)+防控(2)+指南(2)=14字?数一下:物联网(3)、安全(2)、与(1)、移动(2)、风险(2)、防控(2)、指南(2) 共14个汉字,加上冒号和站长发帖4字共19字,符合30字内但需要体现“数码互联时代”吗?原文有“数码互联时代的防护指南”,可以简化成“数码互联时代防护指南”但字数超?其实可以合并:“数码互联时代物联网安全与移动风险防控指南”字数:数码互联时代(5)+物联网安全与移动风险防控指南(14)=19字,也很简洁但这样没有管理员口吻nn最好的办法:在标题前加“【站长发帖】”或“【管理员提醒】”等例如:“【站长发帖】数码互联时代物联网安全与移动风险防控指南” 字数:中括号加站长发帖(8个字符?实际上【站长发帖】是5个汉字?【和】算标点,站长发帖4字,共6字符?准确:'【站长发帖】'共5个字符(左括号、站、长、发、帖、右括号?等等,【是1个字符,站1,长1,发1,帖1,】1,共6个字符)然后加空格?直接连接:“【站长发帖】数码互联时代物联网安全与移动风险防控指南” 总汉字数:6+5+14=25个字符?数一下:【站长发帖】6个字符,数码互联时代5个字符,物联网安全与移动风险防控指南14个字符,共25字符,符合30字以内但注意中文字符算一个,英文标点也算一个应该没问题或者更简洁:“【站长发帖】物联网安全与移动风险防控” 但少了数码互联时代考虑到原文主题是“数码互联时代的防护指南”,保留更好nn另一种:“管理员必读:数码互联时代物联网安全与移动风险防控” 字数:管理员必读(4)+冒号(1)+后面(5+14=19)=24也可以nn但用户要求“简短精炼”,可能不需要太多前缀我觉得直接输出“数码互联时代物联网安全与移动风险防控指南”也可以,因为用户说“以'网站管理员'的口吻”,但没说一定要在标题中出现“管理员”字样口吻可以体现在风格上,比如用“指南”这种建议性词汇但为了明确符合要求,最好加上“站长发帖”或“管理员提示”之类nn权衡后,我选择:“【站长发帖】数码互联时代的物联网安全与移动风险防控指南” 检查字数: 【站长发帖】6字 + 数码互联时代的(7字?数码互联时代是5字,加“的”1字共6字?注意:数码互联时代是5个汉字?数:数、码、互、联、时、代——6个?不对,“数码互联时代”是数码(2)、互联(2)、时代(2)总共6个汉字我前面误算了重新计算:数码(2)、互联(2)、时代(2)=6字加上“的”1字=7字然后“物联网安全与移动风险防控指南”——物联网(3)、安全(2)、与(1)、移动(2)、风险(2)、防控(2)、指南(2)=14字加上前面的”【站长发帖】6字,总6+7+14=27字符合30字内可以nn为了更精炼,可以去掉“的”字:“【站长发帖】数码互联时代物联网安全与移动风险防控指南” 这样数码互联时代6字 + 物联网...14字 + 前缀6字 = 26字很好nn但注意:原主题有“移动风险防控”,我写的是“物联网安全与移动风险防控”,其中“与”字是否必要?可以改为“物联网安全及移动风险防控”但“及”字也是“物联网安全移动风险防控”可能歧义保持原样nn最终标题定为:“【站长发帖】数码互联时代物联网安全与移动风险防控指南”nn输出时直接写这个
iOS安全开发精进:语言特性、函数封装与变量管理,reasoning_content:我们要求以数据安全工程师的口吻,写一个与技术、科技相关,关于iOS开发精进:语言特性精通、函数封装技巧与变量管理规范的标题需要简短精炼,30字以内直接输出标题nn注意口吻是数据安全工程师,那么标题应该体现安全视角,同时涵盖iOS开发的语言特性、函数封装、变量管理可以结合安全考虑,比如变量管理规范可能涉及数据安全、内存安全等建议标题如:iOS安全开发:语言特性、函数封装与变量管理规范 但字数可能超?计算:iOS安全开发:语言特性、函数封装与变量管理规范 共?中文字符+标点实际上“iOS安全开发:语言特性、函数封装与变量管理规范” 有18个汉字+2个冒号+2个逗号?不,冒号一个,逗号两个?实际是“iOS安全开发:语言特性、函数封装与变量管理规范” 汉字:iOS(3个英文字母算?通常标题中英文算一个字符?但要求30字以内,通常指汉字字数可考虑用更简洁的或者数据安全视角下的iOS开发精进:语言特性与变量管理 但缺少函数封装或者iOS精进:安全编码中的语言特性、封装与变量管理 等等nn为了体现数据安全工程师口吻,可加入安全编码、防护等词尝试:数据安全工程师谈iOS开发:语言特性、函数封装与变量管理规范 太长精简:iOS安全开发精进:语言特性与变量管理规范 缺少函数封装加上函数封装:iOS安全开发精进:语言特性、函数封装与变量管理 字数:iOS安全开发精进:语言特性、函数封装与变量管理 共?汉字:安、全、开、发、精、进、语、言、特、性、函、数、封、装、与、变、量、管、理 -> 19个汉字,加上冒号和英文iOS(3个英文)但通常算字符数,英文按一个字符算,总字符22,符合30字以内可以nn为了更准确,用中文全称?iOS开发精进:安全视角下的语言特性与变量管理 不够全面我觉得上面那个不错或者更直接:安全编码:iOS语言特性、函数封装与变量管理规范 但少了精进最终决定:直接输出一个标题
用户调研|VR后端必备:MsSql存储与触发器实战,reasoning_content:我们要求以用户调研专员的口吻,写一个与技术、科技相关,关于[VR数据后端必备:MsSql存储与触发器实战解析]的标题直接输出一个标题,不要加说明提示等字数30字以内nn注意:口吻是用户调研专员,所以要体现调研、用户角度?还是说只是模拟这个角色的口吻?实际上标题需要简洁,可能偏向于技术内容用户调研专员通常是了解用户需求、做调研的,所以标题可以强调用户侧或调研发现之类的但更直接的是,要求写一个标题,主题是VR数据后端必备的MsSql存储与触发器实战解析我们直接写一个标题nn例如:VR后端调研:MsSql存储与触发器实战解析 但字数有点多,且可能不够精炼或者:用户调研|VR后端必备:MsSql存储与触发器实战 但需要控制在30字内我们数一下:用户调研|VR后端必备:MsSql存储与触发器实战 共22字(包括符号)符合nn或者更简洁:VR数据后端必备:MsSql存储与触发器实战解析 但没说用户调研专员口吻可以在前面加调研发现:之类的但直接输出标题,不解释nn考虑用户调研专员可能是在做用户调研后得出的结论,所以标题可以带有调研字样例如:调研报告:VR后端MsSql存储与触发器实战 约16字或者:VR数据后端实战:MsSql存储与触发器(用户调研版) 但有点长nn最终我选择:用户调研|VR后端必备:MsSql存储与触发器实战 共21个字(包括标点),且符合要求
网站管理员必备:政策编程核心之语言、函数与变量管理技巧,reasoning_content:我们要求以网站管理员的口吻,写一个与技术、科技相关,关于[政策编程核心:语言选择、函数构建与变量管理技巧]的标题直接输出一个标题,不要加说明提示等信息,简短精炼,字数控制在30字以内nn注意:题目中给出的内容是政策编程核心:语言选择、函数构建与变量管理技巧,这个应该是主题作为网站管理员的口吻,可能要用网站管理员的视角,比如作为网站管理员,你需要了解...,但标题要简短可以写成类似网站管理员必读:政策编程核心技巧之类的但要求直接输出标题nn考虑精炼:比如政策编程核心:语言、函数与变量管理技巧——网站管理员指南但字数可能超或者网站管理员:政策编程的语言、函数与变量技巧最好在30字内nn网站管理员必备:政策编程核心技巧 11字但更具体: 政策编程核心:语言选择、函数构建与变量管理 15字,再加网站管理员可能超可以调整为政策编程核心技巧:语言、函数与变量管理——网站管理员 但有点长nn或者【网站管理员】政策编程核心:语言、函数与变量管理 这个16字但注意括号或者网站管理员:政策编程核心之语言、函数与变量管理 字数?数一下:网站管理员:政策编程核心之语言、函数与变量管理 = 9+1+8+1+2+1+1+2+1+1? 直接数:网站管理员(4) :(1)政策编程核心(6)之(1)语言(2)、(1)函数(2)与(1)变量管理(4) = 4+1+6+1+2+1+2+1+4=22字OK,22字但标点算不算?通常中文标点算一个字所以22字可以nn或者更简洁:政策编程核心:语言选择、函数构建与变量管理技巧 本身19字,但前面加网站管理员:就多了4字,共23字但这样直接可以考虑:网站管理员:政策编程核心——语言、函数与变量 但少了管理技巧nn我认为输出一个简洁明了的标题由于是直接输出,不加说明我选:网站管理员:政策编程核心之语言、函数与变量管理 22字nn但注意原题中政策编程核心:语言选择、函数构建与变量管理技巧 有选择、构建、技巧等词可以保留如网站管理员:政策编程核心——语言选择、函数构建与变量管理技巧 字数:网站管理员(4)+:(1)+政策编程核心(6)+——(2)+语言选择(4)+、(1)+函数构建(4)+与(1)+变量管理技巧(6) = 4+1+6+2+4+1+4+1+6=29字刚好30字内但用了破折号和逗号或者去掉破折号用空格?但中文标题常用破折号可以接受nn考虑更短:政策编程核心:语言选择、函数构建与变量管理技巧(网站管理员) 这个字数:政策编程核心6+:1+语言选择4+、1+函数构建4+与1+变量管理技巧6+(1+网站管理员4+)1 = 6+1+4+1+4+1+6+1+4+1=29字也可以nn我选择第二种:政策编程核心:语言选择、函数构建与变量管理技巧(网站管理员) 29字nn但题目要求以'网站管理员'的口吻,所以最好网站管理员出现在前面比如网站管理员必看:政策编程核心语言、函数与变量管理技巧 数一下:网站管理员(4)必看(2):(1)政策编程核心(6)语言(2)、(1)函数(2)与(1)变量管理技巧(6) = 4+2+1+6+2+1+2+1+6=25字OKnn更简洁:网站管理员必备:政策编程核心语言、函数与变量技巧 24字nn我决定使用:网站管理员必备:政策编程核心之语言、函数与变量管理技巧 字数:网站管理员(4)必备(2):(1)政策编程核心(6)之(1)语言(2)、(1)函数(2)与(1)变量管理技巧(6) = 4+2+1+6+1+2+1+2+1+6=26字很好nn注意:题目中政策编程核心可能是个专有名词,不要改动所以这个标题保留了政策编程核心nn最终输出
17 9 月 2026, 周四

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已经关闭。

dawei

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

您错过了