MySQL高可用性モジュールの変更カスタムVIPパラメータの受信


しかし、MySQL DBAはMHAの高可用性案を聞いたことがあるに違いありません.多くの会社はMHAを二次開発することでMySQLの高可用性を実現しています.MHAがVIPと連携していない場合は、マスターライブラリの切り替えのたびにデータベース接続の構成をプログラムで変更する必要があります.これは面倒です.MHA+VIP方式を採用する場合、メインライブラリの切り替え中にVIPを新しいメインライブラリにドリフトさせることができ、データベース構成の変更を省くことができます.
会社は以前、各グループのホストがレプリケーションクラスタからmanagerノードを構成し、vipやネットワークインタフェースなどの情報をmasterに書き込んでいました.ip_failoverとmaster_ip_online_changeスクリプトにあります.プライマリスレーブクラスタの数が多すぎる場合、メンテナンスするmanagerノードが多く、管理が面倒です.
VIPをサポートするmysqlプライマリ・スレーブ・クラスタを1つのマネージャ・ノードで管理するにはどうすればいいですか?2つの実装方法があります.
1,各グループのホストはレプリケーションクラスタから2つの切り替えスクリプトを維持し,VIPとネットワークインタフェース情報をスクリプトに書き込む.
2、MHAの関連モジュールを修正して、私たちがカスタマイズしたパラメータを識別できるようにして、私たちは各グループの主が複製クラスタのプロファイルからパラメータに値を渡すだけです.
明らかに、第1の方法はlowしすぎて、大量の切替スクリプトを維持する必要があります.では、どのモジュールを修正する必要がありますか?
マスターを見てcheck_replこのスクリプトでは、マスタースレーブのレプリケーション状態を検出するときにMasterMonitorモジュールが呼び出されることがわかります.
$exit_code = MHA::MasterMonitor::main( "--interactive=0", "--check_only",
  "--check_repl_health", @ARGV );
if ( $exit_code == 0 ) {
  print "
MySQL Replication Health is OK.
"; } else {   print "
MySQL Replication Health is NOT OK!
"; }

masterha経由master_switchこのスクリプトでは、オンライン切替が呼び出しのMasterRotateモジュールであり、フェイルオーバーが呼び出しのMasterFailoverモジュールであることがわかります.
if ( $master_state eq "dead" ) {
  $exit_code = MHA::MasterFailover::main(@ARGV);
}
elsif ( $master_state eq "alive" ) {
  $exit_code = MHA::MasterRotate::main(@ARGV);
}
else {
  pod2usage(1);
}

MasterMonitor.pm,MasterRotate.pm,MasterFailover.pmの3つのモジュールはすべてConfigを呼び出す.pmモジュールはパラメータ構成を読み出すので、これらのモジュールを変更するだけでいいです.
不適切なネットワーク環境のために、プロファイルにこの3つのプロファイルを追加しました.
app_vip:メインライブラリのVIP
Netmask:VIPのネットワークビット
interface:VIPバインドするネット上
調整に対応するコードは以下の通りです.
Config.pm:
宣言変数:
my @PARAM_ARRAY =
  qw/ hostname ip port ssh_host ssh_ip ssh_port ssh_connection_timeout ssh_options 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 client_bindir client_libdir use_gtid_auto_pos app_vip netmask interface/;

変数に値を割り当てるには、次の手順に従います.
  $value{app_vip} = $param_arg->{app_vip};
  if ( !defined( $value{app_vip} ) ) {
    $value{app_vip} = $default->{app_vip};
  }
  $value{netmask} = $param_arg->{netmask};
  if ( !defined( $value{netmask} ) ) {
    $value{netmask} = $default->{netmask};
  }
  $value{interface} = $param_arg->{interface};
  if ( !defined( $value{interface} ) ) {
    $value{interface} = $default->{interface};
  }

MasterMonitor.pm :
コピー検出時のコマンドを変更するには、次の手順に従います.
"$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}  --app_vip=$current_master->{app_vip} --netmask=$current_master->{netmask} --interface=$current_master->{interface}";

MasterMonitor.pm :
元のマスターライブラリの書き込みを停止するコマンドを変更します.
"$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} --orig_master_user=$orig_master->{escaped_user} --orig_master_password=$orig_master->{escaped_password} --new_master_host=$new_master->{hostname} --new_master_ip=$new_master->{ip} --new_master_port=$new_master->{port} --new_master_user=$new_master->{escaped_user} --new_master_password=$new_master->{escaped_password} --app_vip=$orig_master->{app_vip} --netmask=$orig_master->{netmask} --interface=$orig_master->{interface}";

新しいマスターライブラリへの書き込みを許可するコマンドを変更します.
"$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} --orig_master_user=$orig_master->{escaped_user} --orig_master_password=$orig_master->{escaped_password} --new_master_host=$new_master->{hostname} --new_master_ip=$new_master->{ip} --new_master_port=$new_master->{port} --new_master_user=$new_master->{escaped_user} --new_master_password=$new_master->{escaped_password} --app_vip=$orig_master->{app_vip} --netmask=$orig_master->{netmask} --interface=$orig_master->{interface}";

MasterFailover.pm:
元のスレーブライブラリを無効にするvipコマンドを変更します.
 "$dead_master->{master_ip_failover_script} --orig_master_host=$dead_master->{hostname} --orig_master_ip=$dead_master->{ip} --orig_master_port=$dead_master->{port} --app_vip=$dead_master->{app_vip}  --netmask=$dead_master     ->{netmask} --interface=$dead_master->{interface}";

元のスレーブvipを有効にするコマンドを変更します.
 "$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_m     aster_host=$new_master->{hostname} --new_master_ip=$new_master->{ip} --new_master_port=$new_master->{port} --new_master_user=$new_master->{escaped_user} --new_master_password=$new_master->{escaped_password} --app_vip=$de     ad_master->{app_vip} --netmask=$dead_master->{netmask} --interface=$dead_master->{interface}";