当前位置: 首页 > 编程日记 > 正文

MHA二种高可用架构切换演练

高可用架构一

proxysql+keepalived+mysql+mha
优势,最大程序的降低脑裂风险,可以读写分离(需要开启相应的插件支持)

一、proxysql

1、安装

tar -zxvf proxysql.tar.gz -C /usr/local/chmod -R 700 /usr/local/proxysqlcd /usr/local/proxysql/bin;./proxysqlServer.sh start

2、配置业务通过proxysql访问

1.  添加用户
cd /usr/local/proxysql/bin;server02<2018-08-15 15:34:53> /usr/local/proxysql/binroot># ./add_user.sh test test 添加业务用户(./add_user name password)
Warning: Using a password on the command line interface can be insecure.2.添加mysql master地址
cd /usr/local/proxysql/bin;root># ./set_server.sh 192.168.56.131 online   ---初始配置需要指定将流量打到哪台mysql上面
param  check ok!
Warning: Using a password on the command line interface can be insecure.(注意2个proxysql都需要进行上面的配置)3.验证proxysql
root># mysql -h 192.168.56.131 -uroot -p123456
在master上创建测试数据库
mysql> create database test;
Query OK, 1 row affected (0.00 sec)mysql> grant all on test.* to test identified by 'test';
Query OK, 0 rows affected (0.00 sec)然后使用proxysql测试验证(连接和插入正常)
##Proxysql的端口为6033
root># mysql -h 192.168.56.200 -P 6033 -u test -ptest
mysql> create table test(a int);
Query OK, 0 rows affected (0.18 sec)mysql> insert into test values(1);
Query OK, 1 row affected (0.03 sec)mysql> insert into test values(1);
Query OK, 1 row affected (0.00 sec)

二、keepalived配置

keepalived 和 proxysql配套使用,负责proxysql vip 的漂移root># yum install keepalived -y###master keepalived配置文件
server02<2018-08-15 16:04:30> /etc/keepalived
root># cat keepalived.conf 
global_defs {router_id Ha_keepalived
}
vrrp_script chk_proxysql {script "/usr/local/proxysql/bin/proxysqlServer.sh status"interval 1timeout 1fall 3rise 3user root
}
vrrp_instance VI_1 {state backup    ——两边都为backupinterface eth0virtual_router_id 66priority 100advert_int 1unicast_src_ip 192.168.56.131   —使用单播模式unicast_peer {192.168.56.132}virtual_ipaddress {192.168.56.200}track_script {chk_proxysql}notify_master /etc/keepalived/notify.sh###slave keepalved配置文件
server03<2018-08-15 16:04:30> /etc/keepalived
global_defs {router_id Ha_keepalived
}
vrrp_script chk_proxysql {script "/usr/local/proxysql/bin/proxysqlServer.sh status"interval 1timeout 1fall 3rise 3user root
}
vrrp_instance VI_1 {state backupinterface eth2virtual_router_id 66priority 100advert_int 1unicast_src_ip 192.168.56.132  —使用单播模式unicast_peer {192.168.56.131}virtual_ipaddress {192.168.56.200}track_script {chk_proxysql}notify_master /etc/keepalived/notify.sh
}

三、MHA检测

###proxysql模式
root># masterha_check_ssh --conf=/etc/masterha/proxy_app_default.cnfroot># masterha_check_repl --conf=/etc/masterha/proxy_app_default.cnfroot># masterha_check_status --conf=/etc/masterha/proxy_app_default.cnf###vip模式
root># masterha_check_ssh --conf=/etc/masterha/vip_app_default.cnfroot># masterha_check_repl --conf=/etc/masterha/vip_app_default.cnfroot># masterha_check_status --conf=/etc/masterha/vip_app_default.cnf

四、报错汇总

报错1:
图片描述
解决办法:
修复主从关系即可

模拟故障1

kill 主库的mysql进程
图片描述

查看mha的运行日志(发现mha正常切换了)
root># vim  /etc/masterha/app1/manager.log Wed Aug 15 16:22:18 2018 - [info]  All relay logs were successfully applied.
Wed Aug 15 16:22:18 2018 - [info] Getting new master's binlog name and position..
Wed Aug 15 16:22:18 2018 - [info]  mysql-bin.000004:120
Wed Aug 15 16:22:18 2018 - [info]  All other slaves should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='192.168.56.132', MASTER_PORT=3306, MASTER_LOG_FILE='mysql-bin.000004', MASTER_LOG_POS=120, MASTER_USER='repl', MASTER_PASSWORD='xxx';
Wed Aug 15 16:22:18 2018 - [info] Executing master IP activate script:
Wed Aug 15 16:22:18 2018 - [info]   /etc/masterha/app1/scripts/master_ip_failover_proxy --command=start --ssh_user=root --orig_master_host=192.168.56.131 --orig_master_ip=192.168.56.131 --orig_master_port=3306 --new_master_host=192.168.56.132 --new_master_ip=192.168.56.132 --new_master_port=3306 --new_master_user='mha' --new_master_password='123456'
Set read_only=0 on the new master.
Enabling write on the new master - 192.168.56.132:3306Warning: Using a password on the command line interface can be insecure.
Warning: Using a password on the command line interface can be insecure.
Wed Aug 15 16:22:18 2018 - [info]  OK.
Wed Aug 15 16:22:18 2018 - [info] ** Finished master recovery successfully.mha切换成功 192.168.56.132 为新的mastermysql> show slave hosts;
+-----------+------+------+-----------+--------------------------------------+
| Server_id | Host | Port | Master_id | Slave_UUID                           |
+-----------+------+------+-----------+--------------------------------------+
|         1 |      | 3306 |         2 | bce5f247-a052-11e8-b2f6-000c2911ac5e |
|         3 |      | 3306 |         2 | b9543701-a052-11e8-b2f6-000c29c77f26 |
+-----------+------+------+-----------+--------------------------------------+
2 rows in set (0.00 sec)mysql>

模拟故障2

直接将主库服务器shutdown
验证也是OK

五、手动切换维护

masterha_master_switch --master_state=alive --conf=$conf —orig_master_is_new_slave    —旧的master还存活,并且设置为slave节点(手动切换的时候,注意先停止mha——manager服务, $conf为指定的使用哪种模式的配置文件)样例
masterha_master_switch --master_state=alive --conf=/etc/masterha/proxy_app_default.cnf --orig_master_is_new_slave

高可用架构二

vip+mysql+mha

mha+vip 模式和mha+proxysql模式的不同就在于要初始化不同文件(需要将vip脚本同步到mysql的master和node节点的/etc/masterha/app1/scripts/vip.sh)

1、vip.sh脚本

修改1
server01<2018-08-15 16:56:38> /etc/masterha/app1/scripts
root># cat vip.sh 
#!/bin/shif [ $# -ne 1 ];thenecho "Usage vip.sh {start|stop} " exit 0
fiif="eth0"
key=2
vip="192.168.56.200"start_vip(){
/sbin/ifconfig $if:$key $vip/24;arping -A -c 1 $vip
}stop_vip(){
/sbin/ifconfig $if:$key down
}case $1 in 
"stop")stop_vip $2;;;
"start")start_vip $2;;;
*)echo "Usage vip.sh {start|stop} ";;
esac
手动绑定VIP到master服务器上
ifconfig eth0:2 192.168.56.200 up
###vip模式
root># masterha_check_ssh --conf=/etc/masterha/vip_app_default.cnfroot># masterha_check_repl --conf=/etc/masterha/vip_app_default.cnfroot># masterha_check_status --conf=/etc/masterha/vip_app_default.cnf

