返回顶部
首页 > 资讯 > 数据库 >MHA部署笔记(centos6+mysql5.6)
  • 198
分享到

MHA部署笔记(centos6+mysql5.6)

2024-04-02 19:04:59 198人浏览 安东尼
摘要

环境及软件版本:    Centos6.5x86_64    Mysql5.6.34编译安装版    MHA版本:m

环境及软件版本:

    Centos6.5x86_64

    Mysql5.6.34编译安装版

    MHA版本:mha4mysql-manager-0.56-0.el6.noarch.rpm mha4mysql-node-0.56-0.el6.noarch.rpm

 

节点角色:

    node93:10.1.20.93   默认主库

    node94:10.1.20.94   从库1,原先主库宕机后可提升为主库【mha管理节点也部署在这台机器上】

    node95:10.1.20.95   从库2,不允许提升为主库

   准备的VIP是 10.1.20.100/24

step1、配置主从关系

node93/etc/my.cnf配置文件部分关键地方:

[mysqld]

port            = 3306

Socket          = /tmp/mysql.sock

datadir         = /bdata/data/nowdb2

 

innodb_file_per_table=ON

character-set-server = utf8

default_storage_engine = InnoDB

skip-innodb_adaptive_hash_index

 

master_info_repository = TABLE

relay_log_info_repository = TABLE

relay_log_recovery = 1 #crash safe

log-bin=mysql-bin

binlog_fORMat=row

sync_binlog =1  #确保事务提交的时候BINLOG落盘

log-slave-updates

log_bin_trust_function_creators =1

binlog_rows_query_log_events=ON  #记录执行的语句到BINLOG query event

 

server-id=1020093

relay_log_purge=0

read_only=1

 

 

 

node94/etc/my.cnf配置文件部分关键地方:

[mysqld]

port            = 3306

socket          = /tmp/mysql.sock

datadir         = /bdata/data/nowdb2

 

innodb_file_per_table=ON

character-set-server = utf8

default_storage_engine = InnoDB

skip-innodb_adaptive_hash_index

 

master_info_repository = TABLE

relay_log_info_repository = TABLE

relay_log_recovery = 1 #crash safe

log-bin=mysql-bin

binlog_format=row

sync_binlog =1  #确保事务提交的时候BINLOG落盘

log-slave-updates

log_bin_trust_function_creators =1

binlog_rows_query_log_events=ON  #记录执行的语句到BINLOG query event

 

server-id=1020094

relay_log_purge=0

read_only=1

 

 

 

node95/etc/my.cnf配置文件部分关键地方:

[mysqld]

port            = 3306

socket          = /tmp/mysql.sock

datadir         = /bdata/data/nowdb2

 

innodb_file_per_table=ON

character-set-server = utf8

default_storage_engine = InnoDB

skip-innodb_adaptive_hash_index

 

master_info_repository = TABLE

relay_log_info_repository = TABLE

relay_log_recovery = 1 #crash safe

log-bin=mysql-bin

binlog_format=row

sync_binlog =1  #确保事务提交的时候BINLOG落盘

log-slave-updates

log_bin_trust_function_creators = 1

binlog_rows_query_log_events=ON  #记录执行的语句到BINLOG query event

 

server-id=1020095

relay_log_purge=0

read_only=1

 

 

在node93上创建复制权限的账号,GRANT REPLICATION SLAVE ,REPLICATION CLIENT ON *.* TO 'rpl'@'10.1.%.%' IDENTIFIED BY 'rpl';

然后配置1主2从,(具体步骤略过)。

 

注意:我们要确保能成为主库的节点(node93、node94)都存在主从同步账号,如果node94上不存在rpl账号,就到node94节点去手工添加即可。

 

 

主从关系建立好后,我们在master上创建个mha管理账号,后期会用到:

grant all on *.* to 'mhauser'@'10.1.%.%' identified by 'Abcd@1234';   

(管理账号要在node93、node94、node95所有节点都存在)

 

step2、安装MHA

