【Mysql】MHA配置虛擬ip
虛擬ip飄逸
-
說到Failover,通常有兩種方式:一種是虛擬IP地址,一種是全域性配置檔案。
- MHA並沒有限定使用哪一種方式,而是讓使用者自己選擇,虛擬IP地址的方式會牽扯到其它的軟體,這裡就不贅述了
-
上篇文章搭建mha+keepalive就是透過keepalive來控制虛擬ip,本片文章在介紹一種虛擬ip的方式
配置虛擬ip
- 採用ifconfig的方式
-
/sbin/ifconfig eth0:1 192.168.6.66/24
- /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 中下面兩行註釋去掉:
實驗
-
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
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上去了
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2122973/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Linux 配置虛擬IPLinux
- MySQL MHA配置MySql
- Mysql MHA部署-04MHA配置MySql
- 虛擬機器(三)虛擬機器配置靜態Ip虛擬機
- mysql5.7MHA配置MySql
- VMware Fusion虛擬機器配置固定IP虛擬機
- MYSQL + MHA +keepalive + VIP安裝配置(二)--MHA的配置MySql
- VMware配置centos虛擬機器靜態ipCentOS虛擬機
- linux配置基於ip的虛擬主機Linux
- suse 增加虛擬ip
- 【MySQL】MHA的基本配置及註釋MySql
- MYSQL + MHA +keepalive + VIP安裝配置(一)--MYSQL安裝配置MySql
- RAC中的虛擬IP
- 虛擬機器 NAT 網路靜態ip配置記錄虛擬機
- VMware 虛擬機器,配置 Ubuntu 22.04 靜態 IP 地址。虛擬機Ubuntu
- MHA+MySQL主從配置實現MySQL高可用MySql
- 【MHA】mysql高可用之MHAMySql
- mysql虛擬表MySql
- MySQL虛擬列MySql
- 配置虛擬機器叢集常用設定主機IP操作虛擬機
- MHA配置搭建
- MYSQL+複製+MHA+VIP配置總結MySql
- mysql之MHAMySql
- 詳解Nginx 虛擬主機配置的三種方式(基於IP)Nginx
- mac上使用Vmware Fusion虛擬機器配置Centos的靜態ipMac虛擬機CentOS
- 《轉》QEMU-KVM建立虛擬機器自動指定IP的配置虛擬機
- MySQL MHA部署 Part 5 MHA部署指南MySql
- 虛擬IP管理系統設計
- 10G RAC 的虛擬IP
- 【VIP】調整RAC虛擬IP地址(VIP)及虛擬主機名
- Nginx虛擬主機配置Nginx
- MYSQL + MHA +keepalive + VIP安裝配置(三)--keepalived安裝配置MySql
- (轉)【VIP】調整RAC虛擬IP地址(VIP)及虛擬主機名
- 【Mysql】MHA的原理MySql
- MySQL MHA介紹MySql
- 【MySQL】MHA安裝MySql
- mysql 5.7 虛擬列功能MySql
- 一臺主機虛擬多個ip