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

news/2024/7/1 3:02:39

高可用架构一

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...


http://lihuaxi.xjx100.cn/news/236412.html

相关文章

[干货]Kaggle热门 | 用一个框架解决所有机器学习难题

新智元推荐 来源&#xff1a;LinkedIn 作者&#xff1a;Abhishek Thakur 译者&#xff1a;弗格森 【新智元导读】本文是数据科学家Abhishek Thakur发表的Kaggle热门文章。作者总结了自己参加100多场机器学习竞赛的经验&#xff0c;主要从模型框架方面阐述了机器学习过程中可能会…

java去掉mongodb日志_如何禁用mongoDB java驱动程序日志记录?

我试图禁用mongo-java-driver-3.0.0的日志输出.我试图在我的应用程序开始之前设置它们,然后加载mongo驱动程序,但它没有帮助.// Enable MongoDB logging in generalSystem.setProperty("DEBUG.MONGO", "false");// Enable DB operation tracingSystem.setP…

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;小…

html 复选框 mysql_Html:实现带复选框的下拉框(一)

概述项目中要用到可多选的下拉框(select)&#xff0c;发现HTML中无此控件&#xff0c;故手动模拟实现一下。模拟所用元素&#xff1a;input&#xff0c;ul&#xff0c;li代码模拟实现带复选框的下拉列表body{margin: 20px;}input{width: 150px;height: 30px;}ul{display: none;…

深入理解 python 元类

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

java map prefix_从键以特定表达式开头的Map中获取所有值的最快方法

小编典典如果您使用NavigableMap(例如TreeMap)&#xff0c;则可以利用基础树数据结构的好处&#xff0c;并执行以下操作(非常O(lg(N))复杂)&#xff1a;public SortedMap getByPrefix(NavigableMap myMap,String prefix ) {return myMap.subMap( prefix, prefix Character.MAX…

OSError: Could not find library geos_c or load any of its variants ['libgeos_c.so.1', 'libgeos_c.so

OSError: Could not find library geos_c or load any of its variants [libgeos_c.so.1, libgeos_c.so 解决&#xff1a; sudo vim /etc/ld.so.conf 添加&#xff1a;/opt/source/geos-3.5.0/build/lib sudo ldconfig

C语言程序试题

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