因为MHA依赖于ssh,因此需要在3台主机之间建立SSH免秘钥登陆。步骤略过。

 

 

3个节点都安装perl包:

yum install perl perl-DBD-MySQL perl-CPAN perl-devel perl-Time-HiRes

 

node93-node95上都安装node包:

rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm

 

node94上安装Manager(当然,我们在3个节点都安装上Manager包也没问题)

rpm -ivh mha4mysql-manager-0.56-0.el6.noarch.rpm

 

 

在node94初始化MHA

mkdir /etc/masterha/

vim /etc/masterha/app1.cnf 内容如下:

[server default]

user=mhauser

passWord=Abcd@1234

manager_workdir=/data/masterha/app1

manager_log=/data/masterha/app1/manager.log

remote_workdir=/data/masterha/app1

ssh_user=root

repl_user=rpl

repl_password=rpl

ping_interval=1

master_binlog_dir=/bdata/data/nowdb2/    # 这个路径和你的mysql的binlog存放路径要一致

 

master_ip_failover_script=/etc/masterha/master_ip_failover

report_script=/etc/masterha/send_report

 

#通过第三方机器确认目标主库是否存活,不是必须的,就算没有也是能用

#secondary_check_script=masterha_secondary_check -s remote_host1 -s remote_host2

 

#故障发生后关闭主机的脚本,不是必须的,但是你要设置为空

# shutdown_script=""

 

 

#手动在线切换VIP脚本,不是必须的,就算没有也是能用,

#如果你有keepalived这种来做切换VIP就可以直接不用了

master_ip_online_change_script==/etc/masterha/master_ip_online_change

 

[server1]

hostname=10.1.20.93

candidate_master=1

 

[server2]

hostname=10.1.20.94

candidate_master=1

 

[server3]

hostname=10.1.20.95

no_master=1   # 禁止

 

 

node94上添加脚本/etc/masterha/master_ip_failover  (里面填写上相关的VIP的信息)

#!/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,

   $orig_master_ssh_port, $new_master_ssh_port

);

 

my $vip ='10.1.20.100';  # Virtual IP

my $devic='eth0';

my $key = "0";

my$net_mask='255.255.255.0';

my $ssh_start_vip ="/sbin/ifconfig $devic:$key $vip netmask $net_mask";

my $ssh_stop_vip ="/sbin/ifconfig $devic:$key down";

my$mysql_conf="/etc/my.cnf";

my $open_readonly="/bin/sed-i 's/.*read_only.*/read_only=1/g' $mysql_conf ";

my $close_readonly="/bin/sed-i 's/.*read_only.*/read_only=0/g' $mysql_conf ";

my $open_relaylog_purge="/bin/sed-i 's/.*relay_log_purge.*/relay_log_purge=0/g' $mysql_conf ";

my$close_relaylog_purge="/bin/sed -i's/.*relay_log_purge.*/relay_log_purge=0/g' $mysql_conf ";

 

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,

   'orig_master_ssh_port=i' => \$orig_master_ssh_port,

   'new_master_host=s'  => \$new_master_host,

   'new_master_ip=s'    =>\$new_master_ip,

   'new_master_port=i'  =>\$new_master_port,

   'new_master_ssh_port=i' => \$new_master_ssh_port,

);

 

exit &main();

 

sub main {

 

   print "\n\nIN SCRIPTTEST====$ssh_stop_vip==$ssh_start_vip===\n\n";

 

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

 

        # $orig_master_host, $orig_master_ip,$orig_master_port are passed.

        # If you manage master ip address atglobal catalog database,

        # invalidate orig_master_ip here.

        my $exit_code = 1;

        eval {

            print "Disabling the VIP onold 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" ) {

 

        # all arguments are passed.

        # If you manage master ip address atglobal 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 {

            print "Enabling the VIP - $vipon 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 thescript.. OK \n";

       # `ssh $ssh_user\@cluster1 \"$ssh_start_vip \"`;

        exit 0;

   }

   else {

        &usage();

        exit 1;

   }

}

 

