In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
Environment and software version:
CentOS6.5x86_64
MySQL5.6.34 compiled and installed version
MHA version: mha4mysql-manager-0.56-0.el6.noarch.rpm mha4mysql-node-0.56-0.el6.noarch.rpm
Node role:
Node93:10.1.20.93 default main library
Node94:10.1.20.94 slave library 1, which can be upgraded to master library after downtime [mha management node is also deployed on this machine]
Node95:10.1.20.95 slave library 2, promotion to master library is not allowed
The prepared VIP is 10.1.20.100amp 24.
Step1, configure master-slave relationship
The key parts of the / etc/my.cnf configuration file of node93:
[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 # ensure that the BINLOG is down when the transaction is committed
Log-slave-updates
Log_bin_trust_function_creators = 1
Binlog_rows_query_log_events=ON # record the statements executed to BINLOG query event
Server-id=1020093
Relay_log_purge=0
Read_only=1
The key parts of the / etc/my.cnf configuration file of node94:
[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 # ensure that the BINLOG is down when the transaction is committed
Log-slave-updates
Log_bin_trust_function_creators = 1
Binlog_rows_query_log_events=ON # record the statements executed to BINLOG query event
Server-id=1020094
Relay_log_purge=0
Read_only=1
The key parts of the / etc/my.cnf configuration file of node95:
[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 # ensure that the BINLOG is down when the transaction is committed
Log-slave-updates
Log_bin_trust_function_creators = 1
Binlog_rows_query_log_events=ON # record the statements executed to BINLOG query event
Server-id=1020095
Relay_log_purge=0
Read_only=1
Create an account with replication permission on node93, GRANT REPLICATION SLAVE, REPLICATION CLIENT ON *. * TO 'rpl'@'10.1.%.%' IDENTIFIED BY' rpl'
Then configure 1 master and 2 slaves (skip the specific steps).
Note: we need to make sure that the nodes that can become the master library (node93, node94) have master-slave synchronization accounts. If the rpl account does not exist on the node94, you can manually add it to the node94 node.
After the master-slave relationship is established, we create a mha management account on master, which will be used later:
Grant all on *. * to 'mhauser'@'10.1.%.%' identified by' Abcd@1234'
(the management account should exist on all nodes of node93, node94 and node95)
Step2, install MHA
Because MHA depends on SSH, it is necessary to establish a SSH key-free login between the three hosts. Skip the steps.
Install the perl package on all 3 nodes:
Yum install perl perl-DBD-MySQL perl-CPAN perl-devel perl-Time-HiRes
Node packages are installed on node93-node95:
Rpm-ivh mha4mysql-node-0.56-0.el6.noarch.rpm
Install the Manager package on node94 (of course, we have no problem installing the Manager package on all three nodes):
Rpm-ivh mha4mysql-manager-0.56-0.el6.noarch.rpm
Initialize MHA in node94
Mkdir / etc/masterha/
The vim / etc/masterha/app1.cnf content is as follows:
[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/ # this path should be the same as the binlog storage path of your mysql
Master_ip_failover_script=/etc/masterha/master_ip_failover
Report_script=/etc/masterha/send_report
# it is not necessary to confirm whether the target main database is alive through a third-party machine, even if it does not.
# secondary_check_script=masterha_secondary_check-s remote_host1-s remote_host2
# the script to shut down the host after a failure is not necessary, but you need to set it to empty
# shutdown_script= ""
# it is not necessary to manually switch VIP scripts online, even if it is not available
# if you have keepalived to switch VIP, you don't need it.
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 # Forbidden
Add a script / etc/masterha/master_ip_failover to node94 (fill in the relevant VIP information)
#! / 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.100mm; # 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 Placement. Readreadcharts only.Grease Universe 1According to g'$mysql_conf"
My $close_readonly= "/ bin/sed-i 's Placement. Readreadcoat only.Grease Universe 0Accord g'$mysql_conf"
My $open_relaylog_purge= "/ bin/sed-i 's mysql_conf. Relayworthy logically purged.
My$close_relaylog_purge= "/ bin/sed-isignsUniq.Relayment logically purge.UnipletCash relaylogically purgett0Compact 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 {
"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"
}
Add a script / etc/masterha/send_report to node94 (fill in the relevant smtp account information):
#! / 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 fileParticipation!\ 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 {
# > > 2502.0.0 Ok: queued as 3532C6DA009D
# 221 2.0.0 Bye
My$logf = shift
OpenRLOG, $logf or die "cannot open file $logf.\ n"
My@log =
CloseRLOG
My$val = 0
If ($log [$# log] = ~ m /\ >\ >\ s221\ s.*\ sBye/) {
Print "Meet Bye.\ t"
$val++
}
If ($log [$# log-1] = ~ 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
Add the script / etc/masterha/master_ip_online_change to node94 (fill in the relevant VIP information):
#! / 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.100Universe 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 ("d", $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 * (. *?)\ 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 * 100milliseconds 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 > zero & $# 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 Magneol timekeeping untilhands readership 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 * 100milliseconds 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 > zero & $# 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 jigsaw timekeeping untilhorse killers 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."
$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."
$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 {
"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
}
On node94, check that the SSH of MHA is configured correctly:
Masterha_check_ssh--conf=/etc/masterha/app1.cnf
If "All SSH connection tests passedsuccessfully." It means that the configuration is fine.
On node94, check that the master-slave replication of MHA is configured correctly:
Masterha_check_repl--conf=/etc/masterha/app1.cnf
If prompted by "MySQL Replication Health is OK", the configuration is fine.
Start MHA in the foreground on node94:
Masterha_manager--conf=/etc/masterha/app1.cnf-ignore_last_failover starts monitoring at the front desk
Simulate node93master downtime and observe the automatic switching of master:
If you stop the mysql service of node93, you can find that the masterha_manager process opened on the node94 automatically exits. Check to other nodes, and you can find that the master / slave switch has occurred.
Then start the mysql of node93, and it will not automatically become master when it is launched again.
[!! Note: if you directly put the node93 online, there will be two master nodes in the cluster, brain fissure, and the masterha_manger cannot be started. We need to manually change it to a slave node, as follows:
On node93, execute:
> 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; # for the location here, you need to look at the contents of manager.log in the / data/masterha/app1 directory of node94 to find the specific binlog location.
> start slave
> show slave status\ G
After rejoining node93 to the cluster, we execute masterha_manager--conf=/etc/masterha/app1.cnf on the node94 manager node again-- ignore_last_failover finds that startup does not exit. (do not close this window during verification)
Check the current master-slave configuration:
Node94 opens another xshell window, which can execute masterha_check_repl--conf=/etc/masterha/app1.cnf
You can see that the master node and slave node have changed:
Check to see if masterha is started:
Open another xshell window, you can execute masterha_check_status--conf=/etc/masterha/app1.cnf
If you need to stop masterha, do not use stop or kill, use the following command:
Masterha_stop--conf=/etc/masterha/app1.cnf
The method of manually switching between master and slave:
Masterha_master_switch-h View help Information
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
When switching manually, you need to pay attention to 2 points:
1. When performing manual switching, you need to turn off the old master and the event scheduler of the host that is about to be upgraded to master, otherwise you cannot switch (set global event_scheduler = OFF;)
2. When performing manual switching, you need to turn off the monitoring masterha_stop--conf=/etc/masterha/app1.cnf of MHA)
3, when the manual switching script is executed, it will automatically execute FLUSH TABLES WITH READ LOCK; on the original master after the switch is completed, and then UNLOCK TABLES releases the lock of the original master.
To send an email script, you need to install the plug-in first:
Yuminstall perl-Mail-Sender
If the transmission fails, you can check / tmp/monitormail.log to find out the reason for the failure.
If MHA is abnormal:
You can view the log path: / data/masterha/app1/
Masterha_manager also has several useful startup parameters:
-- remove_dead_master_conf this parameter means that when a master-slave switch occurs, the ip of the old master library will be removed from the configuration file.
-- manger_log log storage location. If you want to standardize the management log, you can add it.
-- ignore_last_failover this parameter means that the file generated by the last MHA trigger switch is ignored. By default, after the MHA switch occurs, the app1.failover.complete file will be generated in the log directory, that is, the / data I set above. If the file is found to exist in this directory next time, the switch will not be allowed, unless the file is deleted after the first switch. By default, the switch is not allowed. If MHA detects continuous downtime and the interval between two outages is less than 8 hours, Failover will not occur. This restriction is to avoid the ping-pong effect. [if we need to force switching, we need to remove this file app1.failover.complete first]
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.