MySQL高可用方案 MHA之三 master_ip_online_change
主从架构
master:
10.150.20.90 ed3jrdba90
slave:
10.150.20.97 ed3jrdba97
10.150.20.132 ed3jrdba132
manager:
10.150.20.95 ed3jrdba95
vip:
10.150.20.200
master_ip_online_change参数
mha manager 节点上
# vi /etc/mysql_mha/app1.cnf
#手动switchover时候的切换脚本
master_ip_online_change_script= /usr/local/bin/master_ip_online_change
master_ip_online_change_script 指的是手动执行mysql master switchover时执行的切换脚本。
# cat /etc/mysql_mha/app1.cnf
[server default]
manager_log=/data/mysql_mha/app1-manager.log
manager_workdir=/data/mysql_mha/app1
master_binlog_dir=/data/mysql_33061/logs
master_ip_online_change_script= /usr/local/bin/master_ip_online_change
password=mha_monitor
ping_interval=5
remote_workdir=/data/mysql_mha/app1
repl_password=replicator
repl_user=replicator
shutdown_script=""
ssh_user=root
user=mha_monitor
[server1]
hostname=10.150.20.90
port=33061
[server2]
hostname=10.150.20.97
port=33061
[server3]
hostname=10.150.20.132
port=33061
编辑master_ip_online_change脚本,没有使用 keepalived ,通过脚本的方式管理vip
cat /usr/local/bin/master_ip_online_change
#!/usr/bin/env perl 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;
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.150.20.200';
my $brdc = '10.150.20.255';
my $ifdev = 'ens3';
my $key = '';
my $ssh_start_vip = "/usr/sbin/ip addr add $vip/24 brd $brdc dev $ifdev label $ifdev:$key;/usr/sbin/arping -q -A -c 1 -I $ifdev $vip;iptables -F;";
my $ssh_stop_vip = "/usr/sbin/ip addr del $vip/24 dev $ifdev label $ifdev:$key"; 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 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 = unless ($running_time_threshold);
$type = 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*$/$/ 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 >= ); if ( $type >= ) {
next if ( defined($command) && $command eq "Sleep" );
next if ( defined($command) && $command eq "Connect" );
} if ( $type >= ) {
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
# . Set read_only= on the new master
# . DROP USER so that no app user can establish new connections
# . Set read_only= on the current master
# . Kill current queries
# * Any database access failure will result in script die.
my $exit_code = ;
eval {
## Setting read_only= 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, );
print current_time_us() . " Set read_only on the new master.. ";
$new_master_handler->enable_read_only();
if ( $new_master_handler->is_read_only() ) {
print "ok.\n";
}
else {
die "Failed!\n";
}
$new_master_handler->disconnect(); # Connecting to the orig master, die if any database error happens
my $orig_master_handler = new MHA::DBHelper();
$orig_master_handler->connect( $orig_master_ip, $orig_master_port,
$orig_master_user, $orig_master_password, ); ## Drop application user so that nobody can connect. Disabling per-session binlog beforehand
#$orig_master_handler->disable_log_bin_local();
#print current_time_us() . " Drpping app user on the orig master..\n";
#FIXME_xxx_drop_app_user($orig_master_handler); ## Waiting for N * milliseconds so that current connections can exit
my $time_until_read_only = ;
$_tstart = [gettimeofday];
my @threads = get_threads_util( $orig_master_handler->{dbh},
$orig_master_handler->{connection_id} );
while ( $time_until_read_only > && $#threads >= ) {
if ( $time_until_read_only % == ) {
printf
"%s Waiting all running %d threads are disconnected.. (max %d milliseconds)\n",
current_time_us(), $#threads + , $time_until_read_only * ;
if ( $#threads < ) {
print Data::Dumper->new( [$_] )->Indent()->Terse()->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= on the current master so that nobody(except SUPER) can write
print current_time_us() . " Set read_only=1 on the orig master.. ";
$orig_master_handler->enable_read_only();
if ( $orig_master_handler->is_read_only() ) {
print "ok.\n";
}
else {
die "Failed!\n";
} ## Waiting for M * milliseconds so that current update queries can complete
my $time_until_kill_threads = ;
@threads = get_threads_util( $orig_master_handler->{dbh},
$orig_master_handler->{connection_id} );
while ( $time_until_kill_threads > && $#threads >= ) {
if ( $time_until_kill_threads % == ) {
printf
"%s Waiting all running %d queries are disconnected.. (max %d milliseconds)\n",
current_time_us(), $#threads + , $time_until_kill_threads * ;
if ( $#threads < ) {
print Data::Dumper->new( [$_] )->Indent()->Terse()->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} );
} print "Disabling the VIP on old master: $orig_master_host \n";
&stop_vip(); ## Terminating all threads
print current_time_us() . " Killing all application threads..\n";
$orig_master_handler->kill_threads(@threads) if ( $#threads >= );
print current_time_us() . " done.\n";
#$orig_master_handler->enable_log_bin_local();
$orig_master_handler->disconnect(); ## After finishing the script, MHA executes FLUSH TABLES WITH READ LOCK
$exit_code = ;
};
if ($@) {
warn "Got Error: $@\n";
exit $exit_code;
}
exit $exit_code;
}
elsif ( $command eq "start" ) {
## Activating master ip on the new master
# . Create app user with write privileges
# . Moving backup script if needed
# . 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 or , MHA does not abort
my $exit_code = ;
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, ); ## Set read_only= on the new master
#$new_master_handler->disable_log_bin_local();
print current_time_us() . " Set read_only=0 on the new master.\n";
$new_master_handler->disable_read_only(); ## Creating an app user on the new master
#print current_time_us() . " Creating app user on the new master..\n";
#FIXME_xxx_create_app_user($new_master_handler);
#$new_master_handler->enable_log_bin_local();
$new_master_handler->disconnect(); ## Update master ip on the catalog database, etc
print "Enabling the VIP - $vip on the new master - $new_master_host \n";
&start_vip();
$exit_code = ;
};
if ($@) {
warn "Got Error: $@\n";
exit $exit_code;
}
exit $exit_code;
}
elsif ( $command eq "status" ) { # do nothing
exit ;
}
else {
&usage();
exit ;
}
} # A simple system call that enable the VIP on the new master
sub start_vip() {
`ssh $new_master_ssh_user\@$new_master_host \" $ssh_start_vip \"`;
}
# A simple system call that disable the VIP on the old_master
sub stop_vip() {
`ssh $orig_master_ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;
} sub usage {
"Usage: master_ip_online_change --command=start|stop|status --orig_master_host=host --orig_master_ip=ip --orig_master_port=port --orig_master_user=user --orig_master_password=password --orig_master_ssh_user=sshuser --new_master_host=host --new_master_ip=ip --new_master_port=port --new_master_user=user --new_master_password=password --new_master_ssh_user=sshuser \n";
die;
}
master_ip_online_change
更换ip后,一定要执行下 arping
验证 switchover
手动切换之前先停止 mha manager
关闭 mha manager
#masterha_stop --conf=/etc/mysql_mha/app1.cnf
查看 manager status
# masterha_check_status --conf=/etc/mysql_mha/app1.cnf
app1 is stopped(2:NOT_RUNNING).
查看 manager log
# tail -n 1000 -f /data/mysql_mha/app1-manager.log
检查复制环境ssh
# masterha_check_ssh --conf=/etc/mysql_mha/app1.cnf
检查整个复制环境
# masterha_check_repl --conf=/etc/mysql_mha/app1.cnf
手动执行
目前,ed3jrdba90目前是 master,ed3jrdba97是ed3jrdba90的 slave, 切换将ed3jrdba97为master,ed3jrdba90为slave。
# masterha_master_switch --conf=/etc/mysql_mha/app1.cnf --master_state=alive --orig_master_is_new_slave --new_master_host=10.150.20.97 --new_master_port=33061 --running_updates_limit=10000
# masterha_master_switch --conf=/etc/mysql_mha/app1.cnf --master_state=alive --orig_master_is_new_slave --new_master_host=10.150.20.97 --new_master_port= --running_updates_limit=
Wed Dec :: - [info] MHA::MasterRotate version 0.58.
Wed Dec :: - [info] Starting online master switch..
Wed Dec :: - [info]
Wed Dec :: - [info] * Phase : Configuration Check Phase..
Wed Dec :: - [info]
Wed Dec :: - [info] Reading default configuration from /etc/masterha_default.cnf..
Wed Dec :: - [info] Reading application default configuration from /etc/mysql_mha/app1.cnf..
Wed Dec :: - [info] Reading server configuration from /etc/mysql_mha/app1.cnf..
Wed Dec :: - [info] GTID failover mode =
Wed Dec :: - [info] Current Alive Master: 10.150.20.90(10.150.20.90:)
Wed Dec :: - [info] Alive Slaves:
Wed Dec :: - [info] 10.150.20.97(10.150.20.97:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Wed Dec :: - [info] Replicating from 10.150.20.90(10.150.20.90:)
Wed Dec :: - [info] 10.150.20.132(10.150.20.132:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Wed Dec :: - [info] Replicating from 10.150.20.90(10.150.20.90:) It is better to execute FLUSH NO_WRITE_TO_BINLOG TABLES on the master before switching. Is it ok to execute on 10.150.20.90(10.150.20.90:)? (YES/no): YES
Wed Dec :: - [info] Executing FLUSH NO_WRITE_TO_BINLOG TABLES. This may take long time..
Wed Dec :: - [info] ok.
Wed Dec :: - [info] Checking MHA is not monitoring or doing failover..
Wed Dec :: - [info] Checking replication health on 10.150.20.97..
Wed Dec :: - [info] ok.
Wed Dec :: - [info] Checking replication health on 10.150.20.132..
Wed Dec :: - [info] ok.
Wed Dec :: - [info] 10.150.20.97 can be new master.
Wed Dec :: - [info]
From:
10.150.20.90(10.150.20.90:) (current master)
+--10.150.20.97(10.150.20.97:)
+--10.150.20.132(10.150.20.132:) To:
10.150.20.97(10.150.20.97:) (new master)
+--10.150.20.132(10.150.20.132:)
+--10.150.20.90(10.150.20.90:) Starting master switch from 10.150.20.90(10.150.20.90:) to 10.150.20.97(10.150.20.97:)? (yes/NO): yes
Wed Dec :: - [info] Checking whether 10.150.20.97(10.150.20.97:) is ok for the new master..
Wed Dec :: - [info] ok.
Wed Dec :: - [info] 10.150.20.90(10.150.20.90:): SHOW SLAVE STATUS returned empty result. To check replication filtering rules, temporarily executing CHANGE MASTER to a dummy host.
Wed Dec :: - [info] 10.150.20.90(10.150.20.90:): Resetting slave pointing to the dummy host.
Wed Dec :: - [info] ** Phase : Configuration Check Phase completed.
Wed Dec :: - [info]
Wed Dec :: - [info] * Phase : Rejecting updates Phase..
Wed Dec :: - [info]
Wed Dec :: - [info] Executing master ip online change script to disable write on the current master:
Wed Dec :: - [info] /usr/local/bin/master_ip_online_change --command=stop --orig_master_host=10.150.20.90 --orig_master_ip=10.150.20.90 --orig_master_port= --orig_master_user='mha_monitor' --new_master_host=10.150.20.97 --new_master_ip=10.150.20.97 --new_master_port= --new_master_user='mha_monitor' --orig_master_ssh_user=root --new_master_ssh_user=root --orig_master_is_new_slave --orig_master_password=xxx --new_master_password=xxx
Wed Dec :: Set read_only on the new master.. ok.
Wed Dec :: Set read_only= on the orig master.. ok.
Disabling the VIP on old master: 10.150.20.90
Wed Dec :: Killing all application threads..
Wed Dec :: done.
Wed Dec :: - [info] ok.
Wed Dec :: - [info] Locking all tables on the orig master to reject updates from everybody (including root):
Wed Dec :: - [info] Executing FLUSH TABLES WITH READ LOCK..
Wed Dec :: - [info] ok.
Wed Dec :: - [info] Orig master binlog:pos is mysql-bin.:.
Wed Dec :: - [info] Waiting to execute all relay logs on 10.150.20.97(10.150.20.97:)..
Wed Dec :: - [info] master_pos_wait(mysql-bin.:) completed on 10.150.20.97(10.150.20.97:). Executed events.
Wed Dec :: - [info] done.
Wed Dec :: - [info] Getting new master's binlog name and position..
Wed Dec :: - [info] mysql-bin.:
Wed Dec :: - [info] All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='10.150.20.97', MASTER_PORT=, MASTER_LOG_FILE='mysql-bin.000014', MASTER_LOG_POS=, MASTER_USER='replicator', MASTER_PASSWORD='xxx';
Wed Dec :: - [info] Executing master ip online change script to allow write on the new master:
Wed Dec :: - [info] /usr/local/bin/master_ip_online_change --command=start --orig_master_host=10.150.20.90 --orig_master_ip=10.150.20.90 --orig_master_port= --orig_master_user='mha_monitor' --new_master_host=10.150.20.97 --new_master_ip=10.150.20.97 --new_master_port= --new_master_user='mha_monitor' --orig_master_ssh_user=root --new_master_ssh_user=root --orig_master_is_new_slave --orig_master_password=xxx --new_master_password=xxx
Wed Dec :: Set read_only= on the new master.
Enabling the VIP - 10.150.20.200 on the new master - 10.150.20.97
Wed Dec :: - [info] ok.
Wed Dec :: - [info]
Wed Dec :: - [info] * Switching slaves in parallel..
Wed Dec :: - [info]
Wed Dec :: - [info] -- Slave switch on host 10.150.20.132(10.150.20.132:) started, pid:
Wed Dec :: - [info]
Wed Dec :: - [info] Log messages from 10.150.20.132 ...
Wed Dec :: - [info]
Wed Dec :: - [info] Waiting to execute all relay logs on 10.150.20.132(10.150.20.132:)..
Wed Dec :: - [info] master_pos_wait(mysql-bin.:) completed on 10.150.20.132(10.150.20.132:). Executed events.
Wed Dec :: - [info] done.
Wed Dec :: - [info] Resetting slave 10.150.20.132(10.150.20.132:) and starting replication from the new master 10.150.20.97(10.150.20.97:)..
Wed Dec :: - [info] Executed CHANGE MASTER.
Wed Dec :: - [info] Slave started.
Wed Dec :: - [info] End of log messages from 10.150.20.132 ...
Wed Dec :: - [info]
Wed Dec :: - [info] -- Slave switch on host 10.150.20.132(10.150.20.132:) succeeded.
Wed Dec :: - [info] Unlocking all tables on the orig master:
Wed Dec :: - [info] Executing UNLOCK TABLES..
Wed Dec :: - [info] ok.
Wed Dec :: - [info] Starting orig master as a new slave..
Wed Dec :: - [info] Resetting slave 10.150.20.90(10.150.20.90:) and starting replication from the new master 10.150.20.97(10.150.20.97:)..
Wed Dec :: - [info] Executed CHANGE MASTER.
Wed Dec :: - [info] Slave started.
Wed Dec :: - [info] All new slave servers switched successfully.
Wed Dec :: - [info]
Wed Dec :: - [info] * Phase : New master cleanup phase..
Wed Dec :: - [info]
Wed Dec :: - [info] 10.150.20.97: Resetting slave info succeeded.
Wed Dec :: - [info] Switching master to 10.150.20.97(10.150.20.97:) completed successfully.
切换过程
此时,查看新主ed3jrdba97的信息
# ifconfig ens3:1
ens3:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.150.20.200 netmask 255.255.255.0 broadcast 10.150.20.255
ether 54:52:00:49:48:92 txqueuelen 1000 (Ethernet)
root@(none) 04:50:08>show processlist;
+----+------------+---------------------+------+-------------+------+---------------------------------------------------------------+------------------+
| Id | User | Host | db | Command | Time | State | Info |
+----+------------+---------------------+------+-------------+------+---------------------------------------------------------------+------------------+
| 13 | root | localhost | NULL | Sleep | 755 | | NULL |
| 36 | replicator | 10.150.20.132:38717 | NULL | Binlog Dump | 79 | Master has sent all binlog to slave; waiting for more updates | NULL |
| 37 | replicator | 10.150.20.90:15003 | NULL | Binlog Dump | 78 | Master has sent all binlog to slave; waiting for more updates | NULL |
| 38 | root | localhost | NULL | Query | 0 | starting | show processlist |
+----+------------+---------------------+------+-------------+------+---------------------------------------------------------------+------------------+
4 rows in set (0.00 sec)
manager节点:
# masterha_check_repl --conf=/etc/mysql_mha/app1.cnf
Wed Dec :: - [info] Reading default configuration from /etc/masterha_default.cnf..
Wed Dec :: - [info] Reading application default configuration from /etc/mysql_mha/app1.cnf..
Wed Dec :: - [info] Reading server configuration from /etc/mysql_mha/app1.cnf..
Wed Dec :: - [info] MHA::MasterMonitor version 0.58.
Wed Dec :: - [info] GTID failover mode =
Wed Dec :: - [info] Dead Servers:
Wed Dec :: - [info] Alive Servers:
Wed Dec :: - [info] 10.150.20.90(10.150.20.90:)
Wed Dec :: - [info] 10.150.20.97(10.150.20.97:)
Wed Dec :: - [info] 10.150.20.132(10.150.20.132:)
Wed Dec :: - [info] Alive Slaves:
Wed Dec :: - [info] 10.150.20.90(10.150.20.90:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Wed Dec :: - [info] Replicating from 10.150.20.97(10.150.20.97:)
Wed Dec :: - [info] 10.150.20.132(10.150.20.132:) Version=5.7.-log (oldest major version between slaves) log-bin:enabled
Wed Dec :: - [info] Replicating from 10.150.20.97(10.150.20.97:)
Wed Dec :: - [info] Current Alive Master: 10.150.20.97(10.150.20.97:)
Wed Dec :: - [info] Checking slave configurations..
Wed Dec :: - [info] read_only= is not set on slave 10.150.20.132(10.150.20.132:).
Wed Dec :: - [info] Checking replication filtering settings..
Wed Dec :: - [info] binlog_do_db= , binlog_ignore_db=
Wed Dec :: - [info] Replication filtering check ok.
Wed Dec :: - [info] GTID (with auto-pos) is not supported
Wed Dec :: - [info] Starting SSH connection tests..
Wed Dec :: - [info] All SSH connection tests passed successfully.
Wed Dec :: - [info] Checking MHA Node version..
Wed Dec :: - [info] Version check ok.
Wed Dec :: - [info] Checking SSH publickey authentication settings on the current master..
Wed Dec :: - [info] HealthCheck: SSH to 10.150.20.97 is reachable.
Wed Dec :: - [info] Master MHA Node version is 0.58.
Wed Dec :: - [info] Checking recovery script configurations on 10.150.20.97(10.150.20.97:)..
Wed Dec :: - [info] Executing command: save_binary_logs --command=test --start_pos= --binlog_dir=/data/mysql_33061/logs --output_file=/data/mysql_mha/app1/save_binary_logs_test --manager_version=0.58 --start_file=mysql-bin.
Wed Dec :: - [info] Connecting to root@10.150.20.97(10.150.20.97:)..
Creating /data/mysql_mha/app1 if not exists.. ok.
Checking output directory is accessible or not..
ok.
Binlog found at /data/mysql_33061/logs, up to mysql-bin.
Wed Dec :: - [info] Binlog setting check done.
Wed Dec :: - [info] Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers..
Wed Dec :: - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='mha_monitor' --slave_host=10.150.20.90 --slave_ip=10.150.20.90 --slave_port= --workdir=/data/mysql_mha/app1 --target_version=5.7.-log --manager_version=0.58 --relay_log_info=/data/mysql_33061/logs/relay-log.info --relay_dir=/data/mysql_33061/data/ --slave_pass=xxx
Wed Dec :: - [info] Connecting to root@10.150.20.90(10.150.20.90:)..
Checking slave recovery environment settings..
Opening /data/mysql_33061/logs/relay-log.info ... ok.
Relay log found at /data/mysql_33061/logs, up to relaylog.
Temporary relay log file is /data/mysql_33061/logs/relaylog.
Checking if super_read_only is defined and turned on.. not present or turned off, ignoring.
Testing mysql connection and privileges..
mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Wed Dec :: - [info] Executing command : apply_diff_relay_logs --command=test --slave_user='mha_monitor' --slave_host=10.150.20.132 --slave_ip=10.150.20.132 --slave_port= --workdir=/data/mysql_mha/app1 --target_version=5.7.-log --manager_version=0.58 --relay_log_info=/data/mysql_33061/logs/relay-log.info --relay_dir=/data/mysql_33061/data/ --slave_pass=xxx
Wed Dec :: - [info] Connecting to root@10.150.20.132(10.150.20.132:)..
Checking slave recovery environment settings..
Opening /data/mysql_33061/logs/relay-log.info ... ok.
Relay log found at /data/mysql_33061/data, up to cgdb-relay-bin.
Temporary relay log file is /data/mysql_33061/data/cgdb-relay-bin.
Checking if super_read_only is defined and turned on.. not present or turned off, ignoring.
Testing mysql connection and privileges..
mysql: [Warning] Using a password on the command line interface can be insecure.
done.
Testing mysqlbinlog output.. done.
Cleaning up test file(s).. done.
Wed Dec :: - [info] Slaves settings check done.
Wed Dec :: - [info]
10.150.20.97(10.150.20.97:) (current master)
+--10.150.20.90(10.150.20.90:)
+--10.150.20.132(10.150.20.132:) Wed Dec :: - [info] Checking replication health on 10.150.20.90..
Wed Dec :: - [info] ok.
Wed Dec :: - [info] Checking replication health on 10.150.20.132..
Wed Dec :: - [info] ok.
Wed Dec :: - [info] Checking master_ip_failover_script status:
Wed Dec :: - [info] /usr/local/bin/master_ip_failover --command=status --ssh_user=root --orig_master_host=10.150.20.97 --orig_master_ip=10.150.20.97 --orig_master_port= IN SCRIPT TEST====/usr/sbin/ip addr del 10.150.20.200/ dev ens3 label ens3:==/usr/sbin/ip addr add 10.150.20.200/ brd 10.150.20.255 dev ens3 label ens3:;/usr/sbin/arping -q -A -c -I ens3 10.150.20.200;iptables -F;=== Checking the Status of the script.. OK
Wed Dec :: - [info] OK.
Wed Dec :: - [warning] shutdown_script is not defined.
Wed Dec :: - [info] Got exit code (Not master dead). MySQL Replication Health is OK.
复制环境检查
可以看到当前的架构:
10.150.20.97(10.150.20.97:33061) (current master)
+--10.150.20.90(10.150.20.90:33061)
+--10.150.20.132(10.150.20.132:33061)
启动 mha manager
switchover成功后,修改/etc/mysql_mha/app1.cnf,然后再启动 mha manager
启动 manager
# nohup masterha_manager --conf=/etc/mysql_mha/app1.cnf --remove_dead_master_conf --ignore_last_failover < /dev/null > /data/mysql_mha/app1-manager.log 2>&1 &
查看 manager status
# masterha_check_status --conf=/etc/mysql_mha/app1.cnf
查看 manager log
# tail -n 1000 -f /var/log/mysql_mha/app1-manager.log
switchover的过程,基本为以下步骤:
1.检测复制设置和确定当前主服务器
2.确定新的主服务器
3.阻塞写入到当前主服务器
4.等待所有从服务器赶上复制
5.授予写入到新的主服务器
6.重新设置从服务器
MySQL高可用方案 MHA之三 master_ip_online_change的更多相关文章
- MySQL高可用方案--MHA部署及故障转移
架构设计及必要配置 主机环境 IP 主机名 担任角色 192.168.192.128 node_master MySQL-Master| ...
- MySQL高可用方案MHA在线切换的步骤及原理
在日常工作中,会碰到如下的场景,如mysql数据库升级,主服务器硬件升级等,这个时候就需要将写操作切换到另外一台服务器上,那么如何进行在线切换呢?同时,要求切换过程短,对业务的影响比较小. MHA就提 ...
- mysql高可用方案MHA介绍
mysql高可用方案MHA介绍 概述 MHA是一位日本MySQL大牛用Perl写的一套MySQL故障切换方案,来保证数据库系统的高可用.在宕机的时间内(通常10-30秒内),完成故障切换,部署MHA, ...
- MySQL高可用方案MHA自动Failover与手动Failover的实践及原理
集群信息 角色 IP地址 ServerID 类型 Master ...
- MySQL高可用方案MHA的部署和原理
MHA(Master High Availability)是一套相对成熟的MySQL高可用方案,能做到在0~30s内自动完成数据库的故障切换操作,在master服务器不宕机的情况下,基本能保证数据的一 ...
- mysql 高可用方案MHA介绍
概述 MHA是一位日本MySQL大牛用Perl写的一套MySQL故障切换方案,来保证数据库系统的高可用.在宕机的时间内(通常10—30秒内),完成故障切换,部署MHA,可避免主从一致性问题,节约购买新 ...
- MySQL高可用方案--MHA原理
简介 MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Facebook公司)开发,是日 ...
- MySQL高可用方案 MHA之一MHA安装
MHA0.58安装 MHA(Master High Availability)由两部分组成:MHA Manager(管理节点)和MHA Node(数据节点).管理节点mha4mysql-manager ...
- (转)MySQL高可用方案MHA的部署和原理
背后深层次的逻辑: MHA Node则运行在每个mysql节点上,MHA Manager会定时探测集群中的master节点,当master出现故障时,它自动将最新数据的slave提升为master,然 ...
随机推荐
- 洛谷 P2196 挖地雷 & [NOIP1996提高组](搜索,记录路径)
传送门 解题思路 就是暴力!!! 没什么好说的,总之,就是枚举每一个起点,然后暴力算一遍以这个点为起点的所有路径,在算的过程中,只要比目前找到的答案更优,就有可能是最后的答案,于是就把路径更新一遍,保 ...
- [Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理)
[Codeforces 1228E]Another Filling the Grid (排列组合+容斥原理) 题面 一个\(n \times n\)的格子,每个格子里可以填\([1,k]\)内的整数. ...
- django项目学习之QQ登录
最近在用django框架写一个商城项目(前后端分离),里面用到的一些技术其他项目也可以借鉴,于是就想写一些博客记录,以防自己忘记,今天先写一个关于登录接口中引入QQ登录接口的流程. 关于QQ登录接口的 ...
- Python 入门之 模块
Python 入门之 模块 1.模块 (1)模块是什么? 将一些常用的功能封装到一个文件中,那么这个存储着很多常用的功能的py文件,就是模块. 模块就是文件,存放一堆常用的函数.模块,就是一些常用 ...
- 手摸手教你如何在 Python 编码中做到小细节大优化
手摸手教你如何在 Python 编码中做到小细节大优化 在列表里计数 """ 在列表里计数,使用 Python 原生函数计数要快很多,所以尽量使用原生函数来计算. &qu ...
- 区块链开源实现hyperledger fabric架构详解
hyperledger fabric是区块链中联盟链的优秀实现,主要代码由IBM.Intel.各大银行等贡献,目前v1.1版的kafka共识方式可达到1000/s次的吞吐量.本文中我们依次讨论:区块链 ...
- RabbitMQ交换器Exchange介绍与实践
RabbitMQ交换器Exchange介绍与实践 RabbitMQ系列文章 RabbitMQ在Ubuntu上的环境搭建 深入了解RabbitMQ工作原理及简单使用 RabbitMQ交换器Exchang ...
- spark复习笔记(1)
使用spark实现work count ---------------------------------------------------- (1)用sc.textFile(" &quo ...
- js中的数组去掉空值
//result 是有空值的数组//r是处理好的数组var r = result.filter(function (s) { return s && s.trim();});
- JavaEE高级-SpringMVC学习笔记
*SpringMVC概述 - Spring为展示层提供的基于MVC设计理念的优秀Web框架,是目前最主流的MVC框架之一 - Spring3.0后全面超越Struts2,成为最优秀的MVC框架 - S ...