# A simple system call that enablethe VIP on the new master

sub start_vip() {

   `ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;

   print "Disable read_only and relay_log_purge in my.cnf -  on the new master - $new_master_host\n";

   `ssh $ssh_user\@$new_master_host \" $close_readonly \"`;

   `ssh $ssh_user\@$new_master_host \" $close_relaylog_purge \"`;

   

}

# A simple system call thatdisable the VIP on the old_master

sub stop_vip() {

   `ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;

  print "Enable read_only and relay_log_purge in my.cnf -  on the orig master - $orig_master_host\n";

   `ssh $ssh_user\@$orig_master_host \" $open_readonly \"`;

   `ssh $ssh_user\@$orig_master_host \" $open_relaylog_purge \"`;

}

 

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--orig_master_ssh_port=ssh_port --new_master_ssh_port = ssh_port\n";

}

 

 

node94上添加脚本/etc/masterha/send_report(里面填写上相关的smtp账号的信息)

#!/usr/bin/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 scriptand is not complete. Modify the script based on your environment.

 

use strict;

use warnings FATAL => 'all';

use Mail::Sender;

use Getopt::Long;

 

#new_master_host and new_slave_hostsare set only when recovering master succeeded

my ( $dead_master_host,$new_master_host, $new_slave_hosts, $subject, $body ,$conf);

my$smtp='smtp.exmail.qq.com';

my$mail_from='zabbix@xxxx.com';

my$mail_user='zabbix@xxxx.com';

my $mail_pass='xxxxxxx';

my$mail_to=['lixxxx@xxxx.com'];

GetOptions(

 'orig_master_host=s' => \$dead_master_host,

 'new_master_host=s'  =>\$new_master_host,

 'new_slave_hosts=s'  =>\$new_slave_hosts,

 'subject=s'          =>\$subject,

 'body=s'             => \$body,

 'conf=s'             => \$conf,

);

 

mailToContacts($smtp,$mail_from,$mail_user,$mail_pass,$mail_to,$subject,$body);

check_if_sendmail_ok('/tmp/monitormail.log');

 

sub mailToContacts {

   my ( $smtp, $mail_from, $user, $passwd, $mail_to, $subject, $msg ) = @_;

   open my $DEBUG, "> /tmp/monitormail.log"

        or die "Can't open the debug      file:$!\n";

   my $sender = new Mail::Sender {

        ctype       => 'text/plain; charset=utf-8',

        encoding    => 'utf-8',

        smtp        => $smtp,

        from        => $mail_from,

        auth        => 'LOGIN',

        TLS_allowed => '0',

        authid      => $user,

        authpwd     => $passwd,

        to          => $mail_to,

        subject     => $subject,

        debug       => $DEBUG

   };

 

   $sender->MailMsg(

        {  msg   => $msg,

            debug => $DEBUG

        }

   ) or print $Mail::Sender::Error;

   return 1;

}

 

