我的编程空间,编程开发者的网络收藏夹
学习永远不晚

MHA集群搭建

短信预约 -IT技能 免费直播动态提醒
省份

北京

  • 北京
  • 上海
  • 天津
  • 重庆
  • 河北
  • 山东
  • 辽宁
  • 黑龙江
  • 吉林
  • 甘肃
  • 青海
  • 河南
  • 江苏
  • 湖北
  • 湖南
  • 江西
  • 浙江
  • 广东
  • 云南
  • 福建
  • 海南
  • 山西
  • 四川
  • 陕西
  • 贵州
  • 安徽
  • 广西
  • 内蒙
  • 西藏
  • 新疆
  • 宁夏
  • 兵团
手机号立即预约

请填写图片验证码后获取短信验证码

看不清楚,换张图片

免费获取短信验证码

MHA集群搭建

开篇

本文主要介绍如何搭建MHA集群,希望给你带来帮助

基本环境介绍

Linux:CentOS 7.4
MySQL:5.7.21+传统复制(开启GTID不搭建binlog server)
VIP:192.168.68.100
角色 ip地址 主机名 server_id 类型
Master 192.168.68.161 server1 1413306
Candicate master 192.168.68.162 server2 1423306
Manager/Slave 192.168.68.163 server3 1433306 读/监控/管理

server1

主从复制搭建

#创建复制用户
grant replication slave on *.* to 'repl'@'192.168.68.%' identified by 'repl4slave';
flush privileges;
#创建监控用户
grant all privileges on *.* to 'xmm'@'192.168.68.%' identified by 'xmmxmm';
flush privileges;

MHA安装

#软件安装
yum localinstall -y mha4mysql-node-0.56-0.el6.noarch
#SSH登陆检查
ssh server2
ssh server3

如果不是一个新master

#master导出数据
mysqldump --master-data=2 --single-transaction -R --triggers -A >server1-all-180329.sql

VIP手工绑定

绑定:/sbin/ip addr add 192.168.68.100/32 dev ens32
解绑:/sbin/ip addr del 192.168.68.100/32 dev ens32 

server2

主从复制搭建

#配置和开启复制
change master to master_host='192.168.68.161',master_port=3306,master_user='repl',master_password='repl4slave',master_auto_position=1;
start slave;
#slave开启read_only
mysql -h227.0.0.1 -p -e 'set global read_only=1'
mysql -h227.0.0.1 -p -e 'set global relay_log_purge=0'

MHA安装

#软件安装
yum localinstall -y mha4mysql-node-0.56-0.el6.noarch
#SSH登陆检查
ssh server1
ssh server3

如果master不是新的

#导入数据
mysql -h227.0.0.1 -uroot -p < /tmp/data/server1-all-180329.sql

server3

主从复制搭建

#导入数据、配置和开启复制
mysql -h227.0.0.1 -uroot -p < /tmp/data/server1-all-180329.sql
change master to master_host='192.168.68.135',master_port=3306,master_user='repl',master_password='repl4slave',master_auto_position=1;
start slave;
#slave开启read_only
mysql -h227.0.0.1 -p -e 'set global read_only=1'
mysql -h227.0.0.1 -p -e 'set global relay_log_purge=0'

MHA安装

#软件安装
yum localinstall -y mha4mysql-node-0.56-0.el6.noarch
yum localinstall -y mha4mysql-manager-0.56-0.el6.noarch
#SSH无密钥验证登陆
ssh-keygen
cd ~/.ssh/
cat id_rsa.pub > authorized_keys
chmod 600 *
scp -r ~/.ssh/ root@192.168.68.161:~/
scp -r ~/.ssh/ root@192.168.68.162:~/
ssh server2
ssh server3
#创建MHA工作目录,上传配置文件和脚本
mkdir -p /etc/masterha
masterha_default.cnf
app1.cnf
master_ip_failover
master_ip_online_change
chmod +x master_ip*
#开启debug
masterha_default.cnf --> log_level=debug
#manager上检查ssh/rple/开启mha进程
masterha_check_ssh xxx
masterha_check_repl xxx
masterha_manager xxx

配置文件和脚本详细

masterha_default.cnf
[server default]
#MySQL的用户和密码
user=xmm
password=xmmxmm

#系统ssh用户
ssh_user=root

#复制用户
repl_user=repl
repl_password=repl4slave

#监控
ping_interval=1
#shutdown_script=""

#日志输出
log_level=debug

#报警脚本
report_script=/etc/masterha/send_report    