手动切换

手动切换
masterha_master_switch --master_state=alive --conf=/etc/masterha/vip_app_default.cnf --orig_master_is_new_slave

相关脚本
https://pan.baidu.com/s/1hTdh...

相关文章:

如何关闭事件跟踪程序

最近经常遇到一些独享服务器用户反应自己的服务器联系万网工程师重起后&#xff0c;重新登陆时遇到的界面不知道该如何操作问题。当您看到此界面时&#xff0c;只需要在“注释”下面的空白处随意输入字符即可激活“确定”按钮&#xff0c;点击“确定”后可以进入系统。 这个界…

(C++)1015 德才论

#include<cstdio> #include<algorithm> #include<cstring> using namespace std; const int M 100000;struct Testee{char no[10];int de;int cai;int type;//第几类 }peo[M10];bool cmp(Testee a,Testee b){//比较顺序依次为总分&#xff0c;德分&#xf…

Vim命令相关

在shell中&#xff0c;记住一些常用的vim命令&#xff0c;会在操作时候事半功倍。 光标移动 h,j,k,l,h #表示往左&#xff0c;j表示往下&#xff0c;k表示往右&#xff0c;l表示往上 Ctrl f #上一页 Ctrl b #下一页 w, e, W, E #跳到单词的后面&#xff0c;小…

做科研的几点体会

刚刚开始做实验的时候&#xff0c;别人怎么说我就怎么做&#xff0c;每天在实验台旁干到深夜&#xff0c;以为这就是科研了。两个月过去&#xff0c;突然发现自己还在原地踏步。那种感觉&#xff0c;只能用”沮丧”来形 容。我开始置疑自己的行为和观念。感觉有种习惯的力量在束…

ICMP报文分析

