MySQL5.6基于MHA方式高可用搭建
master 10.205.22.185 #MHA node
slave1 10.205.22.186 #MHA node+MHA manager
slave2 10.205.22.187 #MHA node
三台服务器的MySQL已经搭建好主从架构,并互相配置好ssh免密码登录。
1.下载MHA,并安装MHA包的依赖软件
https://downloads.mariadb.com/MHA(或者 https://github.com/yotoobo/linux/tree/master/mha)
yum install perl-Config-Tiny perl-Log-Dispatch perl-Time-HiRes perl-Parallel-ForkManager
2.安装MHA软件包
rpm -ivh mha4mysql-node-0.56-.el6.noarch #所有节点安装
rpm -ivh mha4mysql-manager-0.56-0.el6.noarch #186管理节点安装
3.创建用户mha管理的账号,在所有mysql服务器上都需要执行:
GRANT ALL PRIVILEGES ON *.* TO 'mha_rep'@'10.205.22.%' IDENTIFIED BY ''; 如果是在slave服务器上安装的manager,则需要创建以本机hostname名连接的账号,不然masterha_check_repl测试通不过。
GRANT ALL PRIVILEGES ON *.* TO 'mha_rep'@'master(主机名)' IDENTIFIED BY ''
4.在MHA manager服务器添加配置文件/etc/masterha/app1.cnf(自定义),并创建相关目录和修改权限
[server default]
manager_workdir=/var/log/masterha/app1
manager_log=/var/log/masterha/app1/manager.log
secondary_check_script= masterha_secondary_check -s 10.205.22.185 -s 10.205.22.186 #实现多路由监测Master的可用性
master_ip_failover_script=/usr/local/scripts/master_ip_failover user=mha_rep
password= ssh_user=root
repl_user=repl
repl_password=password
ping_interval= [server1]
hostname=10.205.22.185
candidate_master=
master_binlog_dir=/home/data/mysql/binlog [server2]
hostname=10.205.22.186
candidate_master=
master_binlog_dir=/home/data/mysql/binlog [server3]
hostname=10.205.22.187
no_master=
master_binlog_dir=/home/data/mysql/binlog
mkdir -p /home/data/mysql/binlog #创建相关目录
chown -R mysql.mysql /home/data/mysql/binglog #修改权限
5.编写自动切换VIP的脚本,/usr/local/scripts/master_ip_failover ,并加上可执行权限+x。
!/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 = '10.205.22.111/24'; # Virtual IP
my $gateway = '10.205.22.1'; #Gateway IP
my $interface = 'eth0';
my $key = "";
my $ssh_start_vip = "/sbin/ifconfig $interface:$key $vip;/sbin/arping -I $interface -c 3 -s $vip $gateway >/dev/null 2>&1";
my $ssh_stop_vip = "/sbin/ifconfig $interface:$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 = ;
eval {
print "Disabling the VIP on old master: $orig_master_host \n";
&stop_vip();
$exit_code = ;
};
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 the new master - $new_master_host \n";
&start_vip();
$exit_code = ;
};
if ($@) {
warn $@;
exit $exit_code;
}
exit $exit_code;
}
elsif ( $command eq "status" ) {
print "Checking the Status of the script.. OK \n";
`ssh $ssh_user\@$orig_master_host \" $ssh_start_vip \"`;
exit ;
}
else {
&usage();
exit ;
}
}
# 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 {
"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";
}
6.检查配置文件
利用mha工具检测ssh
masterha_check_ssh --conf=/etc/masterha_application.cnf 使用mha工具check检查repl环境
masterha_check_repl --conf=/etc/masterha_application.cnf
7.开启MHA manager,并查看状态
开启masterha_manager
nohup masterha_manager --conf=/etc/masterha/app1.cnf > /tmp/mha_manager.log >& &
(masterha_stop --conf=/etc/masterha/app1.cnf #关闭时使用的命令) 查看
masterha_check_status --conf=/etc/masterha/app1.cnf
8.模拟MySQL故障,查看VIP漂移和MySQL自动切换情况(切换后MHA服务会自动停止)
/etc/init.d/mysqld stop #master上操作
在manager上查看切换日志:tail -f /var/log/masterha/app1/manager.log
查看备用节点情况:show master status \G
9.MySQL故障服务器重新加入MHA环境
.把故障服务器设为新的slave
.重新启动MHA manager
.查看MHA状态
10.在线手动切换主从,没有启用MHA自动切换功能
1.原master出现故障
masterha_stop --conf=/etc/masterha/app1.cnf #停止
masterha_master_switch --master_state=dead --conf=/etc/masterha/app1.cnf --dead_master_host=10.205.22.185 --dead_master_port= --new_master_host=10.205.22.186 --new_master_port= --ignore_last_failover 2.把原master变为slave切换
masterha_master_switch --conf=/etc/masterha/app1.cnf --master_state=alive --new_master_host=10.205.22.185 --new_master_port=3306 --orig_master_is_new_slave
为了保证数据完全一致性,在最快的时间内完成切换,MHA的在线切换必须满足以下条件才会切换成功,否则会切换失败。
1.所有slave的IO线程都在运行
2.所有slave的SQL线程都在运行
3.所有的show slave status的输出中Seconds_Behind_Master参数小于或者等于running_updates_limit秒,如果在切换过程中不指定running_updates_limit,那么默认情况下running_updates_limit为1秒。
4.在master端,通过show processlist输出,没有一个更新花费的时间大于running_updates_limit秒。
MySQL5.6基于MHA方式高可用搭建的更多相关文章
- 技术实战:基于 MHA 方式实现 MySQL 的高可用(转)
转自:http://os.51cto.com/art/201307/401702_all.htm MHA故障转移可以很好的帮我们解决从库数据的一致性问题,同时最大化挽回故障发生后的数据.本文分享了基于 ...
- 基于zookeeper的高可用Hadoop HA集群安装
(1)hadoop2.7.1源码编译 http://aperise.iteye.com/blog/2246856 (2)hadoop2.7.1安装准备 http://aperise.iteye.com ...
- MySQL/MariaDB数据库的MHA实现高可用实战
MySQL/MariaDB数据库的MHA实现高可用实战 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.MySQL高可用常见的解决方案 1>.Multi-Master ...
- MaxCompute,基于Serverless的高可用大数据服务
摘要:2019年1月18日,由阿里巴巴MaxCompute开发者社区和阿里云栖社区联合主办的“阿里云栖开发者沙龙大数据技术专场”走近北京联合大学,本次技术沙龙上,阿里巴巴高级技术专家吴永明为大家分享了 ...
- 实现基于Keepalived主从高可用集群网站架构
背景 上一期我们实现了基于lvs负载均衡集群的电商网站架构,随着业务的发展,网站的访问量越来越大,网站访问量已经从原来的1000QPS,变为3000QPS,目前业务已经通过集群LVS架构可做到随时拓展 ...
- 使用Docker Compose部署基于Sentinel的高可用Redis集群
使用Docker Compose部署基于Sentinel的高可用Redis集群 https://yq.aliyun.com/articles/57953 Docker系列之(五):使用Docker C ...
- hadoop 集群HA高可用搭建以及问题解决方案
hadoop 集群HA高可用搭建 目录大纲 1. hadoop HA原理 2. hadoop HA特点 3. Zookeeper 配置 4. 安装Hadoop集群 5. Hadoop HA配置 搭建环 ...
- 基于LevelDB的高可用ActiveMQ集群
基于LevelDB的高可用ActiveMQ集群 http://donald-draper.iteye.com/blog/2347913
- hadoop+zookeeper集群高可用搭建
hadoop+zookeeper集群高可用搭建 Senerity 发布于 2 ...
随机推荐
- httpd 的坑
Httpd服务器的坑 在/etc/httpd/conf/httpd.conf中的配置信息, 有时注释到的内容仍然会生效 配置Auth时, 允许htpasswd规定的文件中的所有的用户, Require ...
- HDU 5407——CRB and Candies——————【逆元+是素数次方的数+公式】
CRB and Candies Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- 集成Springboot+MyBatis+JPA
1.前言 Springboot最近可谓是非常的火,本人也在项目中尝到了甜头.之前一直使用Springboot+JPA,用了一段时间发现JPA不是太灵活,也有可能是我不精通JPA,总之为了多学学Spri ...
- 设置Tomcat的字符编码
在 server.xml 中的 Connector 标签在加入 URIEncoding="UTF-8" 属性. <Connector port="8080" ...
- 《ArcGIS Runtime SDK for Android开发笔记》——翻译:ArcGIS Runtime SDK for Android 10.2.7发布
ArcGIS Runtime SDK for Android v10.2.7 released by Dan O'Neill on October 1, 2015(发布时间:2015年10月1日) W ...
- SqlServer存储过程中常用函数及操作
1.case语句 用于选择语句 SELECT ProductNumber, Category = CASE ProductLine WHEN 'R' THEN 'Road' WHEN 'M' THEN ...
- instanceof和相关函数
instanceof:如果左边对象是右边类型所表示类(或任意一子类)的一个实例,则返回true,否则false.判断左边真实类型是不是右边的类或它的派生类. //实例一 Object o= new L ...
- Limesurvey-2.55 (Ubuntu 16.04)
平台: Ubuntu 类型: 虚拟机镜像 软件包: limesurvey-2.55 business intelligence commercial limesurvey open-source 服务 ...
- vos优化客户线路数量
问题: 客户A打电话过来说之前给开的300线路不够用了,今天好多电话呼不出去了,线路太挤了! 麻烦增加线路,如何操作? 方法: 登陆VOS——在线对接——(客户A的对接网关ID)——双击 打开网关管理 ...
- 罗技G502设置
这个鼠标默认内置了3个档案模式,用G9键来调节. p2 蓝色 1个灯 p2 蓝色 2个灯 p3 蓝色 3个灯 如此循环设置