sub check_if_sendmail_ok{

    #>>250 2.0.0 Ok: queued as 3532C6DA009D

    #<<QUIT

    #>>221 2.0.0 Bye

    my$logf = shift;

    openRLOG, $logf or die "cannot open file $logf.\n";

    my@log = <RLOG>;

    closeRLOG;

    my$val = 0;

    if($log[$#log]=~ m/\>\>\s221\s.*\sBye/){

       print"Meet Bye.\t";

       $val++;

    }

    if($log[$#log-1]=~ m/\<\<\sQUIT/){

       print"Meet QUIT.\t";

       $val++;

    }

    if($log[$#log-2]=~ m/\>\>\s250\s.*\sOk: queued/){

       print"Meet queued.\t";

       $val++;

    }

    print"\n";

    if($val== 3){

       print"send mail success.\n";

    }

    else{

       print"send mail failed.check DNS/SMTP config\n";

    }

    return$val;

}

 

# Do whatever you want here

 

exit 0;

 

 

node94上添加脚本/etc/masterha/master_ip_online_change(里面填写上相关的VIP的信息)

 

#!/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 scriptand 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( sleepgettimeofday 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

);

my $vip ='10.1.20.100/24';

my $key = '0';

my $ssh_start_vip ="/sbin/ifconfig eth0:$key $vip";

my $ssh_stop_vip ="/sbin/ifconfig eth0:$key down";

my $orig_master_ssh_port = 22;

my $new_master_ssh_port = 22;

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,

 'orig_master_ssh_port=i'    =>\$orig_master_ssh_port,

 'new_master_ssh_port=i'    =>\$new_master_ssh_port,

);

 

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 = newMHA::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() . " Setread_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 ifany database error happens

      my $orig_master_handler = newMHA::DBHelper();

     $orig_master_handler->connect($orig_master_ip, $orig_master_port,

        $orig_master_user,$orig_master_password, 1 );

 

      ## Drop application user so that nobodycan connect. Disabling per-session binlog beforehand

      $orig_master_handler->disable_log_bin_local();

      print current_time_us() . " Drppingapp user on the orig master..\n";

     #FIXME_xxx_drop_app_user($orig_master_handler);

 

      ## Waiting for N * 100 milliseconds sothat 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 %dthreads are disconnected.. (max %d milliseconds)\n",

            current_time_us(), $#threads + 1,$time_until_read_only * 100;

          if ( $#threads < 5 ) {

           printData::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 currentmaster so that nobody(except SUPER) can write

      print current_time_us() . " Setread_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 sothat 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 %dqueries 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() . " Killingall 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, MHAexecutes FLUSH TABLES WITH READ LOCK

      eval {

      `ssh -p$orig_master_ssh_port$orig_master_ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;

        };

        if ($@) {

            warn $@;

        }

      $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 eventhough activating updatable accounts/ip failed so that we don't interruptslaves' recovery.

# If exit code is 0 or 10, MHAdoes not abort

   my $exit_code = 10;

   eval {

      my $new_master_handler = newMHA::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() . " Setread_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() . " Creatingapp 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 catalogdatabase, etc

      `ssh -p$new_master_ssh_port$new_master_ssh_user\@$new_master_host \" $ssh_start_vip \"`;

      $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;

}

 

 

 

 

 

 

node94上检查MHA SSH是否配置无误:

    masterha_check_ssh--conf=/etc/masterha/app1.cnf

    如能出现"All SSH connection tests passedsuccessfully." 说明配置没问题

 

node94上检查MHA 的主从复制是否配置无误:

    masterha_check_repl--conf=/etc/masterha/app1.cnf

    如提示"MySQL Replication Health is OK"说明配置没问题

 

node94上前台启动MHA

    masterha_manager--conf=/etc/masterha/app1.cnf --ignore_last_failover  在前台启动监控

 

模拟node93master宕机、观察master的自动切换:

将node93的mysql服务停掉,可以发现此时node94上开启的masterha_manager进程自动退出了,到其他节点去查看,可以发现主从切换了。

 

 

然后启动node93mysql,再次上线就不会自动变成master

【!!注意:直接将node93上线的话,集群中就出现了2个主节点,脑裂,masterha_manger也无法启动】,我们需要先手工将其改为从节点,操作如下:

在node93上,执行:

> change master to

    master_host='10.1.20.94',

    master_user='rpl',

    master_password='rpl',

    master_log_file='mysql-bin.000003',

    master_log_pos=1881;     # 这里的位置,需要看下node94的/data/masterha/app1目录下的manager.log里面的内容找到具体的binlog位置。

 

> start slave;

> show slave status\G

 

将node93 重新加入集群后,我们在node94 manager节点上再次执行 masterha_manager--conf=/etc/masterha/app1.cnf --ignore_last_failover  发现启动不退出了。(验证过程中不要关闭这个窗口)


 

检查下当前主从的配置:

    node94另外开一个xshell窗口,可以执行 masterha_check_repl--conf=/etc/masterha/app1.cnf

    可以看出主节点、从节点的发生了变化:

MHA部署笔记(centos6+mysql5.6)


查看是否masterha启动:

    另外开一个xshell窗口,可以执行 masterha_check_status--conf=/etc/masterha/app1.cnf

MHA部署笔记(centos6+mysql5.6)


如果需要停止masterha的话,不要用stop或者kill,要用下面的命令:

    masterha_stop--conf=/etc/masterha/app1.cnf


手动切换主从的方法:

    masterha_master_switch-h   查看帮助信息

    masterha_master_switch--conf=/etc/masterha/app1.cnf --master_state=alive --new_master_host=10.1.20.93--new_master_port=3306 --orig_master_is_new_slave --running_updates_limit=10000

MHA部署笔记(centos6+mysql5.6)

MHA部署笔记(centos6+mysql5.6)



手工切换的时候需要注意2:

1、执行手工切换的时候,需要先关掉老的master和即将提升为master的主机的 event scheduler,否则无法切换(set global event_scheduler = OFF;)

2、执行手工切换的时候,需要先关闭MHA的监控 masterha_stop--conf=/etc/masterha/app1.cnf )

3、执行手工切换脚本的时候,它会自动在原先的master上执行FLUSH TABLES WITH READ LOCK; 等切换完成后,再UNLOCK TABLES释放掉这个原有master的

          

 

发送邮件的脚本,需要先安装插件:

    yuminstall perl-Mail-Sender

    发送失败的话,可以查看/tmp/monitormail.log 找找失败的原因。

 


MHA异常的话:

    可以查看日志路径:/data/masterha/app1/



masterha_manager 还有几个比较有用的启动参数:

    --remove_dead_master_conf    该参数代表当发生主从切换后,老的主库的ip将会从配置文件中移除。

    --manger_log    日志存放位置,想规范化管理日志可以加上

    --ignore_last_failover    该参数代表忽略上次MHA触发切换产生的文件,默认情况下,MHA发生切换后会在日志目录,也就是上面我设置的/data产生app1.failover.complete文件,下次再次切换的时候如果发现该目录下存在该文件将不允许触发切换,除非在第一次切换后收到删除该文件,在缺省情况下,如果MHA检测到连续发生宕机,且两次宕机间隔不足8小时的话,则不会进行Failover,之所以这样限制是为了避免ping-pong效应。【如果我们需要强制切换的话,需要先移除这个文件app1.failover.complete】

 



您可能感兴趣的文档:

--结束END--

本文标题: MHA部署笔记(centos6+mysql5.6)

本文链接: https://lsjlt.com/news/35676.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • MHA部署笔记(centos6+mysql5.6)
    环境及软件版本:    CentOS6.5x86_64    MySQL5.6.34编译安装版    MHA版本:m...
    99+
    2024-04-02
  • Centos7.1部署mysql-5.6.34(笔记)
    这里安装我用的的是mysql二进制包,主要减少编译安装的时间,当然快的还有yum的安装方式。mysql个版本下载地址:http://mirrors.sohu.com/mysql/ 1、解决相关依赖...
    99+
    2024-04-02
  • 一键部署----mysql5.6--jue
    一键部署----mysql5.6--jue #!/bin/bash cd /var/run rm -rf yum.pid read -p "请输入mysql源码包的绝对路径" c cd $c yum install -y ncurses-d...
    99+
    2020-12-27
    一键部署----mysql5.6--jue 数据库入门 数据库基础教程 数据库 mysql
  • MySQL5.6多实例部署
    无论是迫于预算,亦或者是领导要求,多实例的安装也是DBA必须掌握的技术,她的启停和登录方式和单实例安装数据库略有不同,本文记录下如何完成MySQL5.6多实例部署。首先我们看一下my.cnf和单实例的区分:...
    99+
    2024-04-02
  • Mysql5.6 自动化部署
    主机环境:Centos6.5前提: 配置yum源 移除系统自带的mysql 删除原先的mysql用户 使用mysql二进制安装包:https://dev.mysql.com/downloads/file/id=473278[root@mys...
    99+
    2023-06-06
  • MHA的安装部署
    本篇内容主要讲解“MHA的安装部署”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“MHA的安装部署”吧! MHA 0.56 is n...
    99+
    2024-04-02
  • Mysql MHA部署-04MHA配置
    Mysql MHA部署-04MHA配置 一 Mysql MHA部署-01介绍 二 Mysql MHA部署-02主从复制 三 Mysql MHA部署-03MHA软件安装 四 M...
    99+
    2024-04-02
  • MySQL高可用之MHA部署
    MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,在MySQL故障切换过程中,MHA能做到在0~30秒之内自动完成数据库的故障切换操作,并且在进行...
    99+
    2024-04-02
  • MySql5.6性能优化学习笔记
    目标 了解什么是优化 掌握优化查询的方法 掌握优化数据库结构的方法 掌握优化MySQL服务器的方法 什么是优化? 合理安排资源、调整系统参数使MySQL运行更快、更节省资源。...
    99+
    2024-04-02
  • Mysql MHA部署中怎么进行MHA软件安装
    Mysql MHA部署中怎么进行MHA软件安装,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。Mysql MHA部署-MHA软件...
    99+
    2024-04-02
  • 基于centos6的mysql5.7.13主从部署(二)
    基于centos6的mysql5.7.13主从部署(二)一、部署主mysql说明:mysql1是主机,mysql2是备机。创建库[root@mysql1 ~]# mysql -uroot -p123456m...
    99+
    2024-04-02
  • MySQL MHA高可用环境部署
    一,安装MHA基本环境安装MHA节点(1)基本环境说明角色IP地址主机名     =========================================  ...
    99+
    2024-04-02
  • mysql MHA 高可用架构部署
    MHA简介:即Master High Availability Manager and Tools for MySQL,是日本的一位MySQL专家采用Perl语言编写的一个脚本管理工具, 该工具仅...
    99+
    2024-04-02
  • MHA的安装和部署步骤
    本篇内容介绍了“MHA的安装和部署步骤”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!###########...
    99+
    2024-04-02
  • 基于maxscale的读写分离部署笔记
    使用maxscale搭建的读写分离架构,后期还可以再结合MHA做master的故障转移,这样业务层面上不需要做任何的改动即可。基于connect方式的不要使用。从库延迟他还会继续分发请求过去,暂时不适合生产...
    99+
    2024-04-02
  • 【学习笔记】部署yolov8到安卓手机
    一、环境配置和源码安装 首先你需要配置好pytorch环境,本文不再详细阐述,若未配置好环境,可以参考我的另一篇博客:https://blog.csdn.net/liujiahao123987/article/details/128743...
    99+
    2023-09-03
    python opencv 计算机视觉 人工智能 深度学习 Powered by 金山文档
  • mysql高可用MHA部署全过程
    部署计划mysql_master192.168.2.74centos6.9mysql5.5/mha-nodemysql_salve1192.168.2.75centos6.9mysql5.5/mha-nod...
    99+
    2024-04-02
  • PHP学习笔记:服务器部署与配置
    一、引言在进行PHP开发之前,需要先对服务器进行部署与配置,以确保PHP代码能够正常运行。本篇文章将介绍如何进行服务器部署与配置,并提供具体的代码示例。二、服务器部署选择服务器环境在部署服务器之前,我们需要选择合适的服务器环境。常见的服务器...
    99+
    2023-10-21
    服务器 PHP 配置
  • MySQL 搭建MHA架构部署的步骤
    MAH 一:MAH架构介绍 MHA (Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本人youshimaton开发,是一套优秀的作为MySQL高可用...
    99+
    2022-05-20
    MySQL MHA架构部署 MySQL部署MHA架构
  • 如何部署MHA实现MySQL高可用
    MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,在MySQL故障切换过程中,MHA能做到在0~30秒之内自动完成数据库的故障切换操作,并且在进行...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作