MHA高可用架构

  • 用一个管理节点监控后端数据库主库可用性
  • 提供VIP漂移接口,不提供具体方法
  • 提供补全从库日志的脚本
 
MHA
  • 监控主库,提供自动主从切换;
  • 提供VIP漂移接口
  • 提供补全从库日志的脚本
 
MHA的安装步骤

  1. 规划
  2. 配置服务器间域名和ssh互信访问
  3. 在manager节点安装MHA node 和manager组件及依赖包
  4. 在数据库服务器安装MHA node组件及依赖包
  5. 配置VIP管理脚本master_ip_failover和master_ip_online_change
  6. 配置MHA配置文件mha_manager.cnf
  7. 数据库配置主从,添加mha连接用户 ...etc
  8. 启动MHA开始监控数据库主从集群
 
演示

演示MHA部署-环境介绍
 
 
环境请自行提取下载
http://pan.baidu.com/s/1qXDOeba
 
操作步骤
操作步骤:
- .确保主从复制配置完成
- 此列中主从复制账号repl
-
- ##
-
- 虚拟ip已经,部署在主库
- 主库,为mha提供mha账户
-
-
-
-
- .确保hosts和hostname配置正确
- ##
-
- root@debtest1:~/.ssh# cat /etc/hosts
- 127.0.0.1 localhost
- 192.168.0.113 debtest1.sam.test debtest1
- 192.168.0.114 debtest2.sam.test debtest2
- 192.168.0.115 debtest3.sam.test debtest3
-
- # The following lines are desirable for IPv6 capable hosts
- :: localhost ip6-localhost ip6-loopback
- ff02:: ip6-allnodes
- ff02:: ip6-allrouters
- root@debtest1:~/.ssh# cat /etc/hostname
- debtest1
-
- ###############################################################################
-
- .使用ssh-keygen工具生成统一公私钥对,并同步到所有三台机器.测试公私钥验证访问
- ##
-
- ssh-keygen -t rsa
-
- cd ~/.ssh
- cat id_rsa.pub authorized_keys
-
-
- scp ./* root@debtest2:/root/.ssh/
- scp ./* root@debtest3:/root/.ssh/
-
-
- ssh debtest1
- ssh debtest2
- ssh debtest3
-
-
- ###############################################################################
-
- 3.规划节点用户和ip配置
- ##
-
-
- 192.168.0.113 debtest1 --> master
- 192.168.0.114 debtest2 --> mysql1(master)
- 192.168.0.115 debtest3 --> mysql2(slave)
- 192.168.0.119 vip
-
- 定好虚拟ip后别忘了在当前的主库上添加虚拟ip
- ##
- ip addr add 192.168.0.119/32 dev eth1
-
- #删除虚拟ip的命令
- ##ip addr del 192.168.0.119/32 dev eth1
-
- ###############################################################################
-
- 4.在全部节点上安装mha node包和其依赖包
- ##
-
-
- debtest1,debtest1,debtest1
-
- apt-get install libdbd-mysql-perl
-
- dpkg -i mha4mysql-node_0.53_all.deb
-
- ###############################################################################
-
- 5.仅需要在manager节点上安装mha manager包及其依赖包
- ##
-
- debtest1
-
- apt-get install libdbd-mysql-perl
- apt-get install libconfig-tiny-perl
- apt-get install liblog-dispatch-perl
- apt-get install libparallel-forkmanager-perl
-
- dpkg -i mha4mysql-manager_0.53_all.deb
-
-
- ###############################################################################
-
-
- 6.建立配置文件目录,编辑mha必要的三个文件,一个配置文件,2个虚拟ip管理脚本且内容可以一致
- ##
-
- master_ip_online_change
- master_ip_failover
- mha_manager.cnf
-
-
- ###############################################################################
-
- 7.可以尝试验证一下配置是否成功
- ##
-
- masterha_check_ssh --conf=./mha_manager.cnf
- masterha_check_repl --conf=./mha_manager.cnf
-
- ###############################################################################
-
- 8.在manager节点启动mha服务,然后观察日志,并尝试关闭当前主库,注意观察日志,主要看失效发现,日志检测,ip漂移和角色切换过程
- ##
-
- nohup /usr/bin/masterha_manager --conf=/root/mha_base/mha_manager.cnf --ignore_last_failover < /dev/null > /root/mha_base/manager.log 2>&1 &

MHA配置文件

MHA配置文件

[server default]
manager_workdir=/root/mha_base
manager_log=/root/mha_base/manager.log
remote_workdir=/root/mha_base ssh_user=root
ssh_port=
user=mha
password=mha
repl_user=repl
repl_password=repl
multi_tier_slave=
ping_interval=
ping_type=CONNECT
master_ip_failover_script=/root/mha_base/master_ip_failover
master_ip_online_change_script=/root/mha_base/master_ip_online_change
secondary_check_script=/usr/bin/masterha_secondary_check -s 192.168.0.113 -s 192.168.0.115 --user=root --port= --master_host=debtest2 --master_ip=192.168.0.114 --master_port= [server1]
candidate_master=
ignore_fail=
check_repl_delay =
hostname=debtest2
ip=192.168.0.114
port=
ssh_port=
master_binlog_dir=/var/log/mysql/ [server2]
candidate_master=
ignore_fail=
check_repl_delay =
hostname=debtest3
ip=192.168.0.115
port=
ssh_port=
master_binlog_dir=/var/log/mysql/
 
 
 
VIP漂移脚本
#!/usr/bin/env perl

## Note: This is a sample script and is not complete. Modify the script based on your environment.

use strict;
use warnings FATAL => 'all'; use Getopt::Long;
use MHA::DBHelper; 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.0.119/24'; #virtual ip
my $ssh_start_vip = "ip addr add $vip dev eth1";
my $ssh_stop_vip = "ip addr del $vip dev eth1"; 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 {
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 = ;
eval {
print "Disabling the VIP on old master: $orig_master_host \n";
&stop_vip();
$exit_code = ;
# updating global catalog, etc };
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=, etc) here.
my $exit_code = ;
eval {
print "Enabling the VIP - $vip on old master: $new_master_host \n";
&start_vip();
$exit_code = ;
};
if ($@) {
warn $@; # If you want to continue failover, exit .
exit $exit_code;
}
exit $exit_code;
}
elsif ( $command eq "status" ) { # do nothing
exit ;
}
else {
&usage();
exit ;
}
} # Enable the VIP on the new_master
sub start_vip() {
`ssh $ssh_user\@$new_master_host \" $ssh_start_vip \"`;
} # Disable the VIP on the old_master sub stop_vip() {
my $ssh_user = "root";
`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=port\n";
}
 
 
 
 
 
 
 
 
 
 
 
 

mysql高可用框架-MHA的更多相关文章

  1. MySQL高可用之MHA (转)

    MySQL高可用之MHA MHA简介 MHA是由日本人yoshinorim(原就职于DeNA现就职于FaceBook)开发的比较成熟的MySQL高可用方案.MHA能够在30秒内实现故障切换,并能在故障 ...

  2. mysql高可用方案MHA介绍

    mysql高可用方案MHA介绍 概述 MHA是一位日本MySQL大牛用Perl写的一套MySQL故障切换方案,来保证数据库系统的高可用.在宕机的时间内(通常10-30秒内),完成故障切换,部署MHA, ...

  3. MySQL高可用方案MHA自动Failover与手动Failover的实践及原理

    集群信息 角色                             IP地址                 ServerID      类型 Master                     ...

  4. MySQL高可用方案--MHA部署及故障转移

    架构设计及必要配置 主机环境 IP                 主机名             担任角色 192.168.192.128  node_master    MySQL-Master| ...

  5. MySQL高可用方案MHA在线切换的步骤及原理

    在日常工作中,会碰到如下的场景,如mysql数据库升级,主服务器硬件升级等,这个时候就需要将写操作切换到另外一台服务器上,那么如何进行在线切换呢?同时,要求切换过程短,对业务的影响比较小. MHA就提 ...

  6. 【DB宝42】MySQL高可用架构MHA+ProxySQL实现读写分离和负载均衡

    目录 一.MHA+ProxySQL架构 二.快速搭建MHA环境 2.1 下载MHA镜像 2.2 编辑yml文件,创建MHA相关容器 2.3 安装docker-compose软件(若已安装,可忽略) 2 ...

  7. MySQL高可用之MHA的搭建 转

     http://www.cnblogs.com/muhu/p/4045780.html http://www.cnblogs.com/gomysql/p/3675429.html http://www ...

  8. MySQL高可用方案MHA的部署和原理

    MHA(Master High Availability)是一套相对成熟的MySQL高可用方案,能做到在0~30s内自动完成数据库的故障切换操作,在master服务器不宕机的情况下,基本能保证数据的一 ...

  9. MySQL高可用之MHA的搭建

    MySQL MHA架构介绍: MHA(Master High Availability)目前在MySQL高可用方面是一个相对成熟的解决方案,它由日本DeNA公司youshimaton(现就职于Face ...

随机推荐

  1. React Native组件之Text

    React Native组件之Text相当于iOS中的UILabel. 其基本属性如下: /** * Sample React Native App * https://github.com/face ...

  2. PHP正则表达式的快速学习方法

    1.入门简介 简单的说,正则表达式是一种可以用于模式匹配和替换的强有力的工具.我们可以在几乎所有的基于UNIX系统的工具中找到正则表达式的身影,例如,vi编辑器,Perl或PHP脚本语言,以及awk或 ...

  3. XML Schema的基本语法(转)

    XML Schema的基本语法(转) XSDL(XML Schema定义语言)由元素.属性.命名空间和XML文档种的其他节点构成的. 一.XSD中的元素 XSD文档至少要包含:schema根元素和XM ...

  4. js实现时间控件

    <html><head> <title>时间控件</title></head><body > <input name=&q ...

  5. UVA 572

    这是一道纯正的深度优先搜索题目. 题目要求在有多少个不同的块,而不同块的定义则是,一个块中的任意一点和l另一个块中的任意一点不会相连,而相连的定义则是 在横向.纵向和对角线上相连. #include& ...

  6. ✡ leetcode 166. Fraction to Recurring Decimal 分数转换 --------- java

    Given two integers representing the numerator and denominator of a fraction, return the fraction in ...

  7. 配置recovery_min_apply_delay后重启standby节点报错:psql: FATAL: the database system is starting up

    环境: pg版本:PostgreSQL 9.4.4 on x86_64 系统版本:CentOS release 6.6 linux内核版本:2.6.32-504.8.1.el6.x86_64 今天测试 ...

  8. C#里Attribute属性

    系统内置属性 系统内置的Attribute属性Obsolete,被个这属性标记的方法在别的地方被调用的时候会有警告提示; 这个属性还可以指定第二个布尔参数,设置编译时是否报错; 例: [Obsolet ...

  9. 【C】 04 - 表达式和语句

    程序的生命力体现在它千变万化的行为,而再复杂的系统都是由最基本的语句组成的.C语句形式简单自由,但功能强大.从规范的角度学习C语法,一切显得简单而透彻,无需困扰于各种奇怪的语法. 1. 表达式(exp ...

  10. 7、java实现的两种单例模式

    /* 两种单例模式的演示 */ //饿汉式 class Signal { private Signal(){} private Signal s = new Signal(); public stat ...