首页 > 数据库 > 文库 > 正文

MHA配备虚拟ip

2022-08-01 18:56:46
字体:
来源:转载
供稿:网友
        虚拟ip飘逸
        说到Failover,通常有两种方式:一种是虚拟IP地址,一种是全局配置文件。
        MHA并没有限定使用哪一种方式,而是让用户自己选择,虚拟IP地址的方式会牵扯到其它的软件,这里就不赘述了
       上篇文章搭建mha+keepalive就是通过keepalive来控制虚拟ip,本片文章在介绍一种虚拟ip的方式
 
配置虚拟ip
采用ifconfig的方式
/sbin/ifconfig eth0:1 192.168.6.66/24
删除VIP:
/sbin/ifconfig eth0:1 down
网上找了一个master_ip_failover脚本就是用此方法更改VIP:
[root@localhost app1]# more /usr/local/bin/master_ip_online_change_script
#!/usr/bin/env perl
use strict;
use warnings FATAL => 'all';
 
my $vip = '192.168.6.66/24'; # Virtual IP
my $key = "1";
my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig eth0:$key down";
 
GetOptions(
    'command=s' => /$command,
    'ssh_user=s' => /$ssh_user,
    'orig_master_host=s' => /$orig_master_host,
    'orig_master_ip=s' => /$orig_master_ip,
    'orig_master_port=i' => /$orig_master_port,
    'new_master_host=s' => /$new_master_host,
    'new_master_ip=s' => /$new_master_ip,
    'new_master_port=i' => /$new_master_port,
 
sub usage {
    print
    "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=po
rt/n";
}
 
将此脚本复制两次到/usr/local/bin, 分别命名为master_ip_failover 和master_ip_online_change_script
 
然后将/etc/app1.cnf 中下面两行注释去掉:
 
master_ip_failover_script=/usr/local/bin/master_ip_failover
master_ip_online_change_script=/usr/local/bin/master_ip_online_change_script
 
 
实验
1.主库(115)添加一个vip
[root@node2 .ssh]# /sbin/ifconfig eth0:1 192.168.6.66/24
[root@node2 .ssh]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 08:00:27:03:1b:a1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.6.115/24 brd 192.168.6.255 scope global eth0
    inet 192.168.6.66/24 brd 192.168.6.255 scope global secondary eth0:1
    inet6 fe80::a00:27ff:fe03:1ba1/64 scope link
       valid_lft forever preferred_lft forever
 
2.关闭主库mysql
[root@node2 .ssh]# /etc/init.d/mysqld stop
Stopping mysqld:                                           [  OK  ]
[root@node2 .ssh]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 08:00:27:03:1b:a1 brd ff:ff:ff:ff:ff:ff
    inet 192.168.6.115/24 brd 192.168.6.255 scope global eth0           ---vip飘走了
    inet6 fe80::a00:27ff:fe03:1ba1/64 scope link
       valid_lft forever preferred_lft forever
 
3 查看newmaster(114)的ip                                                    ----vip已飘到new master上了
[root@node1 ~]# ip a
 
4 重构mysql.重启mha监控
5 关闭114mysql,vip飘回115上去了

(编辑:错新网)

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选