#切换调用的脚本
master_ip_failover_script= /etc/masterha/master_ip_failover
master_ip_online_change_script= /etc/masterha/master_ip_online_change
app1.cnf
[server default]
#mha manager工作目录
manager_workdir = /var/log/masterha/app1
manager_log = /var/log/masterha/app1/app1.log
remote_workdir = /var/log/masterha/app1

[server1]
hostname=node1
master_binlog_dir = /data/mysql/mysql3306/logs
candidate_master = 0
check_repl_delay = 0

[server2]
hostname=node2
master_binlog_dir=/data/mysql/mysql3306/logs
candidate_master = 1
check_repl_delay = 0

[server3]
hostname=node1
master_binlog_dir = /data/mysql/mysql3306/logs
candidate_master = 0
check_repl_delay = 0
master_ip_failover
#!/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;
#自定义该组机器的vip
my $vip = "192.168.68.100";
my $if = "ens32";
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
);

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,
);

sub add_vip {
    my $output1 = `ssh -o ConnectTimeout=15  -o ConnectionAttempts=3 $orig_master_host /sbin/ip addr del $vip/32 dev $if`;
    my $output2 = `ssh -o ConnectTimeout=15  -o ConnectionAttempts=3 $new_master_host /sbin/ip addr add $vip/32 dev $if`;

}
exit &main();

sub main {
  if ( $command eq "stop" || $command eq "stopssh" ) {

    # $orig_master_host, $orig_master_ip, $orig_master_port are passed.
    # If you manage master ip address at global catalog database,
    # invalidate orig_master_ip here.
    my $exit_code = 1;
    eval {

      # updating global catalog, etc
      $exit_code = 0;
    };
    if ($@) {
      warn "Got Error: $@\n";
      exit $exit_code;
    }
    exit $exit_code;
  }
  elsif ( $command eq "start" ) {

    # all arguments are passed.
    # If you manage master ip address at global catalog database,
    # activate new_master_ip here.
    # You can also grant write access (create user, set read_only=0, etc) here.
    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 "Set read_only=0 on the new master.\n";
      $new_master_handler->disable_read_only();

      ## Creating an app user on the new master
      #print "Creating app user on the new master..\n";
      #FIXME_xxx_create_user( $new_master_handler->{dbh} );
      $new_master_handler->enable_log_bin_local();
      $new_master_handler->disconnect();

      ## Update master ip on the catalog database, etc
      &add_vip();
      $exit_code = 0;
    };
    if ($@) {
      warn $@;

      # If you want to continue failover, exit 10.
      exit $exit_code;
    }
    exit $exit_code;
  }
  elsif ( $command eq "status" ) {

    # do nothing
    exit 0;
  }
  else {
    &usage();
    exit 1;
  }
}

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";
}
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;
#添加vip定义
my $vip = "192.168.68.100";
my $if = "ens32";

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 drop_vip {
        my $output = `ssh -o ConnectTimeout=15  -o ConnectionAttempts=3 $orig_master_host /sbin/ip addr del $vip/32 dev $if`;
    #mysql里的连接全部干掉
    #FIXME
}
sub add_vip {
        my $output = `ssh -o ConnectTimeout=15  -o ConnectionAttempts=3 $new_master_host /sbin/ip addr add $vip/32 dev $if`;

}

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";
      print current_time_us() . " drop vip $vip..\n";
      #drop_app_user($orig_master_handler);
     &drop_vip();

      ## 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";
      print current_time_us() . "Add vip $vip on $if..\n";
     # create_app_user($new_master_handler);
      &add_vip();
      $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;
}
自动删除relay log
#检查软件安装有哪些内容
rpm -ql mha4mysql-node-0.56-0.el6.noarch
#2台slave上
[root@192.168.0.142 ~]# cat purge_relay_log.sh 
#!/bin/bash
user=xmm
passwd=xmmxmm
port=3306
log_dir='/data/masterha/log'
work_dir='/data'
purge='/usr/bin/purge_relay_logs'

if [ ! -d $log_dir ]
then
   mkdir $log_dir -p
fi

$purge --user=$user --password=$passwd --disable_relay_log_purge --port=$port --workdir=$work_dir >> $log_dir/purge_relay_logs.log 2>&1
#添加到crontab定期执行
[root@192.168.0.142 ~]# crontab -l
0 4 * * * /bin/bash /root/purge_relay_log.sh
自动发送邮件
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import smtplib
from email.mime.text import MIMEText
#设置服务器所需信息
#163邮箱服务器地址
mail_host = 'smtp.163.com'
#163用户名
mail_user = 'xxxx'
#密码(部分邮箱为授权码)
mail_pass = 'xxxxx'
#邮件发送方邮箱地址
sender = 'xxxx@163.com'
#邮件接受方邮箱地址,注意需要[]包裹,这意味着你可以写多个邮件地址群发
receivers = ['xxxx@163.com']

#设置email信息
#邮件内容设置
message = MIMEText('content:这是master故障failover切换时自动发送的邮件','plain','utf-8')
#邮件主题
message['Subject'] = 'mha邮件'
#发送方信息
message['From'] = sender
#接受方信息
message['To'] = receivers[0]

#登录并发送邮件
try:
    smtpObj = smtplib.SMTP()
    #连接到服务器
    smtpObj.connect(mail_host,25)
    #登录到服务器
    #smtpObj = smtplib.SMTP_SSL(mail_host)
    smtpObj.login(mail_user,mail_pass)
    #发送
    smtpObj.sendmail(
        sender,receivers,message.as_string())
    #退出
    smtpObj.quit()
    print('success')
except smtplib.SMTPException as e:
    print('error',e) #打印错误

启动三步骤与日志

ssh检查
[root@server3 16:20:38 /usr/bin]
#masterha_check_ssh --global_conf=/etc/masterha/masterha_default.cnf --conf=/etc/masterha/app1.cnf 
Tue Apr  3 16:28:59 2018 - [info] Reading default configuration from /etc/masterha/masterha_default.cnf..
Tue Apr  3 16:28:59 2018 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Tue Apr  3 16:28:59 2018 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Tue Apr  3 16:28:59 2018 - [info] Starting SSH connection tests..
Tue Apr  3 16:29:01 2018 - [debug] 
Tue Apr  3 16:29:00 2018 - [debug]  Connecting via SSH from root@server3(192.168.68.163:22) to root@server1(192.168.68.161:22)..
Tue Apr  3 16:29:00 2018 - [debug]   ok.
Tue Apr  3 16:29:00 2018 - [debug]  Connecting via SSH from root@server3(192.168.68.163:22) to root@server2(192.168.68.162:22)..
Tue Apr  3 16:29:00 2018 - [debug]   ok.
Tue Apr  3 16:29:04 2018 - [debug] 
Tue Apr  3 16:28:59 2018 - [debug]  Connecting via SSH from root@server1(192.168.68.161:22) to root@server2(192.168.68.162:22)..
Tue Apr  3 16:28:59 2018 - [debug]   ok.
Tue Apr  3 16:28:59 2018 - [debug]  Connecting via SSH from root@server1(192.168.68.161:22) to root@server3(192.168.68.163:22)..
Tue Apr  3 16:29:04 2018 - [debug]   ok.
Tue Apr  3 16:29:04 2018 - [debug] 
Tue Apr  3 16:28:59 2018 - [debug]  Connecting via SSH from root@server2(192.168.68.162:22) to root@server1(192.168.68.161:22)..
Tue Apr  3 16:29:00 2018 - [debug]   ok.
Tue Apr  3 16:29:00 2018 - [debug]  Connecting via SSH from root@server2(192.168.68.162:22) to root@server3(192.168.68.163:22)..
Tue Apr  3 16:29:04 2018 - [debug]   ok.
Tue Apr  3 16:29:04 2018 - [info] All SSH connection tests passed successfully.
复制检查
[root@server3 16:29:04 /usr/bin]
#masterha_check_repl --global_conf=/etc/masterha/masterha_default.cnf --conf=/etc/masterha/app1.cnf                 Tue Apr  3 16:29:12 2018 - [info] Reading default configuration from /etc/masterha/masterha_default.cnf..
Tue Apr  3 16:29:12 2018 - [info] Reading application default configuration from /etc/masterha/app1.cnf..
Tue Apr  3 16:29:12 2018 - [info] Reading server configuration from /etc/masterha/app1.cnf..
Tue Apr  3 16:29:12 2018 - [info] MHA::MasterMonitor version 0.56.
Tue Apr  3 16:29:12 2018 - [debug] Connecting to servers..
Tue Apr  3 16:29:13 2018 - [debug]  Connected to: server1(192.168.68.161:3306), user=xmm
Tue Apr  3 16:29:13 2018 - [debug]  Number of slave worker threads on host server1(192.168.68.161:3306): 0
Tue Apr  3 16:29:13 2018 - [debug]  Connected to: server2(192.168.68.162:3306), user=xmm
Tue Apr  3 16:29:13 2018 - [debug]  Number of slave worker threads on host server2(192.168.68.162:3306): 0
Tue Apr  3 16:29:13 2018 - [debug]  Connected to: server3(192.168.68.163:3306), user=xmm
Tue Apr  3 16:29:13 2018 - [debug]  Number of slave worker threads on host server3(192.168.68.163:3306): 0
Tue Apr  3 16:29:13 2018 - [debug]  Comparing MySQL versions..
Tue Apr  3 16:29:13 2018 - [debug]   Comparing MySQL versions done.
Tue Apr  3 16:29:13 2018 - [debug] Connecting to servers done.
Tue Apr  3 16:29:13 2018 - [info] GTID failover mode = 1
Tue Apr  3 16:29:13 2018 - [info] Dead Servers:
Tue Apr  3 16:29:13 2018 - [info] Alive Servers:
Tue Apr  3 16:29:13 2018 - [info]   server1(192.168.68.161:3306)
Tue Apr  3 16:29:13 2018 - [info]   server2(192.168.68.162:3306)
Tue Apr  3 16:29:13 2018 - [info]   server3(192.168.68.163:3306)
Tue Apr  3 16:29:13 2018 - [info] Alive Slaves:
Tue Apr  3 16:29:13 2018 - [info]   server2(192.168.68.162:3306)  Version=5.7.21-log (oldest major version between slaves) log-bin:enabled
Tue Apr  3 16:29:13 2018 - [info]     GTID ON
Tue Apr  3 16:29:13 2018 - [debug]    Relay log info repository: FILE
Tue Apr  3 16:29:13 2018 - [info]     Replicating from 192.168.68.161(192.168.68.161:3306)
Tue Apr  3 16:29:13 2018 - [info]     Primary candidate for the new Master (candidate_master is set)
Tue Apr  3 16:29:13 2018 - [info]   server3(192.168.68.163:3306)  Version=5.7.21-log (oldest major version between slaves) log-bin:enabled
Tue Apr  3 16:29:13 2018 - [info]     GTID ON
Tue Apr  3 16:29:13 2018 - [debug]    Relay log info repository: FILE
Tue Apr  3 16:29:13 2018 - [info]     Replicating from 192.168.68.161(192.168.68.161:3306)
Tue Apr  3 16:29:13 2018 - [info] Current Alive Master: server1(192.168.68.161:3306)
Tue Apr  3 16:29:13 2018 - [info] Checking slave configurations..
Tue Apr  3 16:29:13 2018 - [info] Checking replication filtering settings..
Tue Apr  3 16:29:13 2018 - [info]  binlog_do_db= , binlog_ignore_db= 
Tue Apr  3 16:29:13 2018 - [info]  Replication filtering check ok.
Tue Apr  3 16:29:13 2018 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Tue Apr  3 16:29:13 2018 - [info] Checking SSH publickey authentication settings on the current master..
Tue Apr  3 16:29:13 2018 - [debug] SSH connection test to server1, option -o StrictHostKeyChecking=no -o PasswordAuthentication=no -o BatchMode=yes -o ConnectTimeout=5, timeout 5
Tue Apr  3 16:29:13 2018 - [info] HealthCheck: SSH to server1 is reachable.
Tue Apr  3 16:29:13 2018 - [info] 
server1(192.168.68.161:3306) (current master)
 +--server2(192.168.68.162:3306)
 +--server3(192.168.68.163:3306)

