MHAプラグインベースのMySQL高可用性スイッチングアーキテクチャ
一、環境:
CentOS 7+MySQL 5.7+GTIDビジネスシステム:mainBusiness
node1 : 192.168.1.109 port:3109
node2 : 192.168.1.110 port:3110
VIP :192.168.1.88
manager:192.168.1.8
1.背景:
Galera cluster(Mariadb Cluster,GroupReplication,PXC)とKeepAlivedのほか、業界で広く使われているMySQLの高可用性はMHAアーキテクチャです.
MHAの作者はDeNAを離れてFACEBOOKに加入した後、このツールを更新することはめったにありません.
2.インストール:
RPMパッケージのインストール方法は最も簡単ですが、著者らは27日前にライブラリからsuper-read-onlyパラメータを有効にした最適化を追加しました.簡単に言えば、このパラメータを有効にすると、プロファイル内のユーザーが差異トランザクションを適用できないという問題が発生する可能性があります.するとsuper-read-onlyパラメータが開いているかどうかを判断する論理判断が追加され、開いている場合はこのパラメータを閉じてから差異トランザクションを適用して再開します.
そこでここではGithub上の最新のコードをコンパイルする方法でインストールします.アドレス:
https://github.com/yoshinorim/mha4mysql-manager
https://github.com/yoshinorim/mha4mysql-node
node 1とnode 2で:
managerで
プロファイルの内容:
アラームスクリプトの変更:
タイミングクリーンアップrelay logのスクリプトを追加するには、次の手順に従います.
フェイルオーバーVIPスクリプトの変更:
これで、インストールと配置が完全に完了し、運用段階に入りました(必ず3台のホスト間のSSH信頼を完了してください)
実行:
マスターを確認managerの実行状況:
フェイルオーバ:
メインライブラリをシャットダウンし、フェイルオーバ全体を観測するプロセスを行います.
manager側出力は次のとおりです.
フェイルオーバー解析:
1.毎秒MySQLをチェックし、4回連続でMySQLサービスに接続できなくなった後、SSHチェック段階に入り、SSHも通じなくなった後、インスタンスの故障を確認する.障害インスタンスがプライマリ・ライブラリであるため、プライマリ・ライブラリの切り替え操作がトリガーされます.
2.プロファイル情報を再度読み取り、登録されたすべてのインスタンスとその切り替えの好みを取得します.managerノードを閉じ、切り替えスクリプトを有効にして切り替え操作を行います.切り替え操作のロジックは、以前の「masterha_master_switchツールからMHAの切り替えロジックを簡単に分析する」記事で分析したものに近い.
3.マスターライブラリの切り替えに成功したら、切り替えレポートを出力し、/data/mhaでmainBusinessを生成する.failover.completeファイル.次に新しいマスターライブラリに仮想IPのマウントを行い,故障報告メールを送信する.
添付:
2つの前文:
1.relay logを定期的に整理することに注意してください.私は構築が終わった後、直接圧測データの書き込みを行い、大量のrelay logがすべてのハードディスク空間を使い果たした.このとき、ライブラリMySQLサービスから偽死し、MHAのすべてのスクリプトもライブラリからの応答が得られないため、同じように詰まってしまいます.
2.もう一つの簡単なsend_Reportのスクリプト:
メールシステムのインストールスクリプト:
呼び出し方法:
変換元:https://mp.weixin.qq.com/s/52GeT016mENFiMqLRUZj2A
CentOS 7+MySQL 5.7+GTIDビジネスシステム:mainBusiness
node1 : 192.168.1.109 port:3109
node2 : 192.168.1.110 port:3110
VIP :192.168.1.88
manager:192.168.1.8
1.背景:
Galera cluster(Mariadb Cluster,GroupReplication,PXC)とKeepAlivedのほか、業界で広く使われているMySQLの高可用性はMHAアーキテクチャです.
MHAの作者はDeNAを離れてFACEBOOKに加入した後、このツールを更新することはめったにありません.
2.インストール:
RPMパッケージのインストール方法は最も簡単ですが、著者らは27日前にライブラリからsuper-read-onlyパラメータを有効にした最適化を追加しました.簡単に言えば、このパラメータを有効にすると、プロファイル内のユーザーが差異トランザクションを適用できないという問題が発生する可能性があります.するとsuper-read-onlyパラメータが開いているかどうかを判断する論理判断が追加され、開いている場合はこのパラメータを閉じてから差異トランザクションを適用して再開します.
そこでここではGithub上の最新のコードをコンパイルする方法でインストールします.アドレス:
https://github.com/yoshinorim/mha4mysql-manager
https://github.com/yoshinorim/mha4mysql-node
node 1とnode 2で:
#
mkdir -p /data/mha/
#
wget https://codeload.github.com/yoshinorim/mha4mysql-node/zip/master -O /usr/local/src/mha-node.zip
wget https://codeload.github.com/yoshinorim/mha4mysql-manager/zip/master -O /usr/local/src/mha-manager.zip
#
unzip /usr/local/src/mha-manager.zip -d /usr/local/src
unzip /usr/local/src/mha-node.zip -d /usr/local/src
# perl
yum -y install perl perl-ExtUtils-MakeMaker perl-ExtUtils-CBuilder perl-Parallel-ForkManager perl-Config-Tiny
yum -y install 'perl(inc::Module::Install)'
yum -y install 'perl(Test::Without::Module)'
yum -y install 'perl(Log::Dispatch)'
#
cd /usr/local/src/mha4mysql-manager-master/
perl Makefile.PL # y
make &&make install
#
cd /usr/local/src/mha4mysql-node-master/
perl Makefile.PL
make &&make install
#
cp /usr/
# MHA
#node1
mysql --login-path=3109 -e 'create user mha@'192.168.1.8' identified by 'sa123456''
mysql --login-path=3109 -e 'grant all privileges on *.* to mha@'192.168.1.8''
mysql --login-path=3109 -e 'flush privilges'
#node2
mysql --login-path=3110 -e 'create user mha@'192.168.1.8' identified by 'sa123456''
mysql --login-path=3110 -e 'grant all privileges on *.* to mha@'192.168.1.8''
mysql --login-path=3110 -e 'flush privilges'
managerで
#
mkdir -p /data/mha/mainBusiness
#
wget https://codeload.github.com/yoshinorim/mha4mysql-node/zip/master -O /usr/local/src/mha-node.zip
wget https://codeload.github.com/yoshinorim/mha4mysql-manager/zip/master -O /usr/local/src/mha-manager.zip
#
unzip /usr/local/src/mha-manager.zip -d /usr/local/src
unzip /usr/local/src/mha-node.zip -d /usr/local/src
# perl
yum -y install perl perl-ExtUtils-MakeMaker perl-ExtUtils-CBuilder perl-Parallel-ForkManager perl-Config-Tiny
yum -y install 'perl(inc::Module::Install)'
yum -y install 'perl(Test::Without::Module)'
yum -y install 'perl(Log::Dispatch)'
#
cd /usr/local/src/mha4mysql-manager-master/
perl Makefile.PL # y
make &&make install
#
cd /usr/local/src/mha4mysql-node-master/
perl Makefile.PL
make &&make install
#
cp /usr/local/src/mha4mysql-manager-master/samples/conf/* /etc/mha
mv /etc/mha/app1.cnf /etc/mha/mainBusiness.cnf
プロファイルの内容:
manager_workdir=/data/mha/mainBusiness # MHA
manager_log=/data/mha/mainBusiness/manager.log #MHA manager
remote_workdir=/data/mha/ # MHA node
master_binlog_dir= /data/mysql/3109/log/,/data/mysql/3110/log/ # MHA node binlog
#secondary_check_script= masterha_secondary_check -s 192.168.1.109 -s 192.168.1.110
master_ip_failover_script= /etc/mha/master_ip_failover # VIP
master_ip_online_change_script= /etc/mha/master_ip_online_change # VIP
report_script= /etc/mha/send_report #
ping_interval=1 # MHA manager (1 )
[server1]
hostname=192.168.1.109
port=3109
ssh_user=root
ssh_port=22
candidate_master=1 # ,1 ,0
check_repl_delay=0 # ,0 ,1
[server2]
hostname=192.168.1.110
port=3110
ssh_user=root
ssh_port=22
candidate_master=1 # ,1 ,0
check_repl_delay=0 # ,0 ,1
アラームスクリプトの変更:
vim /etc/mha/send_report
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';
use Mail::Sender;
use Getopt::Long;
#new_master_host and new_slave_hosts are set only when recovering master succeeded
my ( $dead_master_host, $new_master_host, $new_slave_hosts, $subject, $body );
my $smtp='smtp.mxhichina.com';
my $mail_from='[email protected]';
my $mail_user='[email protected]';
my $mail_pass='Rl123456';
my $mail_to=['[email protected]','[email protected]'];
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,
);
# Do whatever you want here
mailToContacts($smtp,$mail_from,$mail_user,$mail_pass,$mail_to,$subject,$body);
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:$!
";
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;
}
タイミングクリーンアップrelay logのスクリプトを追加するには、次の手順に従います.
cat >/etc/auto_clean_relay_log.sh<> $log_dir/purge_relay_logs.log 2>&1
crontab -e
0 0 */3 * * sh /etc/auto_clean_relay_log.sh
フェイルオーバーVIPスクリプトの変更:
vim /etc/mha/master_ip_failover
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
use Getopt::Long;
use MHA::DBHelper;
# vip
my $vip = "192.168.1.100";
my $if = "eth0";
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: $@
";
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.
";
$new_master_handler->disable_read_only();
## Creating an app user on the new master
#print "Creating app user on the new master..
";
#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
";
}
vim /etc/mha/master_ip_online_change
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.1.100";
my $if = "eth0";
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 = 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.
";
}
else {
die "Failed!
";
}
$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..
";
print current_time_us() . " drop vip $vip..
";
#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)
",
current_time_us(), $#threads + 1, $time_until_read_only * 100;
if ( $#threads new( [$_] )->Indent(0)->Terse(1)->Dump . "
"
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.
";
}
else {
die "Failed!
";
}
## 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)
",
current_time_us(), $#threads + 1, $time_until_kill_threads * 100;
if ( $#threads new( [$_] )->Indent(0)->Terse(1)->Dump . "
"
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..
";
$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, MHA executes FLUSH TABLES WITH READ LOCK
$exit_code = 0;
};
if ($@) {
warn "Got Error: $@
";
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.
";
$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..
";
print current_time_us() . "Add vip $vip on $if..
";
# 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: $@
";
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
";
die;
}
これで、インストールと配置が完全に完了し、運用段階に入りました(必ず3台のホスト間のSSH信頼を完了してください)
実行:
masterha_manager --conf=/etc/mha/mainBusiness.cnf &
マスターを確認managerの実行状況:
masterha_check_status --conf=/etc/mha/mainBusiness.cnf
フェイルオーバ:
メインライブラリをシャットダウンし、フェイルオーバ全体を観測するプロセスを行います.
[g:\~]$ Connecting to 192.168.1.110:22...
Could not connect to '192.168.1.110' (port 22): Connection failed.
Type `help' to learn how to use Xshell prompt.
manager側出力は次のとおりです.
Sun Feb 4 12:26:46 2018 - [info] Starting ping health check on 192.168.1.110(192.168.1.110:3110)..
Sun Feb 4 12:26:46 2018 - [info] Ping(SELECT) succeeded, waiting until MySQL doesn't respond..
Sun Feb 4 12:30:41 2018 - [warning] Got error on MySQL select ping: 2006 (MySQL server has gone away)
Sun Feb 4 12:30:41 2018 - [info] Executing SSH check script: exit 0
Sun Feb 4 12:30:41 2018 - [warning] HealthCheck: SSH to 192.168.1.110 is NOT reachable.
Sun Feb 4 12:30:43 2018 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.1.110' (4))
Sun Feb 4 12:30:43 2018 - [warning] Connection failed 2 time(s)..
Sun Feb 4 12:30:44 2018 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.1.110' (4))
Sun Feb 4 12:30:44 2018 - [warning] Connection failed 3 time(s)..
Sun Feb 4 12:30:45 2018 - [warning] Got error on MySQL connect: 2003 (Can't connect to MySQL server on '192.168.1.110' (4))
Sun Feb 4 12:30:45 2018 - [warning] Connection failed 4 time(s)..
Sun Feb 4 12:30:45 2018 - [warning] Master is not reachable from health checker!
Sun Feb 4 12:30:45 2018 - [warning] Master 192.168.1.110(192.168.1.110:3110) is not reachable!
Sun Feb 4 12:30:45 2018 - [warning] SSH is NOT reachable.
Sun Feb 4 12:30:45 2018 - [info] Connecting to a master server failed. Reading configuration file /etc/masterha_default.cnf and /etc/mha/mainBusiness.cnf again, and trying to connect to all servers to check server status..
Sun Feb 4 12:30:45 2018 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sun Feb 4 12:30:45 2018 - [info] Reading application default configuration from /etc/mha/mainBusiness.cnf..
Sun Feb 4 12:30:45 2018 - [info] Reading server configuration from /etc/mha/mainBusiness.cnf..
Sun Feb 4 12:30:46 2018 - [info] GTID failover mode = 1
Sun Feb 4 12:30:46 2018 - [info] Dead Servers:
Sun Feb 4 12:30:46 2018 - [info] 192.168.1.110(192.168.1.110:3110)
Sun Feb 4 12:30:46 2018 - [info] Alive Servers:
Sun Feb 4 12:30:46 2018 - [info] 192.168.1.109(192.168.1.109:3109)
Sun Feb 4 12:30:46 2018 - [info] Alive Slaves:
Sun Feb 4 12:30:46 2018 - [info] 192.168.1.109(192.168.1.109:3109) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled
Sun Feb 4 12:30:46 2018 - [info] GTID ON
Sun Feb 4 12:30:46 2018 - [info] Replicating from 192.168.1.110(192.168.1.110:3110)
Sun Feb 4 12:30:46 2018 - [info] Primary candidate for the new Master (candidate_master is set)
Sun Feb 4 12:30:46 2018 - [info] Checking slave configurations..
Sun Feb 4 12:30:46 2018 - [info] Checking replication filtering settings..
Sun Feb 4 12:30:46 2018 - [info] Replication filtering check ok.
Sun Feb 4 12:30:46 2018 - [info] Master is down!
Sun Feb 4 12:30:46 2018 - [info] Terminating monitoring script.
Sun Feb 4 12:30:46 2018 - [info] Got exit code 20 (Master dead).
Sun Feb 4 12:30:46 2018 - [info] MHA::MasterFailover version 0.57.
Sun Feb 4 12:30:46 2018 - [info] Starting master failover.
Sun Feb 4 12:30:46 2018 - [info]
Sun Feb 4 12:30:46 2018 - [info] * Phase 1: Configuration Check Phase..
Sun Feb 4 12:30:46 2018 - [info]
Sun Feb 4 12:30:47 2018 - [info] GTID failover mode = 1
Sun Feb 4 12:30:47 2018 - [info] Dead Servers:
Sun Feb 4 12:30:47 2018 - [info] 192.168.1.110(192.168.1.110:3110)
Sun Feb 4 12:30:47 2018 - [info] Checking master reachability via MySQL(double check)...
Sun Feb 4 12:30:48 2018 - [info] ok.
Sun Feb 4 12:30:48 2018 - [info] Alive Servers:
Sun Feb 4 12:30:48 2018 - [info] 192.168.1.109(192.168.1.109:3109)
Sun Feb 4 12:30:48 2018 - [info] Alive Slaves:
Sun Feb 4 12:30:48 2018 - [info] 192.168.1.109(192.168.1.109:3109) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled
Sun Feb 4 12:30:48 2018 - [info] GTID ON
Sun Feb 4 12:30:48 2018 - [info] Replicating from 192.168.1.110(192.168.1.110:3110)
Sun Feb 4 12:30:48 2018 - [info] Primary candidate for the new Master (candidate_master is set)
Sun Feb 4 12:30:48 2018 - [info] Starting GTID based failover.
Sun Feb 4 12:30:48 2018 - [info]
Sun Feb 4 12:30:48 2018 - [info] ** Phase 1: Configuration Check Phase completed.
Sun Feb 4 12:30:48 2018 - [info]
Sun Feb 4 12:30:48 2018 - [info] * Phase 2: Dead Master Shutdown Phase..
Sun Feb 4 12:30:48 2018 - [info]
Sun Feb 4 12:30:48 2018 - [info] Forcing shutdown so that applications never connect to the current master..
Sun Feb 4 12:30:48 2018 - [info] Executing master IP deactivation script:
Sun Feb 4 12:30:48 2018 - [info] /etc/mha/master_ip_failover --orig_master_host=192.168.1.110 --orig_master_ip=192.168.1.110 --orig_master_port=3110 --command=stop
Sun Feb 4 12:30:48 2018 - [info] done.
Sun Feb 4 12:30:48 2018 - [warning] shutdown_script is not set. Skipping explicit shutting down of the dead master.
Sun Feb 4 12:30:48 2018 - [info] * Phase 2: Dead Master Shutdown Phase completed.
Sun Feb 4 12:30:48 2018 - [info]
Sun Feb 4 12:30:48 2018 - [info] * Phase 3: Master Recovery Phase..
Sun Feb 4 12:30:48 2018 - [info]
Sun Feb 4 12:30:48 2018 - [info] * Phase 3.1: Getting Latest Slaves Phase..
Sun Feb 4 12:30:48 2018 - [info]
Sun Feb 4 12:30:48 2018 - [info] The latest binary log file/position on all slaves is 3110binlog.000073:234
Sun Feb 4 12:30:48 2018 - [info] Latest slaves (Slaves that received relay log files to the latest):
Sun Feb 4 12:30:48 2018 - [info] 192.168.1.109(192.168.1.109:3109) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled
Sun Feb 4 12:30:48 2018 - [info] GTID ON
Sun Feb 4 12:30:48 2018 - [info] Replicating from 192.168.1.110(192.168.1.110:3110)
Sun Feb 4 12:30:48 2018 - [info] Primary candidate for the new Master (candidate_master is set)
Sun Feb 4 12:30:48 2018 - [info] The oldest binary log file/position on all slaves is 3110binlog.000073:234
Sun Feb 4 12:30:48 2018 - [info] Oldest slaves:
Sun Feb 4 12:30:48 2018 - [info] 192.168.1.109(192.168.1.109:3109) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled
Sun Feb 4 12:30:48 2018 - [info] GTID ON
Sun Feb 4 12:30:48 2018 - [info] Replicating from 192.168.1.110(192.168.1.110:3110)
Sun Feb 4 12:30:48 2018 - [info] Primary candidate for the new Master (candidate_master is set)
Sun Feb 4 12:30:48 2018 - [info]
Sun Feb 4 12:30:48 2018 - [info] * Phase 3.3: Determining New Master Phase..
Sun Feb 4 12:30:48 2018 - [info]
Sun Feb 4 12:30:48 2018 - [info] Searching new master from slaves..
Sun Feb 4 12:30:48 2018 - [info] Candidate masters from the configuration file:
Sun Feb 4 12:30:48 2018 - [info] 192.168.1.109(192.168.1.109:3109) Version=5.7.19-log (oldest major version between slaves) log-bin:enabled
Sun Feb 4 12:30:48 2018 - [info] GTID ON
Sun Feb 4 12:30:48 2018 - [info] Replicating from 192.168.1.110(192.168.1.110:3110)
Sun Feb 4 12:30:48 2018 - [info] Primary candidate for the new Master (candidate_master is set)
Sun Feb 4 12:30:48 2018 - [info] Non-candidate masters:
Sun Feb 4 12:30:48 2018 - [info] Searching from candidate_master slaves which have received the latest relay log events..
Sun Feb 4 12:30:48 2018 - [info] New master is 192.168.1.109(192.168.1.109:3109)
Sun Feb 4 12:30:48 2018 - [info] Starting master failover..
Sun Feb 4 12:30:48 2018 - [info]
From:
192.168.1.110(192.168.1.110:3110) (current master)
+--192.168.1.109(192.168.1.109:3109)
To:
192.168.1.109(192.168.1.109:3109) (new master)
Sun Feb 4 12:30:48 2018 - [info]
Sun Feb 4 12:30:48 2018 - [info] * Phase 3.3: New Master Recovery Phase..
Sun Feb 4 12:30:48 2018 - [info]
Sun Feb 4 12:30:48 2018 - [info] Waiting all logs to be applied..
Sun Feb 4 12:30:48 2018 - [info] done.
Sun Feb 4 12:30:48 2018 - [info] Getting new master's binlog name and position..
Sun Feb 4 12:30:48 2018 - [info] 3109binlog.000089:234
Sun Feb 4 12:30:48 2018 - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.1.109', MASTER_PORT=3109, MASTER_AUTO_POSITION=1, MASTER_USER='repl', MASTER_PASSWORD='xxx';
Sun Feb 4 12:30:48 2018 - [info] Master Recovery succeeded. File:Pos:Exec_Gtid_Set: 3109binlog.000089, 234, 2285de8a-9bc2-11e7-8a15-000c298e9a6f:1-14,
28ea40ab-9bbd-11e7-8cd1-000c29c31069:1-15308048
Sun Feb 4 12:30:48 2018 - [info] Executing master IP activate script:
Sun Feb 4 12:30:48 2018 - [info] /etc/mha/master_ip_failover --command=start --ssh_user=root --orig_master_host=192.168.1.110 --orig_master_ip=192.168.1.110 --orig_master_port=3110 --new_master_host=192.168.1.109 --new_master_ip=192.168.1.109 --new_master_port=3109 --new_master_user='mha' --new_master_password=xxx
Set read_only=0 on the new master.
ssh: connect to host 192.168.1.110 port 22: Connection timed out
Sun Feb 4 12:31:35 2018 - [info] OK.
Sun Feb 4 12:31:35 2018 - [info] ** Finished master recovery successfully.
Sun Feb 4 12:31:35 2018 - [info] * Phase 3: Master Recovery Phase completed.
Sun Feb 4 12:31:35 2018 - [info]
Sun Feb 4 12:31:35 2018 - [info] * Phase 4: Slaves Recovery Phase..
Sun Feb 4 12:31:35 2018 - [info]
Sun Feb 4 12:31:35 2018 - [info]
Sun Feb 4 12:31:35 2018 - [info] * Phase 4.1: Starting Slaves in parallel..
Sun Feb 4 12:31:35 2018 - [info]
Sun Feb 4 12:31:35 2018 - [info] All new slave servers recovered successfully.
Sun Feb 4 12:31:35 2018 - [info]
Sun Feb 4 12:31:35 2018 - [info] * Phase 5: New master cleanup phase..
Sun Feb 4 12:31:35 2018 - [info]
Sun Feb 4 12:31:35 2018 - [info] Resetting slave info on the new master..
Sun Feb 4 12:31:35 2018 - [info] 192.168.1.109: Resetting slave info succeeded.
Sun Feb 4 12:31:35 2018 - [info] Master failover to 192.168.1.109(192.168.1.109:3109) completed successfully.
Sun Feb 4 12:31:35 2018 - [info]
----- Failover Report -----
mainBusiness: MySQL Master failover 192.168.1.110(192.168.1.110:3110) to 192.168.1.109(192.168.1.109:3109) succeeded
Master 192.168.1.110(192.168.1.110:3110) is down!
Check MHA Manager logs at Client-Cent7-IP008:/data/mha/mainBusiness/manager.log for details.
Started automated(non-interactive) failover.
Invalidated master IP address on 192.168.1.110(192.168.1.110:3110)
Selected 192.168.1.109(192.168.1.109:3109) as a new master.
192.168.1.109(192.168.1.109:3109): OK: Applying all logs succeeded.
192.168.1.109(192.168.1.109:3109): OK: Activated master IP address.
192.168.1.109(192.168.1.109:3109): Resetting slave info succeeded.
Master failover to 192.168.1.109(192.168.1.109:3109) completed successfully.
Sun Feb 4 12:31:35 2018 - [info] Sending mail..
Option new_slave_hosts requires an argument # , , , 。
Unknown option: conf
フェイルオーバー解析:
1.毎秒MySQLをチェックし、4回連続でMySQLサービスに接続できなくなった後、SSHチェック段階に入り、SSHも通じなくなった後、インスタンスの故障を確認する.障害インスタンスがプライマリ・ライブラリであるため、プライマリ・ライブラリの切り替え操作がトリガーされます.
2.プロファイル情報を再度読み取り、登録されたすべてのインスタンスとその切り替えの好みを取得します.managerノードを閉じ、切り替えスクリプトを有効にして切り替え操作を行います.切り替え操作のロジックは、以前の「masterha_master_switchツールからMHAの切り替えロジックを簡単に分析する」記事で分析したものに近い.
3.マスターライブラリの切り替えに成功したら、切り替えレポートを出力し、/data/mhaでmainBusinessを生成する.failover.completeファイル.次に新しいマスターライブラリに仮想IPのマウントを行い,故障報告メールを送信する.
添付:
2つの前文:
1.relay logを定期的に整理することに注意してください.私は構築が終わった後、直接圧測データの書き込みを行い、大量のrelay logがすべてのハードディスク空間を使い果たした.このとき、ライブラリMySQLサービスから偽死し、MHAのすべてのスクリプトもライブラリからの応答が得られないため、同じように詰まってしまいます.
2.もう一つの簡単なsend_Reportのスクリプト:
vim /etc/mha/mha_error.sh
#!/bin/sh
SYSTEM=$1
echo $1 'mha error,please check it immediately!'|mail -s 'mha error' [email protected]
メールシステムのインストールスクリプト:
printf " mail "
yum -y install sendmail* > /dev/null 2>&1
yum -y install mailx > /dev/null 2>&1
printf "\033[32;1m%20s\033[0m
" "[ OK ]"
printf " "
cat > /etc/mail.rc< /dev/null 2>&1
printf "\033[32;1m%20s\033[0m
" "[ OK ]"
printf " "
systemctl restart sendmail > /dev/null 2>&1
printf "\033[32;1m%20s\033[0m
" "[ OK ]"
printf " "
hostname |mail -s "test" [email protected]
printf "\033[32;1m%20s\033[0m
" "[ OK ]"
呼び出し方法:
/etc/mha/mah_error.sh mainBusiness
変換元:https://mp.weixin.qq.com/s/52GeT016mENFiMqLRUZj2A