免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 8087 | 回复: 4
打印 上一主题 下一主题

mysql mha高可用 虚拟ip问题 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2014-03-11 17:13 |只看该作者 |倒序浏览
大家好,最近搭建mha测试

测试都通过了。
但是当我想运用虚拟ip是出现了问题。
我的app1.cnf如下

  1. [server default]
  2. # mysql user and password
  3. user=root
  4. password=123456
  5. ssh_user=root
  6. # working directory on the manager
  7. manager_workdir=/var/log/masterha/app1
  8. # working directory on MySQL servers
  9. remote_workdir=/var/log/masterha/app1
  10. ping_interval=1

  11. shutdown_script=""

  12. master_ip_failover_script=/usr/local/bin/master_ip_failover

  13. master_ip_online_change_script=/usr/local/bin/master_ip_online_change_script

  14. report_script=""
  15. [server1]
  16. hostname=192.168.1.42
  17. candidate_master=1

  18. [server2]
  19. hostname=192.168.1.41
  20. candidate_master=1

  21. [server3]
  22. hostname=192.168.1.47
  23. no_master=1
复制代码
当我在app1.cnf中启用master_ip_failover_script=/usr/local/bin/master_ip_failover这句的时候就出问题。

[error][/usr/lib/perl5/vendor_perl/MHA/MasterMonitor.pm, ln315] Error happend on checking configurations. Can't exec "/usr/local/bin/master_ip_failover": Permission denied at /usr/lib/perl5/vendor_perl/MHA/ManagerUtil.pm line 68.
提示的68行内容: return MHA::NodeUtil::system_rc( system($cmd) );

我的master_ip_failover文件脚本代码如下。来自网络,我只修改了虚拟ip。希望有相关经验的朋友不吝赐教!谢谢。
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings FATAL => 'all';

  4. use Getopt::Long;

  5. my (
  6.     $command,          $ssh_user,        $orig_master_host, $orig_master_ip,
  7.     $orig_master_port, $new_master_host, $new_master_ip,    $new_master_port
  8. );

  9. # my $vip = '172.16.21.119/24';  # Virtual IP
  10. my $vip = '192.168.1.250/24';  # Virtual IP
  11. my $key = "1";
  12. my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip";
  13. my $ssh_stop_vip = "/sbin/ifconfig eth0:$key down";

  14. GetOptions(
  15.     'command=s'          => \$command,
  16.     'ssh_user=s'         => \$ssh_user,
  17.     'orig_master_host=s' => \$orig_master_host,
  18.     'orig_master_ip=s'   => \$orig_master_ip,
  19.     'orig_master_port=i' => \$orig_master_port,
  20.     'new_master_host=s'  => \$new_master_host,
  21.     'new_master_ip=s'    => \$new_master_ip,
  22.     'new_master_port=i'  => \$new_master_port,
  23. );

  24. exit &main();

  25. sub main {

  26.     print "\n\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\n\n";

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

  28.         # $orig_master_host, $orig_master_ip, $orig_master_port are passed.
  29.         # If you manage master ip address at global catalog database,
  30.         # invalidate orig_master_ip here.
  31.         my $exit_code = 1;
  32.         eval {
  33.             print "Disabling the VIP on old master: $orig_master_host \n";
  34.             &stop_vip();
  35.             $exit_code = 0;
  36.         };
  37.         if ($@) {
  38.             warn "Got Error: $@\n";
  39.             exit $exit_code;
  40.         }
  41.         exit $exit_code;
  42.     }
  43.     elsif ( $command eq "start" ) {

  44.         # all arguments are passed.
  45.         # If you manage master ip address at global catalog database,
  46.         # activate new_master_ip here.
  47.         # You can also grant write access (create user, set read_only=0, etc) here.
  48.         my $exit_code = 10;
  49.         eval {
  50.             print "Enabling the VIP - $vip on the new master - $new_master_host \n";
  51.             &start_vip();
  52.             $exit_code = 0;
  53.         };
  54.         if ($@) {
  55.             warn $@;
  56.             exit $exit_code;
  57.         }
  58.         exit $exit_code;
  59.     }
  60.     elsif ( $command eq "status" ) {
  61.         print "Checking the Status of the script.. OK \n";
  62.         `ssh $ssh_user\@cluster1 \" $ssh_start_vip \"`;
  63.         exit 0;
  64.     }
  65.     else {
  66.         &usage();
  67.         exit 1;
  68.     }
  69. }

  70. # A simple system call that enable the VIP on the new master
  71. sub start_vip() {
  72.     `ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
  73. }
  74. # A simple system call that disable the VIP on the old_master
  75. sub stop_vip() {
  76.     `ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;
  77. }

  78. sub usage {
  79.     print
  80.     "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";
  81. }
复制代码

论坛徽章:
0
2 [报告]
发表于 2014-03-11 17:54 |只看该作者
解决了。呵呵谢谢qq群里的朋友提醒,考进来的脚本要赋权在usr/local/bin 下执行chmod +x *
另外如果出现下面的问题
?#!/usr/bin/env: No such file or directory (2011-05-10 14:03:25)转载▼

这个问题是由于源码格式编码错误;notepad++里面,点击菜单 格式 - 以UTF-8无BOM格式编码, 保存重新编译运行即可

论坛徽章:
3
丑牛
日期:2014-02-25 15:19:10金牛座
日期:2014-02-28 19:01:322015亚冠之西悉尼流浪者
日期:2015-06-10 15:01:09
3 [报告]
发表于 2014-03-12 15:01 |只看该作者
本帖最后由 pxf520 于 2014-03-12 15:05 编辑

不考虑arp问题 ,小心会死得很惨的。

论坛徽章:
0
4 [报告]
发表于 2014-03-13 10:25 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
5 [报告]
发表于 2014-03-17 10:02 |只看该作者
本地测试都搞定了。。可惜服务器不许连接外网,,,依赖包问题啊纠结死了,按照yum命令下载提示的rpm文件,我单独下了相关rpm包,可惜安装时还是提示各种依赖。。不断尝试中不知道是否可行。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP