【Mysql】MHA配置虚拟ip
发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,虚拟ip飘逸说到Failover,通常有两种方式:一种是虚拟IP地址,一种是全局配置文件。MHA并没有限定使用哪一种方式,而是让用户自己选择,虚拟IP地址的方式会牵扯到其它的软件,这里就不赘述了上篇文
千家信息网最后更新 2025年02月02日【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安全错误
数据库的锁怎样保障安全
黑龙江新一代网络技术基础
人工智能数据库哪个最好
育才网络技术
网络安全二本有哪些
三级网络技术难考么
海曙一站式软件开发外包
网络安全法第三次审议时间
河北联想服务器虚拟化定制
重庆工业软件开发怎么样
河北高院网络安全
热血江湖取服务器状态值
学什么数据库好
大华视频服务器的作用有哪些
lte无线网络技术交流
3家公司被网络安全审查
数据库列级指定外键
威海量化积分管理软件开发公司
头歌实践教学平台数据库
上网用代理服务器
人间地狱服务器问题
laravel查询数据库
防控网络安全知识
树型数据库
宿州映雪网络技术服务有限公司
生存战争服务器1
财讯杂志在万方数据库收录吗
大唐高鸿网络安全事业部
好用的服务器防护软件下载
文件管理服务器ftp
软件开发专业自考