虚拟ip飘逸
配置虚拟ip
删除VIP:- /sbin/ifconfig eth0:1 down
-
[root@localhost app1]# more /usr/local/bin/master_ip_online_change_script
-
#!/usr/bin/env perl
-
use strict;
-
use warnings FATAL => 'all';
-
-
use Getopt::Long;
-
-
my (
-
$command, $ssh_user, $orig_master_host, $orig_master_ip,
-
$orig_master_port, $new_master_host, $new_master_ip, $new_master_port
-
);
-
-
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,
-
);
-
-
exit &main();
-
-
sub main {
-
-
print "\n\nIN SCRIPT TEST====$ssh_stop_vip==$ssh_start_vip===\n\n";
-
-
if ( $command eq "stop" || $command eq "stopssh" ) {
-
-
# $orig_master_host, $orig_master_ip, $orig_master_port are passed.
-
# If you manage master ip address at global catalog database,
-
# invalidate orig_master_ip here.
-
my $exit_code = 1;
-
eval {
-
print "disabling the VIP on old master: $orig_master_host \n";
-
&stop_vip();
-
$exit_code = 0;
-
};
-
if ($@) {
-
warn "Got Error: $@\n";
-
exit $exit_code;
-
}
-
exit $exit_code;
-
}
-
elsif ( $command eq "start" ) {
-
-
# all arguments are passed.
-
# If you manage master ip address at global catalog database,
-
# activate new_master_ip here.
-
# You can also grant write access (create user, set read_only=0, etc) here.
-
my $exit_code = 10;
-
eval {
-
print "Enabling the VIP - $vip on the new master - $new_master_host \n";
-
&start_vip();
-
$exit_code = 0;
-
};
-
if ($@) {
-
warn $@;
-
exit $exit_code;
-
}
-
exit $exit_code;
-
}
-
elsif ( $command eq "status" ) {
-
print "Checking the Status of the script.. OK \n";
-
`ssh $ssh_user\@cluster1 \" $ssh_start_vip \"`;
-
exit 0;
-
}
-
else {
-
&usage();
-
exit 1;
-
}
-
}
-
-
# A simple system call that enable the VIP on the new master
-
sub start_vip() {
-
`ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
-
}
-
# A simple system call that disable the VIP on the old_master
-
sub stop_vip() {
-
`ssh $ssh_user\@$orig_master_host \" $ssh_stop_vip \"`;
-
}
-
-
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
实验
-
[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 -
-
[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
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:7a:c6:9c brd ff:ff:ff:ff:ff:ff
inet 192.168.6.114/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:fe7a:c69c/64 scope link
valid_lft forever preferred_lft forever
- 4 重构MysqL.重启mha监控
- 5 关闭114MysqL,vip飘回115上去了
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。