1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings FATAL => 'all';
  5.  
  6. use Getopt::Long;
  7.  
  8. my (
  9. $command, $ssh_user, $orig_master_host, $orig_master_ip,
  10. $orig_master_port, $new_master_host, $new_master_ip, $new_master_port
  11. );
  12.  
  13. my $vip = '192.168.237.120/24';
  14. my $key = '2';
  15. my $ssh_start_vip = "/sbin/ifconfig eno16777736:$key $vip";
  16. my $ssh_stop_vip = "/sbin/ifconfig eno16777736:$key down";
  17.  
  18. GetOptions(
  19. 'command=s' => \$command,
  20. 'ssh_user=s' => \$ssh_user,
  21. 'orig_master_host=s' => \$orig_master_host,
  22. 'orig_master_ip=s' => \$orig_master_ip,
  23. 'orig_master_port=i' => \$orig_master_port,
  24. 'new_master_host=s' => \$new_master_host,
  25. 'new_master_ip=s' => \$new_master_ip,
  26. 'new_master_port=i' => \$new_master_port,
  27. );
  28.  
  29. exit &main();
  30.  
  31. sub main {
  32.  
  33. print "\n\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\n\n";
  34.  
  35. if ( $command eq "stop" || $command eq "stopssh" ) {
  36.  
  37. my $exit_code = ;
  38. eval {
  39. print "Disabling the VIP on old master: $orig_master_host \n";
  40. &stop_vip();
  41. $exit_code = ;
  42. };
  43. if ($@) {
  44. warn "Got Error: $@\n";
  45. exit $exit_code;
  46. }
  47. exit $exit_code;
  48. }
  49. elsif ( $command eq "start" ) {
  50.  
  51. my $exit_code = ;
  52. eval {
  53. print "Enabling the VIP - $vip on the new master - $new_master_host \n";
  54. &start_vip();
  55. $exit_code = ;
  56. };
  57. if ($@) {
  58. warn $@;
  59. exit $exit_code;
  60. }
  61. exit $exit_code;
  62. }
  63. elsif ( $command eq "status" ) {
  64. print "Checking the Status of the script.. OK \n";
  65. exit ;
  66. }
  67. else {
  68. &usage();
  69. exit ;
  70. }
  71. }
  72.  
  73. sub start_vip() {
  74. `ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
  75. }
  76. sub stop_vip() {
  77. return 0 unless ($ssh_user);
  78. `ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;
  79. }
  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. }

mha切换脚本可用的的更多相关文章

  1. MySQL/MariaDB数据库的MHA实现高可用实战

      MySQL/MariaDB数据库的MHA实现高可用实战 作者:尹正杰  版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL高可用常见的解决方案 1>.Multi-Master ...

  2. Redis主从配置及通过Keepalived实现Redis自动切换高可用

    Redis主从配置及通过Keepalived实现Redis自动切换高可用 [日期:2014-07-23] 来源:Linux社区  作者:fuquanjun [字体:大 中 小]   一:环境介绍: M ...

  3. MySQL数据库主从切换脚本自动化

    MySQL数据库主从切换脚本自动化 本文转载自:https://blog.csdn.net/weixin_36135773/article/details/79514507 在一些实际环境中,如何实现 ...

  4. MySQL--19 MHA切换日志分析

    MHA切换检测日志分析 GTID模式 [root@db03 ~]# tail -f /etc/mha/manager.log #在MySQL select ping:2006上出错(MySQL服务器已 ...

  5. [转]IP动态切换脚本

    因为公司办公室要设置固定IP才行,而家里的IP段和公司是不一样的,家里采用了DHCP机制,这样每次就得改IP设置,很是不方便,就写了这个脚本来动态切换,很流畅的说!WINXP,WIN7测试通过~嘿嘿~ ...

  6. mysql+keepalived主从切换脚本 转

    Keepalived MySQL故障自动切换脚本   MySQL架构为master-slave(主从),master故障自动切换到slave上.当然也可以设置为双master,但这里有个弊端:就是当主 ...

  7. IP切换脚本

    1. 新建bat文件: 2. 将下面内容拷贝进bat文件: 3. 运行bat文件: @echo off color 00title IP切换脚本:start @echo --------------- ...

  8. mysql mha 主从自动切换 高可用

    mha(Master High Availability)目前在MySQL多服务器(超过二台),高可用方面是一个相对成熟的解决方案. 一,什么是mha,有什么特性 1. 主服务器的自动监控和故障转移 ...

  9. MySQL高可用之MHA切换测试(switchover & failover)

      Preface       I've installed MasterHA yesterday,Now let's test the master-slave switch and failove ...

随机推荐

  1. C++ smart pointer智能指针

      在C++中,程序员可以直接操作内存,给编程增加了不少的灵活性.但是灵活性是有代价的,程序员必须负责自己负责释放自己申请的内存,否则就会出现内存泄露.智能指针就是为了解决这个问题而存在的.它和其他指 ...

  2. kafka 配置文件注释

    文章转载自:http://liyonghui160com.iteye.com/blog/2163899 server.properties配置: server.properties中所有配置参数说明( ...

  3. MySQL 5.6学习笔记(数据表基本操作)

    1. 创建数据表 1.1 最基本的语法 CREATE TABLE tbl_name (col_name column_definition,...) [table_options] -column_d ...

  4. Atitit opencv 模板匹配

    Atitit opencv 模板匹配 1.1. 图片1 1.2. Atitit opencv 模板匹配  6中匹配算法貌似效果区别不大1 1.3. 对模板缩放的影响 一般的缩放可以,太大了就歇菜了.. ...

  5. Oracle Time Model Statistics(时间模型统计)

    Oracle数据库从10g開始,启用以时间模型统计为主.命中率为辅等性能度量指标.基于时间模型统计,主要是基于操作类型測量在数据库中花费的时间的统计信息.最重要的时间模型统计是数据库时间.或DB时间. ...

  6. mongoose查询不到数据表中的数据的问题

    在做分类管理的时候,在数据库中创建了一张category表,但使用下面这行代码始终查不到表里的数据,也没有任何报错. var Category = mongoose.model('Category', ...

  7. Flink SQL与 SQL Parser ,calcite

    http://vinoyang.com/2017/06/12/flink-table-sql-source/ Flink Table&Sql 如何结合Apache Calcite http:/ ...

  8. tensorflow笔记1:基础函数、embedding_lookup

    函数一:tf.nn.embedding_lookup() ERROR: I get this error: TypeError: Tensors in list passed to 'values' ...

  9. (转)C++头文件顺序

    转自:http://blog.csdn.net/clever101/article/details/7269058关键总结:先包含的头文件的函数会覆盖后包含的头文件的同名函数.建议采用Google C ...

  10. vue实现点击区域外部的区域,关闭该区域

    var _this = this; document.addEventListener('click',function(e){ console.log(_this.$refs.configforms ...