Tue Apr  3 16:29:13 2018 - [info] Checking replication health on server2..
Tue Apr  3 16:29:13 2018 - [info]  ok.
Tue Apr  3 16:29:13 2018 - [info] Checking replication health on server3..
Tue Apr  3 16:29:13 2018 - [info]  ok.
Tue Apr  3 16:29:13 2018 - [info] Checking master_ip_failover_script status:
Tue Apr  3 16:29:13 2018 - [info]   /etc/masterha/master_ip_failover --command=status --ssh_user=root --orig_master_host=server1 --orig_master_ip=192.168.68.161 --orig_master_port=3306 
Tue Apr  3 16:29:13 2018 - [info]  OK.
Tue Apr  3 16:29:13 2018 - [warning] shutdown_script is not defined.
Tue Apr  3 16:29:13 2018 - [debug]  Disconnected from server1(192.168.68.161:3306)
Tue Apr  3 16:29:13 2018 - [debug]  Disconnected from server2(192.168.68.162:3306)
Tue Apr  3 16:29:13 2018 - [debug]  Disconnected from server3(192.168.68.163:3306)
Tue Apr  3 16:29:13 2018 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.
启动MHA
[root@server3 16:29:13 /usr/bin]
#masterha_manager --global_conf=/etc/masterha/masterha_default.cnf --conf=/etc/masterha/app1.cnf > /var/log/masterha/app1/app1.log 2>&1 &
[2] 4406

