【Mysql】MHA配置虚拟ip
发表于:2025-11-16 作者:千家信息网编辑
千家信息网最后更新 2025年11月16日,虚拟ip飘逸说到Failover,通常有两种方式:一种是虚拟IP地址,一种是全局配置文件。MHA并没有限定使用哪一种方式,而是让用户自己选择,虚拟IP地址的方式会牵扯到其它的软件,这里就不赘述了上篇文
千家信息网最后更新 2025年11月16日【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 中下面两行注释去掉:
master_ip_failover_script=/usr/local/bin/master_ip_failovermaster_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: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: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: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: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: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: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上去了
方式
配置
地址
就是
文章
脚本
上篇
全局
文件
此方法
注释
用户
而是
软件
实验
控制
监控
选择
重构
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
电脑后台数据库导出
望京软件开发
云南商务外贸软件开发
企业邮箱服务器端口
达梦8数据库误删恢复
炫舞时代服务器无法连接
快速选择整列数据库
h5点击查询数据库
流媒体服务器有什么用
表格式数据库软件下载
小学电信网络安全主题教育
网络技术系学生党支部
网络安全与认证的
辅警网络安全心得体会300字
湖南长沙软件开发培训学校
杭州应用软件开发要多少钱
软件开发简历技能介绍
主机版2k22 连不进服务器
五十k棋牌软件开发
棋魂下载软件开发
政府免费网络安全吗
王者荣耀怎么找到原先的服务器
mysql数据库分词检索
潘多拉 vpn服务器
gtin 数据库
光网络技术的发展ppt
四川省信用社软件开发
查阅中文文献常用数据库有哪些
郝洛德服务器免费转服吗
web 服务器主机