Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Basic knowledge of MHA

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Environment: manager: 10.1.99.213 (install mha manager mha node package) installation dependency can use the corresponding version of the machine epel source master: 10.1.99.216 (install mysql and mha node package) node1: 10.1.99.214 (install mysql and mha node package) node2: 10.1.99.215 (install mysql and mha node package)

Dependency: yum install perl-DBD-MySQL yum install perl-Config-Tiny yum install perl-Log-Dispatch yum install perl-Parallel-ForkManager

About the process of MHA failover: ① saves the down master before it has time to transfer the binlog ② to check the latest status of slave, apply differential relay logs to each slave ③ application master binlog to each slave ④ upgrade one slave to the main ⑤ other slave points to the new master

Manager Toolkit: masterha_check_ssh check SSH configuration status of MHA masterha_check_repl check MySQL replication status masterha_manger launch MHA masterha_check_status detect current MHA health masterha_master_monitor detect master down masterha_master_switch control failover (automatic or manual) masterha_conf_host add or remove configured server information

Node toolkit (automatic invocation does not require manual execution):

Save_binary_logs saves and copies binary logs of master

Apply_diff_relay_logs identifies differential relay log events and applies their differential events to other slave

Purge_relay_logs clears relay logs (does not block SQL threads)

Configuration process (app1.conf of mha manager configuration file at the end of the article): mutual trust configuration among ① hosts (sshkey-gen, ssh-copy-I, etc.) Master-slave configuration between ② master and node (replication account repl (replication slave) and management account mha (ALL) are required. Enable log-bin parameter (failover pick-up master can only switch to the machine with this parameter enabled) Node has to configure relay-log-purge=0,read_only=1, etc.) ③ manager configuration file / etc/mha/app1.conf ④ manager ssh check (masterha_check_ssh-- conf=/etc/mha/app1.cnf) ⑤ manager repl check (masterha_check_repl-- conf=/etc/mha/app1.cnf) ⑥ launch mha manager (masterha_manager-- conf=/etc/mha/app1.cnf) do not start in the background Will exit ⑦ to check manager status (masterha_check_status-- conf=/etc/mha/app1.cnf) ⑧ close mha manager (masterha_stop-- conf=/etc/mha/app1.cnf)

Parameter:-- ignore_last_failover: by default, if MHA detects continuous downtime and the interval between two outages is less than 8 hours, Failover will not be performed. This restriction is to avoid ping-pong effect. This parameter means that the files generated by the last MHA trigger switch are 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 you find that the file exists in this directory next time, you will not be allowed to trigger the switch. Unless the file is deleted after the first switch-remove_dead_master_conf: this parameter means that when the master-slave switch occurs, the old master library will be removed from the configuration file. In general, it does not need to be opened.

Processing after Failover: ① starts downtime master ② itself as pointing to the new master (pointing to the content view log to determine cat app1.log | grep-I "change master") ③ starts mha manager ④ if you want to still use the original instance as master, use this command masterha_master_switch to switch manually

Annex app1.conf

Click (here) to collapse or open

# BEGIN# [server default] manager_log=/tmp/app1.logmanager_workdir=/tmpmaster_binlog_dir=/opt/mysqluser=mhapassword=taomeeping_interval=2repl_password=taomeerepl_user=replssh_user=rootmaster_ip_failover_script=/usr/bin/masterha_ip_ failover[server1] hostname=10.1.99.216port= 3306[server2] hostname=10.1.99.215port= 3306[server3] hostname=10.1.99.214port=3306# # END#

Cat masterha_ip_failover

Click (here) to collapse or open

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

My (

$command, $ssh_user, $orig_master_host, $orig_master_ip

$orig_master_port, $new_master_host, $new_master_ip, $new_master_port

);

My $vip = '10.1.99.233ax 24'

My $key ='0'

My $ssh_start_vip = "/ sbin/ifconfig eth0:$key $vip"

My $ssh_stop_vip = "/ sbin/ifconfig eth0:$key down"

My $ssh_Bcast_arp = "/ usr/bin/arping-c 3-A 10.1.99.233"; # ARP reply mode to update neighbors. If not, the server will automatically wait for the vip cache to expire, and the VIP will be unavailable for a certain period of time.

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

);

Exit & main ()

Sub main {

Print "\ n\ nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\ n\ n"

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

My $exit_code = 1

Eval {

Print "Disabling the VIP on old 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") {

My $exit_code = 10

Eval {

Print "Enabling the VIP-$vip on the new master-$new_master_host\ n"

& start_vip ()

# & start_arp ()

$exit_code = 0

}

If ($@) {

Warn $@

Exit $exit_code

}

Exit $exit_code

}

Elsif ($command eq "status") {

Print "Checking the Status of the script.. OK\ n"

Exit 0

}

Else {

& usage ()

Exit 1

}

}

Sub start_vip () {

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

}

Sub start_arp () {

`ssh $ssh_user\ @ $new_master_host\ "$ssh_Bcast_arp\" `

}

Sub stop_vip () {

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

}

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}

Manual switch error report: masterha_master_switch-- master_state=alive-- conf=/etc/mha/app1.cnf

Fri Oct 14 18:22:58 2016-[info] Checking MHA is not monitoring or doing failover.. Fri Oct 14 18:22:58 2016-[error] [/ usr/share/perl5/vendor_perl/MHA/MasterRotate.pm, ln142] Getting advisory lock failed on the current master. MHA Monitor runs on the current master. Stop MHA Manager/Monitor and try again. Fri Oct 14 18:22:58 2016-[error] [/ usr/share/perl5/vendor_perl/MHA/ManagerUtil.pm, ln177] Got ERROR: at / usr/bin/masterha_master_switch line 53.

When you switch MHA manually, you need to turn off masterha_manager, the monitoring tool responsible for automatic switching, before you can complete the manual switch.

Reference: MySQL MHA build & Test

Note: slave needs to set up read_only=1 relay_log_purge=1 scheduled tasks to delete relay_log

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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report