压测与故障切换

有关故障切换参考另外一篇博文

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

MHA集群搭建

下载Word文档到电脑,方便收藏和打印~

下载Word文档

猜你喜欢

2024-04-02

集群搭建

1.  集群搭建之主从复制MySQL主从复制是一个异步的复制过程,主库发送更新事件到从库,从库读取更新记录,并执行更新记录,使得从库的内容与主库保持一致。1.1   主服务器的配置1.1.1   第一步:修改my.conf文件:在[mysqld]段下添加:#启
集群搭建
2017-09-01
2024-04-02

搭建Domino群集

搭建Domino群集浙江省电力办公自动化系统(以下简称:OA系统)是全省推广,统一软件、统一平台、统一规划与实施的一套大型应用系统。它的硬件平台采用IBM的小型机AS/400,软件采用Lotus Domino/Notes,并实施了在一台小型
2023-06-03

搭建Nacos集群

nacos的默认端口是8848,但是他还占用了另外两个接口:9848、9849。因此,在单机配置集群时,不可使用三个连续的端口,否则会导致 gRPC端口冲突。 端口与主端口(8848)偏移量作用98481000客户端gRPC请求服务端口,用
2023-08-18

Hadoop集群搭建

文章目录 一、运行环境配置(所有节点)1、基础配置2、配置Host 二、依赖软件安装(101节点)1、安装JDK2、安装Hadoop(root)3、Hadoop目录结构 三、本地运行模式(官方WordCount)1、简介
2023-08-30

redis集群搭建

Redis 5.0之后版本的高可用集群搭建 Redis系统介绍: Redis的基础介绍与安装使用步骤:https://www.jianshu.com/p/2a23257af57b Redis的基础数据结构与使用:https://www.jianshu.co
redis集群搭建
2019-03-23

mongodb集群搭建

mongodb集群搭建 小码农叔叔 2019-06-17 22:51:33 4086 收藏 7 分类专栏: mongodb 版权 集群方式有三种:Replica Set、Sharding、Master-Slaver三种方式 常用的主要是副本集和主从模式,主从模
mongodb集群搭建
2014-09-28

kafka集群搭建

一个典型的Kafka 集群中包含若干Producer(可以是web 前端产生的Page View,或者是服务器日志,系统 CPU、Memory 等),若干broker(Kafka 支持水平扩展,一般broker 数量越多,集群吞吐率越高),
2023-01-31
2024-04-02

nacos集群搭建

在官方文档上面就有结束搭建nacos是介绍 官方文档提供了一个Nacos集群的架构图,当我们访问Nacos时,首先会经过SLB,也就是负载均衡,通常是一个nginx,通过nginx来进行分发到具体的Nacos服务器上面。我们需要给不同的服
2023-08-19

Kubernetes 集群搭建(上)

不知道各位对Kubernetes了解多少呢?如果还是有一些了解,建议你读一下这篇文章,或许对你有些许帮助 !阅读本文您需要具备一下知识点:1.Kubernetes2.kubeadm3.docker以上三点如过各位看官都知晓,那么请尽情食用,
2023-06-05

kafka---- zookeeper集群搭建

1.准备工作:##准备3个节点,要求配置好主机名称,服务器之间系统时间保持一致##注意/etc/hostname 和/etc/hosts 配置主机名称(在这个里我准备Prac-zk-133, Prac-zk-134 , Prac-zk-13
2023-08-30

docker redis4.0集群搭建

redis集群对于很多人来说非常熟悉,在前些日子,我也有一位大兄弟也发布过一篇关于在阿里云(centOS7)上搭建redis 集群的文章,虽然集群搭建的文章在网上很多,我比较喜欢这篇文章的地方是他在搭建过程中,指出一些我们会遇到而别人没有指
2023-01-31

搭建mysql NDB集群

NDB群集安装介绍https://dev.mysql.com/doc/refman/8.0/en/mysql-cluster-basics.htmlNDBCLUSTER (也称为NDB)是一种内存存储引擎,提供高可用性和数据持久性功能。的NDBCLUSTER存
搭建mysql NDB集群
2020-08-26
2024-04-02

Elasticsearch集群搭建及Py

本文记录Elasticsearch物理集群的安装步骤,在3台机器上部署一个集群。行文顺序为整个安装过程从头到尾,期间发现不少问题。因此,本文不适合一步步跟着做,建议您看完整篇文章,然后再开始搭建集群。1 . 环境机器: 3台物理机器,分别为
2023-01-31

编程热搜

目录