MHA master_ip_failover


点击(此处)折叠或打开

  1. #!/usr/bin/env perl



  2.     ## Note: This is a sample script and is not complete. Modify the script based on your environment.

  3.     use strict;
  4.     use warnings FATAL => 'all';

  5.     use Getopt::Long;
  6.     use MHA::DBHelper;


  7.     my (
  8.       $command, $ssh_user, $orig_master_host,
  9.       $orig_master_ip, $orig_master_port, $new_master_host,
  10.       $new_master_ip, $new_master_port
  11.     );

  12.     my $vip = '10.0.0.10/24'; #virtual ip
  13.     my $key = "2";
  14.     my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip";
  15.     my $ssh_stop_vip = "/sbin/ifconfig eth0:$key down";


  16.     GetOptions(
  17.       'command=s' => \$command,
  18.       'ssh_user=s' => \$ssh_user,
  19.       'orig_master_host=s' => \$orig_master_host,
  20.       'orig_master_ip=s' => \$orig_master_ip,
  21.       'orig_master_port=i' => \$orig_master_port,
  22.       'new_master_host=s' => \$new_master_host,
  23.       'new_master_ip=s' => \$new_master_ip,
  24.       'new_master_port=i' => \$new_master_port,
  25.       );
  26.     exit &main();

  27.     sub main {
  28.       if ( $command eq "stop" || $command eq "stopssh" ) {

  29.         # $orig_master_host, $orig_master_ip, $orig_master_port are passed.
  30.         # If you manage master ip address at global catalog database,
  31.         # invalidate orig_master_ip here.
  32.         my $exit_code = 1;
  33.         eval {
  34.           print "Disabling the VIP on old master: $orig_master_host \n";
  35.               &stop_vip();
  36.           $exit_code = 0;
  37.               # updating global catalog, etc

  38.         };
  39.         if ($@) {
  40.           warn "Got Error: $@\n";
  41.           exit $exit_code;
  42.         }
  43.         exit $exit_code;
  44.       }
  45.       elsif ( $command eq "start" ) {

  46.         # all arguments are passed.
  47.         # If you manage master ip address at global catalog database,
  48.         # activate new_master_ip here.
  49.         # You can also grant write access (create user, set read_only=0, etc) here.
  50.         my $exit_code = 10;
  51.         eval {
  52.           print "Enabling the VIP - $vip on old master: $new_master_host \n";
  53.               &start_vip();
  54.           $exit_code = 0;
  55.         };
  56.         if ($@) {
  57.           warn $@;

  58.           # If you want to continue failover, exit 10.
  59.           exit $exit_code;
  60.         }
  61.         exit $exit_code;
  62.       }
  63.       elsif ( $command eq "status" ) {

  64.         # do nothing
  65.         exit 0;
  66.       }
  67.       else {
  68.         &usage();
  69.         exit 1;
  70.       }
  71.     }

  72.     # Enable the VIP on the new_master
  73.     sub start_vip() {
  74.         `ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
  75.     }

  76.     # Disable the VIP on the old_master

  77.     sub stop_vip() {
  78.     my $ssh_user = "root";
  79.         `ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;
  80.     }

  81.     sub usage {
  82.       print
  83.     "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";
  84.     }

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26735168/viewspace-2096305/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/26735168/viewspace-2096305/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值