一.概述&#xff1a;1. ICMP同意主机或路由报告差错情况和提供有关异常情况。ICMP是因特网的标准协议&#xff0c;但ICMP不是高层协议&#xff0c;而是IP层的协议。通常ICMP报文被IP层或更高层协议&#xff08;TCP或UDP&#xff09;使用。一些ICMP报文把差错报文返回给用户进…

(C++)1029 旧键盘

#include<cstdio> #include<cstring>const int M 80;//值得注意的地方是“按照发现顺序 ” //采取的最佳策略是&#xff0c;对于字符串1中的每一个字符&#xff0c;看在字符串2中是否出现int hashmap(char c){int res 0;if(0<c&&c<9){res c-0;}e…

深入理解 python 元类

一、什么的元类 # 思考&#xff1a; # Python 中对象是由实例化类得来的&#xff0c;那么类又是怎么得到的呢&#xff1f; # 疑问&#xff1a; # python 中一切皆对象&#xff0c;那么类是否也是对象&#xff1f;如果是&#xff0c;那么它又是那个类实例化而来的呢&…

使用.NET REACTOR制作软件许可证

使用.NET REACTOR制作软件许可证 原文:使用.NET REACTOR制作软件许可证软件下载地址&#xff1a;http://www.eziriz.com/downloads.htm 做一个简单的许可证系统&#xff0c;下面是具体步骤&#xff1a;1&#xff0c; OPEN ASSEMBLY打开项目可执行文件(debug文件夹里面exe文件…

(C++)CSP 201712-2 游戏

#include<cstdio> #include<algorithm> using namespace std;const int M 1000;int k;bool obsl(int x){if(x%k0||x%10k){return true;//淘汰 }else return false; }int main(){int n;//孩子的个数 scanf("%d%d",&n,&k);int i1;//现在报的数 in…

在wpf中运行EXE文件

最简单的方法&#xff1a;System.Diagnostics.Process.Start("路径");网上的其他方法&#xff1a; Process p new System.Diagnostics.Process(); p.StartInfo.FileName "路径"; p.StartInfo.Arguments ""; …

C语言程序试题

一个无向连通图G点上的哈密尔顿&#xff08;Hamiltion&#xff09;回路是指从图G上的某个顶点出发&#xff0c;经过图上所有其他顶点一次且仅一次&#xff0c;最后回到该顶点的路劲。一种求解无向图上哈密尔顿回路算法的基础实现如下&#xff1a; 假设图G存在一个从顶点V0出发的…

利用OWC创建图表的完美解决方案

http://onlytiancai.cnblogs.com/archive/2005/08/24/221761.html 转载于:https://www.cnblogs.com/Athrun/archive/2008/05/19/1202909.html

(C++)1020 月饼 简单贪心

#include<cstdio> #include<algorithm> using namespace std;int types,weight;//月饼的种类数 struct Mooncake{double totalPrice;double price;double weight;double sell;//卖出了多少 };bool cmp(Mooncake a,Mooncake b){return a.price>b.price; }int ma…

枚举,给枚举赋值

/**************枚举*****************/// public enum Colors{// Red,Yellow,Blue,Black,White// }// public static void main(String[] args) {// Colors c Colors.Yellow;// System.out.println(c);//输出枚举// System.out.println(c.ordinal());//输出枚举对应的序号…

青岛...沙尘暴!太可怕了~什么事儿都有!

受蒙古国和我国内蒙古地区出现沙尘暴天气的影响&#xff0c;28日&#xff0c;山东省青岛、烟台等地出现大范围浮尘天气&#xff0c;空气质量明显下降。 28日&#xff0c;一场大范围的浮尘天气影响到烟台&#xff0c;天空一片浑浊&#xff0c;能见度不足5公里&#xff0c;空气质…

面试题收集最新

Java高级程序员面试题------https://www.cnblogs.com/mengdou/p/7233398.html Java高级工程师面试题总结及参考答案-----https://www.cnblogs.com/java1024/p/8594784.html Java高级程序员&#xff08;5年左右&#xff09;面试的题目集----https://blog.csdn.net/fangqun663775…

(C++)1023 组个最小数 简单贪心

#include<cstdio> //#include<algorithm> //using namespace std; //用hash思想读入数字 //解决最高位放谁 //解决后面的位数 //输出 int main(){int key[10];for(int i0;i<10;i){scanf("%d",&key[i]);}//解决最高位for(int i1;i<10;i){if(ke…

Nginx 在centos linux 安装、部署完整步骤并测试通过

需要先装pcre, zlib&#xff0c;前者为了重写rewrite&#xff0c;后者为了gzip压缩。 1.选定源码目录 选定目录 /usr/local/ cd /usr/local/ 2.安装PCRE库 cd /usr/local/ wget http://exim.mirror.fr/pcre/pcre-8.02.tar.gz tar -zxvf pcre-8.02.tar.gz cd pcre-8.02 ./config…

