Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

* New Feature: Supporting ssh_host and ssh_port parameters

  • Loading branch information...
commit 0e0bb1bccfced545dfa45e2747d8d55bf0a7b444 1 parent 06dd340
@yoshinorim authored
View
9 bin/masterha_secondary_check
@@ -26,7 +26,10 @@ use Pod::Usage;
use MHA::ManagerConst;
my @monitoring_servers;
-my ( $help, $version, $ssh_user, $master_host, $master_ip, $master_port );
+my (
+ $help, $version, $ssh_user, $ssh_port,
+ $master_host, $master_ip, $master_port
+);
$| = 1;
GetOptions(
@@ -34,6 +37,7 @@ GetOptions(
'version' => \$version,
'secondary_host=s' => \@monitoring_servers,
'user=s' => \$ssh_user,
+ 'port=s' => \$ssh_port,
'master_host=s' => \$master_host,
'master_ip=s' => \$master_ip,
'master_port=i' => \$master_port,
@@ -53,6 +57,7 @@ unless ($master_host) {
}
$ssh_user = "root" unless ($ssh_user);
+$ssh_port = 22 unless ($ssh_port);
$master_port = 3306 unless ($master_port);
sub exit_by_signal {
@@ -69,7 +74,7 @@ my $exit_code = 0;
foreach my $monitoring_server (@monitoring_servers) {
my $ssh_user_host = $ssh_user . '@' . $monitoring_server;
my $command =
- "ssh $MHA::ManagerConst::SSH_OPT_CHECK $ssh_user_host \"perl -e "
+"ssh $MHA::ManagerConst::SSH_OPT_CHECK -p $ssh_port $ssh_user_host \"perl -e "
. "\\\"use IO::Socket::INET; my \\\\\\\$sock = IO::Socket::INET->new"
. "(PeerAddr => \\\\\\\"$master_host\\\\\\\", PeerPort=> $master_port, "
. "Proto =>'tcp', Timeout => 4); if(\\\\\\\$sock) { close(\\\\\\\$sock); "
View
23 lib/MHA/Config.pm
@@ -31,7 +31,7 @@ use MHA::NodeUtil;
use MHA::ManagerConst;
my @PARAM_ARRAY =
- qw/ hostname ip port node_label candidate_master no_master ignore_fail skip_init_ssh_check skip_reset_slave user password repl_user repl_password disable_log_bin master_pid_file handle_raw_binlog ssh_user remote_workdir master_binlog_dir log_level manager_workdir manager_log check_repl_delay check_repl_filter latest_priority multi_tier_slave ping_interval ping_type secondary_check_script master_ip_failover_script master_ip_online_change_script shutdown_script report_script init_conf_load_script /;
+ qw/ hostname ip port ssh_host ssh_ip ssh_port node_label candidate_master no_master ignore_fail skip_init_ssh_check skip_reset_slave user password repl_user repl_password disable_log_bin master_pid_file handle_raw_binlog ssh_user remote_workdir master_binlog_dir log_level manager_workdir manager_log check_repl_delay check_repl_filter latest_priority multi_tier_slave ping_interval ping_type secondary_check_script master_ip_failover_script master_ip_online_change_script shutdown_script report_script init_conf_load_script /;
my %PARAM;
for (@PARAM_ARRAY) { $PARAM{$_} = 1; }
@@ -68,6 +68,27 @@ sub parse_server {
$value{port} = $default->{port};
$value{port} = 3306 unless ( $value{port} );
}
+
+ $value{ssh_host} = $param_arg->{ssh_host};
+ if ( !defined( $value{ssh_host} ) ) {
+ $value{ssh_host} = $value{hostname};
+ }
+ if ( $value{hostname}
+ && $value{ssh_host}
+ && $value{ssh_host} eq $value{hostname} )
+ {
+ $value{ssh_ip} = $value{ip};
+ }
+ else {
+ $value{ssh_ip} = MHA::NodeUtil::get_ip( $value{ssh_host} );
+ }
+
+ $value{ssh_port} = $param_arg->{ssh_port};
+ if ( !defined( $value{ssh_port} ) ) {
+ $value{ssh_port} = $default->{ssh_port};
+ $value{ssh_port} = 22 unless ( $value{ssh_port} );
+ }
+
$value{user} = $param_arg->{user};
if ( !defined( $value{user} ) ) {
$value{user} = $default->{user};
View
24 lib/MHA/HealthCheck.pm
@@ -43,6 +43,9 @@ sub new {
hostname => undef,
port => undef,
ssh_user => undef,
+ ssh_host => undef,
+ ssh_ip => undef,
+ ssh_port => undef,
workdir => undef,
status_handler => undef,
secondary_check_script => undef,
@@ -265,11 +268,12 @@ sub ping_select($) {
sub ssh_check {
my $ssh_user = shift;
- my $hostname = shift;
- my $ip = shift;
+ my $ssh_host = shift;
+ my $ssh_ip = shift;
+ my $ssh_port = shift;
my $log = shift;
my $num_secs_to_timeout = shift;
- my $ssh_user_host = $ssh_user . '@' . $ip;
+ my $ssh_user_host = $ssh_user . '@' . $ssh_ip;
my $rc = 1;
my $command = "exit 0";
eval {
@@ -277,23 +281,25 @@ sub ssh_check {
{
local $SIG{ALRM} = sub {
kill 9, $pid;
- die "Got timeout on checking SSH connection to $hostname!";
+ die "Got timeout on checking SSH connection to $ssh_host!";
};
alarm $num_secs_to_timeout;
waitpid( $pid, 0 );
alarm 0;
my $exit_code = $? >> 8;
if ( $exit_code == 0 ) {
- $log->info("HealthCheck: SSH to $hostname is reachable.");
+ $log->info("HealthCheck: SSH to $ssh_host is reachable.");
$rc = 0;
}
else {
- $log->warning("HealthCheck: SSH to $hostname is NOT reachable.");
+ $log->warning("HealthCheck: SSH to $ssh_host is NOT reachable.");
$rc = 1;
}
}
elsif ( defined $pid ) {
- exec("ssh $MHA::ManagerConst::SSH_OPT_CHECK $ssh_user_host $command");
+ exec(
+"ssh $MHA::ManagerConst::SSH_OPT_CHECK -p $ssh_port $ssh_user_host $command"
+ );
}
else {
croak "Forking SSH connection process failed!\n";
@@ -401,8 +407,8 @@ sub invoke_ssh_check {
#child ssh check process
exit ssh_check(
- $self->{ssh_user}, $self->{hostname}, $self->{ip},
- $self->{logger}, $self->{interval} * 3
+ $self->{ssh_user}, $self->{ssh_host}, $self->{ssh_ip},
+ $self->{ssh_port}, $self->{logger}, $self->{interval} * 3
);
}
else {
View
19 lib/MHA/ManagerUtil.pm
@@ -69,22 +69,26 @@ sub exec_system {
}
}
-sub exec_ssh_check_cmd($$$) {
+sub exec_ssh_check_cmd($$$$) {
my $ssh_host = shift;
+ my $ssh_port = shift;
my $ssh_cmd = shift;
my $log_output = shift;
my $ret;
return exec_system(
- "ssh $MHA::ManagerConst::SSH_OPT_CHECK $ssh_host $ssh_cmd", $log_output );
+ "ssh $MHA::ManagerConst::SSH_OPT_CHECK -p $ssh_port $ssh_host $ssh_cmd",
+ $log_output );
}
-sub exec_ssh_cmd($$$) {
+sub exec_ssh_cmd($$$$) {
my $ssh_host = shift;
+ my $ssh_port = shift;
my $ssh_cmd = shift;
my $log_output = shift;
my $ret;
return exec_system(
- "ssh $MHA::ManagerConst::SSH_OPT_ALIVE $ssh_host $ssh_cmd", $log_output );
+ "ssh $MHA::ManagerConst::SSH_OPT_ALIVE -p $ssh_port $ssh_host $ssh_cmd",
+ $log_output );
}
sub check_node_version {
@@ -92,10 +96,12 @@ sub check_node_version {
my $ssh_user = shift;
my $ssh_host = shift;
my $ssh_ip = shift;
+ my $ssh_port = shift;
my $ssh_user_host;
my $node_version;
eval {
my $command = "apply_diff_relay_logs --version";
+
if ( $ssh_host || $ssh_ip ) {
if ($ssh_ip) {
$ssh_user_host = $ssh_user . '@' . $ssh_ip;
@@ -104,7 +110,7 @@ sub check_node_version {
$ssh_user_host = $ssh_user . '@' . $ssh_host;
}
$command =
-"ssh $MHA::ManagerConst::SSH_OPT_ALIVE $ssh_user_host \"$command\" 2>&1";
+"ssh $MHA::ManagerConst::SSH_OPT_ALIVE $ssh_user_host -p $ssh_port \"$command\" 2>&1";
}
my $v = `$command`;
@@ -140,9 +146,10 @@ sub check_node_version_nodie {
my $ssh_user = shift;
my $ssh_host = shift;
my $ssh_ip = shift;
+ my $ssh_port = shift;
my $rc = 1;
eval {
- check_node_version( $log, $ssh_user, $ssh_host, $ssh_ip );
+ check_node_version( $log, $ssh_user, $ssh_host, $ssh_ip, $ssh_port );
$rc = 0;
};
if ($@) {
View
54 lib/MHA/MasterFailover.pm
@@ -83,9 +83,10 @@ sub exit_by_signal {
}
sub exec_ssh_child_cmd {
- my ( $ssh_user_host, $ssh_cmd, $logger, $file ) = @_;
+ my ( $ssh_user_host, $ssh_port, $ssh_cmd, $logger, $file ) = @_;
my ( $high, $low ) =
- MHA::ManagerUtil::exec_ssh_cmd( $ssh_user_host, $ssh_cmd, $file );
+ MHA::ManagerUtil::exec_ssh_cmd( $ssh_user_host, $ssh_port, $ssh_cmd,
+ $file );
if ( $logger && $file ) {
$logger->info( "\n" . `cat $file` );
unlink $file;
@@ -320,6 +321,7 @@ sub force_shutdown_internal($) {
else {
$command .= " --command=stop";
}
+ $command .= $dead_master->get_ssh_args_if("orig");
$log->info("Executing master IP deactivatation script:");
$log->info(" $command");
my ( $high, $low ) = MHA::ManagerUtil::exec_system( $command, $g_logfile );
@@ -361,6 +363,7 @@ sub force_shutdown_internal($) {
" --host=$dead_master->{hostname} --ip=$dead_master->{ip} --port=$dead_master->{port} ";
$command .= " --pid_file=$dead_master->{master_pid_file}"
if ( $dead_master->{master_pid_file} );
+ $command .= $dead_master->get_ssh_args_if("shutdown");
$log->info("Executing SHUTDOWN script:");
$log->info(" $command");
my ( $high, $low ) = MHA::ManagerUtil::exec_system( $command, $g_logfile );
@@ -512,7 +515,7 @@ sub save_master_binlog_internal {
if ( $dead_master->{log_level} eq "debug" ) {
$command .= " --debug ";
}
- my $ssh_user_host = $dead_master->{ssh_user} . '@' . $dead_master->{ip};
+ my $ssh_user_host = $dead_master->{ssh_user} . '@' . $dead_master->{ssh_ip};
$log->info(
sprintf(
"Executing command on the dead master %s: %s",
@@ -520,13 +523,15 @@ sub save_master_binlog_internal {
)
);
my ( $high, $low ) =
- MHA::ManagerUtil::exec_ssh_cmd( $ssh_user_host, $command, $g_logfile );
+ MHA::ManagerUtil::exec_ssh_cmd( $ssh_user_host, $dead_master->{ssh_port},
+ $command, $g_logfile );
if ( $high == 0 && $low == 0 ) {
if (
MHA::NodeUtil::file_copy(
0, $_diff_binary_log,
$_diff_binary_log_remote, $dead_master->{ssh_user},
- $dead_master->{ip}, $g_logfile
+ $dead_master->{ssh_ip}, $g_logfile,
+ $dead_master->{ssh_port}
)
)
{
@@ -567,8 +572,9 @@ sub save_master_binlog {
MHA::ManagerUtil::check_node_version(
$log,
$dead_master->{ssh_user},
- $dead_master->{hostname},
- $dead_master->{ip}
+ $dead_master->{ssh_host},
+ $dead_master->{ssh_ip},
+ $dead_master->{ssh_port}
);
my $latest_file =
( $_server_manager->get_latest_slaves() )[0]->{Master_Log_File};
@@ -602,7 +608,8 @@ sub find_slave_with_all_relay_logs {
next if ( $latest_slave->{ssh_ok} == 0 );
}
- my $ssh_user_host = $latest_slave->{ssh_user} . '@' . $latest_slave->{ip};
+ my $ssh_user_host =
+ $latest_slave->{ssh_user} . '@' . $latest_slave->{ssh_ip};
my $command =
"apply_diff_relay_logs --command=find --latest_mlf=$latest_slave->{Master_Log_File} --latest_rmlp=$latest_slave->{Read_Master_Log_Pos} --target_mlf=$oldest_master_log_file --target_rmlp=$oldest_master_log_pos --server_id=$latest_slave->{server_id} --workdir=$latest_slave->{remote_workdir} --timestamp=$_start_datetime --manager_version=$MHA::ManagerConst::VERSION";
if ( $latest_slave->{relay_log_info_type} eq "TABLE" ) {
@@ -621,7 +628,8 @@ sub find_slave_with_all_relay_logs {
);
$log->info("Executing command: $command :");
my ( $high, $low ) =
- MHA::ManagerUtil::exec_ssh_cmd( $ssh_user_host, $command, $g_logfile );
+ MHA::ManagerUtil::exec_ssh_cmd( $ssh_user_host, $latest_slave->{ssh_port},
+ $command, $g_logfile );
if ( $high eq '0' && $low eq '0' ) {
$log->info("OK. $latest_slave->{hostname} has all relay logs.");
return $latest_slave;
@@ -774,7 +782,8 @@ sub send_binlog {
MHA::NodeUtil::file_copy(
1, $_diff_binary_log,
$_diff_binary_log_remote, $target->{ssh_user},
- $target->{ip}, $g_logfile
+ $target->{ssh_ip}, $g_logfile,
+ $target->{ssh_port}
)
)
{
@@ -805,9 +814,10 @@ sub generate_diff_from_readpos {
"Need to get diffs from the latest slave($latest_slave->{hostname}) up to: $latest_slave->{Master_Log_File}:$latest_slave->{Read_Master_Log_Pos} (using the latest slave's relay logs)"
);
- my $ssh_user_host = $latest_slave->{ssh_user} . '@' . $latest_slave->{ip};
+ my $ssh_user_host = $latest_slave->{ssh_user} . '@' . $latest_slave->{ssh_ip};
my ( $high, $low ) =
- MHA::ManagerUtil::exec_ssh_cmd( $ssh_user_host, "exit 0", $g_logfile );
+ MHA::ManagerUtil::exec_ssh_cmd( $ssh_user_host, $latest_slave->{ssh_port},
+ "exit 0", $g_logfile );
if ( $high ne '0' || $low ne '0' ) {
$logger->error("SSH authentication test failed. user=$ssh_user_host");
return ( $high, $low );
@@ -817,7 +827,11 @@ sub generate_diff_from_readpos {
"Connecting to the latest slave host $latest_slave->{hostname}, generating diff relay log files.."
);
my $command =
-"apply_diff_relay_logs --command=generate_and_send --scp_user=$target->{ssh_user} --scp_host=$target->{ip} --latest_mlf=$latest_slave->{Master_Log_File} --latest_rmlp=$latest_slave->{Read_Master_Log_Pos} --target_mlf=$target->{Master_Log_File} --target_rmlp=$target->{Read_Master_Log_Pos} --server_id=$latest_slave->{server_id} --diff_file_readtolatest=$target->{diff_file_readtolatest} --workdir=$latest_slave->{remote_workdir} --timestamp=$_start_datetime --handle_raw_binlog=$target->{handle_raw_binlog} --disable_log_bin=$target->{disable_log_bin} --manager_version=$MHA::ManagerConst::VERSION";
+"apply_diff_relay_logs --command=generate_and_send --scp_user=$target->{ssh_user} --scp_host=$target->{ssh_ip} --latest_mlf=$latest_slave->{Master_Log_File} --latest_rmlp=$latest_slave->{Read_Master_Log_Pos} --target_mlf=$target->{Master_Log_File} --target_rmlp=$target->{Read_Master_Log_Pos} --server_id=$latest_slave->{server_id} --diff_file_readtolatest=$target->{diff_file_readtolatest} --workdir=$latest_slave->{remote_workdir} --timestamp=$_start_datetime --handle_raw_binlog=$target->{handle_raw_binlog} --disable_log_bin=$target->{disable_log_bin} --manager_version=$MHA::ManagerConst::VERSION";
+ if ( $target->{ssh_port} ne 22 ) {
+ $command .= " --scp_port=$target->{ssh_port}";
+ }
+
if ( $latest_slave->{relay_log_info_type} eq "TABLE" ) {
$command .=
" --relay_dir=$latest_slave->{relay_dir} --current_relay_log=$latest_slave->{current_relay_log} ";
@@ -833,8 +847,8 @@ sub generate_diff_from_readpos {
$command .= " --debug ";
}
$logger->info("Executing command: $command");
- return exec_ssh_child_cmd( $ssh_user_host, $command, $logger,
- "$g_workdir/$target->{hostname}_$target->{port}.work" );
+ return exec_ssh_child_cmd( $ssh_user_host, $target->{ssh_port}, $command,
+ $logger, "$g_workdir/$target->{hostname}_$target->{port}.work" );
}
# 0: no need to generate diff
@@ -1028,8 +1042,9 @@ sub gen_diff_from_exec_to_read {
$logger->error("Failed to connect via SSH!");
return 1;
}
- my ( $high, $low ) = exec_ssh_child_cmd( $ssh_user_host, $command, $logger,
- "$g_workdir/$target->{hostname}_$target->{port}.work" );
+ my ( $high, $low ) =
+ exec_ssh_child_cmd( $ssh_user_host, $target->{ssh_port}, $command,
+ $logger, "$g_workdir/$target->{hostname}_$target->{port}.work" );
if ( $high eq '0' && $low eq '0' ) {
return 0;
}
@@ -1108,7 +1123,8 @@ sub apply_diff {
$logger->error("Failed to connect via SSH!");
return ( 1, 0 );
}
- my ( $high, $low ) = exec_ssh_child_cmd( $ssh_user_host, $command, $logger,
+ my ( $high, $low ) =
+ exec_ssh_child_cmd( $ssh_user_host, $target->{ssh_port}, $command, $logger,
"$g_workdir/$target->{hostname}_$target->{port}.work" );
$target->set_default_max_allowed_packet($logger);
@@ -1198,6 +1214,8 @@ sub recover_master($$$) {
if ( $new_master->{master_ip_failover_script} ) {
my $command =
"$new_master->{master_ip_failover_script} --command=start --ssh_user=$new_master->{ssh_user} --orig_master_host=$dead_master->{hostname} --orig_master_ip=$dead_master->{ip} --orig_master_port=$dead_master->{port} --new_master_host=$new_master->{hostname} --new_master_ip=$new_master->{ip} --new_master_port=$new_master->{port}";
+ $command .= $dead_master->get_ssh_args_if("orig");
+ $command .= $new_master->get_ssh_args_if("new");
$log->info("Executing master IP activate script:");
$log->info(" $command");
my ( $high, $low ) = MHA::ManagerUtil::exec_system( $command, $g_logfile );
View
30 lib/MHA/MasterMonitor.pm
@@ -70,10 +70,10 @@ sub check_master_env($) {
$log->info(
"Checking SSH publickey authentication and checking recovery script configurations on the current master.."
);
- my $ssh_user_host = $target->{ssh_user} . '@' . $target->{hostname};
+ my $ssh_user_host = $target->{ssh_user} . '@' . $target->{ssh_host};
MHA::ManagerUtil::check_node_version( $log, $target->{ssh_user},
- $target->{hostname}, $target->{ip} );
+ $target->{ssh_host}, $target->{ssh_ip}, $target->{ssh_port} );
# this file is not created. just checking directory path
my $workfile = "$target->{remote_workdir}/save_binary_logs_test";
@@ -87,9 +87,10 @@ sub check_master_env($) {
$command .= " --debug ";
}
$log->info(" Executing command: $command ");
- $log->info(" Connecting to $ssh_user_host($target->{hostname}).. ");
+ $log->info(" Connecting to $ssh_user_host($target->{ssh_host}).. ");
my ( $high, $low ) =
- MHA::ManagerUtil::exec_ssh_cmd( $ssh_user_host, $command, $g_logfile );
+ MHA::ManagerUtil::exec_ssh_cmd( $ssh_user_host, $target->{ssh_port},
+ $command, $g_logfile );
if ( $high ne '0' || $low ne '0' ) {
$log->error("Master setting check failed!");
return 1;
@@ -104,7 +105,7 @@ sub check_slave_env() {
"Checking SSH publickey authentication and checking recovery script configurations on all alive slave servers.."
);
foreach my $s (@alive_servers) {
- my $ssh_user_host = $s->{ssh_user} . '@' . $s->{ip};
+ my $ssh_user_host = $s->{ssh_user} . '@' . $s->{ssh_ip};
my $command =
"apply_diff_relay_logs --command=test --slave_user=$s->{user} --slave_host=$s->{hostname} --slave_ip=$s->{ip} --slave_port=$s->{port} --workdir=$s->{remote_workdir} --target_version=$s->{mysql_version} --manager_version=$MHA::ManagerConst::VERSION";
if ( $s->{relay_log_info_type} eq "TABLE" ) {
@@ -123,9 +124,11 @@ sub check_slave_env() {
if ( $s->{password} ne "" ) {
$command .= " --slave_pass=$s->{password}";
}
- $log->info(" Connecting to $ssh_user_host($s->{hostname}).. ");
+ $log->info(
+ " Connecting to $ssh_user_host($s->{ssh_host}:$s->{ssh_port}).. ");
my ( $high, $low ) =
- MHA::ManagerUtil::exec_ssh_cmd( $ssh_user_host, $command, $g_logfile );
+ MHA::ManagerUtil::exec_ssh_cmd( $ssh_user_host, $s->{ssh_port}, $command,
+ $g_logfile );
if ( $high ne '0' || $low ne '0' ) {
$log->error("Slaves settings check failed!");
return 1;
@@ -140,7 +143,8 @@ sub check_scripts($) {
if ( $current_master->{master_ip_failover_script} ) {
my $command =
"$current_master->{master_ip_failover_script} --command=status --ssh_user=$current_master->{ssh_user} --orig_master_host=$current_master->{hostname} --orig_master_ip=$current_master->{ip} --orig_master_port=$current_master->{port}";
- $log->info("Checking master_ip_failvoer_script status:");
+ $command .= $current_master->get_ssh_args_if("orig");
+ $log->info("Checking master_ip_failover_script status:");
$log->info(" $command");
my ( $high, $low ) = MHA::ManagerUtil::exec_system( $command, $g_logfile );
if ( $high == 0 && $low == 0 ) {
@@ -160,6 +164,7 @@ sub check_scripts($) {
if ( $current_master->{shutdown_script} ) {
my $command =
"$current_master->{shutdown_script} --command=status --host=$current_master->{hostname} --ip=$current_master->{ip}";
+ $command .= $current_master->get_ssh_args_if("shutdown");
$log->info("Checking shutdown script status:");
$log->info(" $command");
my ( $high, $low ) = MHA::ManagerUtil::exec_system( $command, $g_logfile );
@@ -276,8 +281,10 @@ sub wait_until_master_is_unreachable() {
unless ($g_skip_ssh_check);
$log->info("Checking MHA Node version..");
foreach my $slave (@alive_slaves) {
- MHA::ManagerUtil::check_node_version( $log, $slave->{ssh_user},
- $slave->{hostname}, $slave->{ip} );
+ MHA::ManagerUtil::check_node_version(
+ $log, $slave->{ssh_user}, $slave->{ssh_host},
+ $slave->{ssh_ip}, $slave->{ssh_port}
+ );
}
$log->info(" Version check ok.");
unless ($current_master) {
@@ -331,6 +338,9 @@ sub wait_until_master_is_unreachable() {
port => $current_master->{port},
interval => $current_master->{ping_interval},
ssh_user => $current_master->{ssh_user},
+ ssh_host => $current_master->{ssh_host},
+ ssh_ip => $current_master->{ssh_ip},
+ ssh_port => $current_master->{ssh_port},
status_handler => $_status_handler,
logger => $log,
logfile => $g_logfile,
View
4 lib/MHA/MasterRotate.pm
@@ -253,6 +253,8 @@ sub reject_update($$) {
if ( $new_master->{master_ip_online_change_script} ) {
my $command =
"$orig_master->{master_ip_online_change_script} --command=stop --orig_master_host=$orig_master->{hostname} --orig_master_ip=$orig_master->{ip} --orig_master_port=$orig_master->{port} --new_master_host=$new_master->{hostname} --new_master_ip=$new_master->{ip} --new_master_port=$new_master->{port}";
+ $command .= $orig_master->get_ssh_args_if("orig");
+ $command .= $new_master->get_ssh_args_if("new");
$log->info(
"Executing master ip online change script to disable write on the current master:"
);
@@ -360,6 +362,8 @@ sub switch_master($$$$) {
if ( $new_master->{master_ip_online_change_script} ) {
my $command =
"$new_master->{master_ip_online_change_script} --command=start --orig_master_host=$orig_master->{hostname} --orig_master_ip=$orig_master->{ip} --orig_master_port=$orig_master->{port} --new_master_host=$new_master->{hostname} --new_master_ip=$new_master->{ip} --new_master_port=$new_master->{port}";
+ $command .= $orig_master->get_ssh_args_if("orig");
+ $command .= $new_master->get_ssh_args_if("new");
$log->info(
"Executing master ip online change script to allow write on the new master:"
);
View
10 lib/MHA/SSHCheck.pm
@@ -57,7 +57,7 @@ sub do_ssh_connection_check {
my ( $pid, $exit_code, $target ) = @_;
return if ( $target->{skip_init_ssh_check} );
my $local_file =
- "$workdir/$target->{hostname}_$target->{port}_ssh_check.log";
+ "$workdir/$target->{ssh_host}_$target->{ssh_port}_ssh_check.log";
if ($exit_code) {
$failed = 1;
$log->error( "\n" . `cat $local_file` );
@@ -82,7 +82,7 @@ sub do_ssh_connection_check {
eval {
$SIG{INT} = $SIG{HUP} = $SIG{QUIT} = $SIG{TERM} = "DEFAULT";
$pm->finish(0) if ( $src->{skip_init_ssh_check} );
- $file = "$workdir/$src->{hostname}_$src->{port}_ssh_check.log";
+ $file = "$workdir/$src->{ssh_host}_$src->{ssh_port}_ssh_check.log";
unlink $file;
$pplog = Log::Dispatch->new( callbacks => $MHA::ManagerConst::log_fmt );
$pplog->add(
@@ -98,14 +98,14 @@ sub do_ssh_connection_check {
next if ( $dst->{skip_init_ssh_check} );
next if ( $src->{id} eq $dst->{id} );
$pplog->debug(
-" Connecting via SSH from $src->{ssh_user}\@$src->{hostname}($src->{ip}) to $dst->{ssh_user}\@$dst->{hostname}($dst->{ip}).."
+" Connecting via SSH from $src->{ssh_user}\@$src->{ssh_host}($src->{ssh_ip}:$src->{ssh_port}) to $dst->{ssh_user}\@$dst->{ssh_host}($dst->{ssh_ip}:$dst->{ssh_port}).."
);
my $command =
-"ssh $MHA::ManagerConst::SSH_OPT_CHECK $src->{ssh_user}\@$src->{ip} \"ssh $MHA::ManagerConst::SSH_OPT_CHECK $dst->{ssh_user}\@$dst->{ip} exit 0\"";
+"ssh $MHA::ManagerConst::SSH_OPT_CHECK -p $src->{ssh_port} $src->{ssh_user}\@$src->{ssh_ip} \"ssh $MHA::ManagerConst::SSH_OPT_CHECK -p $dst->{ssh_port} $dst->{ssh_user}\@$dst->{ssh_ip} exit 0\"";
my ( $high, $low ) = MHA::ManagerUtil::exec_system( $command, $file );
if ( $high != 0 || $low != 0 ) {
$pplog->error(
-"SSH connection from $src->{ssh_user}\@$src->{hostname}($src->{ip}) to $dst->{ssh_user}\@$dst->{hostname}($dst->{ip}) failed!"
+"SSH connection from $src->{ssh_user}\@$src->{ssh_host}($src->{ssh_ip}:$src->{ssh_port}) to $dst->{ssh_user}\@$dst->{ssh_host}($dst->{ssh_ip}:$dst->{ssh_port}) failed!"
);
$pm->finish(1);
}
View
37 lib/MHA/Server.pm
@@ -321,11 +321,12 @@ sub check_set_ssh_status {
if ( !$self->{dead} ) {
if (
MHA::HealthCheck::ssh_check(
- $self->{ssh_user}, $self->{hostname}, $self->{ip},
- $self->{logger}, 5
+ $self->{ssh_user}, $self->{ssh_host}, $self->{ssh_ip},
+ $self->{ssh_port}, $self->{logger}, 5
)
|| MHA::ManagerUtil::check_node_version_nodie(
- $log, $self->{ssh_user}, $self->{hostname}, $self->{ip}
+ $log, $self->{ssh_user}, $self->{ssh_host},
+ $self->{ssh_ip}, $self->{ssh_port}
)
)
{
@@ -1006,4 +1007,34 @@ sub print_filter {
return $str;
}
+sub get_ssh_args_if {
+ my $self = shift;
+ my $type = shift;
+
+ my $arg = " ";
+ my $head = "";
+
+ if ( $type eq "orig" ) {
+ $head = " --orig_master_";
+ }
+ elsif ( $type eq "new" ) {
+ $head = " --new_master_";
+ }
+ elsif ( $type eq "shutdown" ) {
+ $head = " --";
+ }
+
+ if ( $self->{hostname} ne $self->{ssh_host}
+ || $self->{ip} ne $self->{ssh_ip} )
+ {
+ $arg .=
+ $head . "ssh_host=$self->{ssh_host}" . $head . "ssh_ip=$self->{ssh_ip}";
+ }
+
+ if ( $self->{ssh_port} ne 22 ) {
+ $arg .= $head . "ssh_port=$self->{ssh_port}";
+ }
+ return $arg;
+}
+
1;
Please sign in to comment.
Something went wrong with that request. Please try again.