Ubuntu16.04安装qt

5.11官方下载网站&#xff1a; http://download.qt.io/official_releases/qt/5.11/5.11.1/ 可以直接下载linux系统下的.run安装包&#xff1a; 安装方式&#xff1a;https://www.jb51.net/LINUXjishu/501994.html 切换到.run所在的目录&#xff0c;然后 第一步&#xff1a; chm…

好男人是怎么变坏的

十岁以前&#xff0c;就不说了&#xff0c;无非是淘气和不懂事。 十三、四岁的时候&#xff0c;开始对女孩有好感&#xff0c;但是那时候他离女孩远远的&#xff0c;并且以讨厌女孩自居&#xff0c;生怕被同伴嘲笑。 十五岁的时候&#xff0c;听到大人们说某某男人好花&#xf…

(C++)小明种苹果(续)

#include<cstdio>struct tree{int left;//剩余的果子数量bool fallfalse;//是否发生掉落int falls0;//这颗数前面的树&#xff08;包括自身&#xff09;发生掉落的次数 }trs[1000];int main(){int n;//树的总数scanf("%d",&n);for(int i0;i<n;i){//对于…

MySQL如何判别InnoDB表是独立表空间还是共享表空间

InnoDB采用按表空间&#xff08;tablespace)的方式进行存储数据, 默认配置情况下会有一个初始大小为10MB&#xff0c; 名字为ibdata1的文件&#xff0c; 该文件就是默认的表空间文件&#xff08;tablespce file&#xff09;&#xff0c;用户可以通过参数innodb_data_file_path对…

如何使用WindowsLiveWriter发文章

1.下载wlw最新版本http://download.microsoft.com/download/8/0/9/809604cd-bd08-42c8-b590-49c332059e64/writer.msi 2.在菜单中选择“Weblog”&#xff0c;然后选择“Another Weblog Service”。如图一 &#xff08;图一&#xff09; 3.在Weblog Homepage URL中输入你的Blog主…

很多学ThinkPHP的新手会遇到的问题

在模板传递变量的时候&#xff0c;很多视频教程都使用$v.channel的方式&#xff0c;如下&#xff1a; <a href"{:U(Chat/set,array(id>$v.channel))}" title"设置" class"btn btn-mini tip"> 这会导致URL在解析的时候出现问题&#xff…

(C++)1040 有几个PAT

#include<cstdio> #include<cstring> const int MOD 1000000007; const int maxn 100010;int main(){char str[maxn];scanf("%s",str);int len strlen(str);//数出每个元素左侧的P的个数int leftnumP[maxn];leftnumP[0] 0;for(int i1;i<len;i){if…

C#进行Visio二次开发之电气线路停电分析逻辑

停电分析&#xff0c;顾名思义&#xff0c;是对图纸进行停电的逻辑分析。在电气化线路中&#xff0c;一条线路是从一个电源出来&#xff0c;连接着很多很多的设备的&#xff0c;进行停电分析&#xff0c;有两个重要的作用&#xff1a;一是看图纸上的Shape元件是否连接正常&…

红芯丑闻揭秘者 Touko 专访 | 关于红芯丑闻的更多内幕……

专栏 | 九章算法 网址 | www.jiuzhang.com ❤ 红芯事件 近日&#xff0c;一则《自主研发的国产浏览器内核&#xff0c;红芯宣布获2.5亿C轮融资》的讯息再次将“国产自主创新”这一话题推向高潮&#xff0c;希冀之声群起。然好景不长&#xff0c;网友Touko在将红芯浏览器的exe文…

数学图形(1.20)N叶草

有N个叶子的草 相关软件参见:数学图形可视化工具,使用自己定义语法的脚本代码生成数学图形.该软件免费开源.QQ交流群: 367752815 vertices 1000 t from 0 to (2*PI) r 10 n rand_int2(3, 10) p 1 cos(n*t) sin(n*t)^2 x p*cos(t) y p*sin(t) N叶草面_1 vertices D1:5…

(C++)1045 快速排序 非满分

#include<cstdio>const int maxn100010; //思路&#xff0c;从第一个元素开始&#xff0c;假设其是主元&#xff0c;然后用two pointers方法&#xff0c;看有没有进行交换&#xff0c;进行了则不是 int main(){int iszy[maxn]{0};//0表示可以是主元&#xff0c;1表示一定…

android笔记1——开发环境的搭建

Long Long ago...已经成为了历史&#xff0c;我还是要说出一个真相&#xff1a;早年前&#xff0c;那时候&#xff0c;android还不被大众所认知的时候&#xff0c;当然开发人员也没不像如今那样趋于饱和状态。一位大牛前辈&#xff0c;也是我的学长&#xff0c;那时候我还在上大…