当前位置:网站首页>MHA high availability cluster deployment and failover of database
MHA high availability cluster deployment and failover of database
2022-07-01 12:39:00 【51CTO】
There are some problems in the traditional master-slave architecture in the previous article ( for example : Single point of failure, etc ), New content will be added to this blog to solve these problems .
One 、MHA Concept
MHA(MasterHigh Availability) It's an excellent set of MySQL Software for failover and master-slave replication in high availability environment .
MHA The emergence of is to solve MySQL Single point problem .
MySQL During failover ,MHA Can do 0-30 Automatic failover within seconds .
MHA It can ensure the consistency of data to the greatest extent in the process of failover , To achieve real high availability .
1、MHA The composition of
MHA Node( Data nodes )
MHA Node Run on each MySQL Server .
MHA Manager( The management node )
MHA Manager It can be deployed separately on a separate machine , Manage multiple master-slave colony ; It can also be deployed in one slave Node .
MHA Manager It will detect the master node . When master Failure time , It can automatically send the latest data to slave Upgrade to a new master, And then put all the other slave Point back to the new master. The entire failover process is completely transparent to the application .
2、MHA Characteristics
During automatic failover ,MHA Trying to save binary logs from the down primary server , Ensure that data is not lost to the greatest extent
Use semi synchronous replication , Can greatly reduce the risk of data loss , If only one slave Has received the latest binary log ,MHA You can apply the latest binary logs to all other slave Server , Therefore, the data consistency of all nodes can be guaranteed
at present MHA Support one master multi-slave architecture , At least three servers , That is, one master and two slaves
Two 、 build MySQL+MHA

Experimental thinking
1、MHA framework
Database installation
One master and two slaves
MHA build
2、 fault simulation
Simulate the failure of the main library
The alternate master database becomes the master database
The original fault main database is restored and rejoined to MHA Become a slave
Experiment preparation
MHAmanager 192.168.74.75
mysql1 192.168.74.76
mysql2 192.168.74.71
mysql3 192.168.74.73
Now three mysql Installed on the host mysql, You can see the script I wrote earlier
Turn off firewalls and security
1、 modify mysql The hostname of the node
192.168.74.76
192.168.74.71

2、 Modify three MySQL The main profile of the server /etc/my.cnf, And create a command soft link
192.168.74.76


192.168.74.71
192.168.74.73


3、 To configure MySQL One master and two slaves
(1) all MySQL Server run MySQL to grant authorization


(2) stay Master Node to view binaries and synchronization points
192.168.74.76
show master status;
# Everyone's binary file name or offset may be different , Remember your

(3) stay Slave1、Slave2 The node performs a synchronization operation

(4)Slave1、Slave2 The node is set to read-only mode

(5) Master slave replication verification

4、 install MHA Software
MHAmanager(192.168.74.75)
mysql1(192.168.74.76)
mysql2(192.168.74.71)
mysql3(192.168.74.73)
First installation epel Source , Online source installation is required
Then install... On all servers node Components

2) install MHA node software package
MHAmanager(192.168.74.75)
mysql1(192.168.74.76)
mysql2(192.168.74.71)
mysql3(192.168.74.73)
For each operating system, the version is different , here CentOS7.4 Must choose 0.57 edition .
On all servers, you must first install node Components , Last in MHA-manager Install on node manager Components , because manager rely on node Components



(3) stay MHA manager Install on node manager Components
192.168.74.75

manager After the components are installed, install them in /usr/local/bin The following tools will be generated 
It mainly includes the following :
node Components will also be installed in /usr/local/bin Several scripts will be generated below ( These tools are usually made of MHAManager The script triggers , There is no need for human operation )
Mainly as follows :
5、 Configure password less authentication on all servers
(1) stay manager Configure password less authentication to all database nodes on the node
192.168.74.75


(2) stay mysql1 Configuration to the database node mysql2 and mysql3 No password authentication ssh-keygen -t rsa
mysql1(192.168.74.76)
(3) stay mysql2 Configuration to the database node mysql1 and mysql3 No password authentication
mysql1(192.168.74.71)
(4) stay mysql3 Configuration to the database node mysql1 and mysql2 No password authentication
mysql1(192.168.74.73)
6、 stay manager Configuration on node MHA
MHAmanager(192.168.74.75)
(1) stay manager Copy related scripts on node to /usr/local/bin Catalog


(2) When copying the above automatic switching VIP Manage scripts to /usr/local/bin Catalog , Use here master_ip_failover Scripts to manage VIP And failover


(3) establish MHA Software directory and copy configuration files , Use here app1.cnf Configuration files to manage mysql Node server


7、 The first configuration needs to be in Master Manually turn on the virtual server on the node IP
Master(192.168.74.76)

8、 stay manager Testing on nodes ssh No password authentication
MHAmanager(192.168.74.75)

9、 stay manager Testing on nodes mysql Master-slave connection


10、 stay manager Start on the node MHA
MHAmanager(192.168.74.75)

11、 Check the status
MHAmanager(192.168.74.76)
see MHA state , You can see the current master yes Mysql1 node .

MHAmanager(192.168.74.76)
see MHA journal , Also to see the current master yes 192.168.76.76

mysql1(192.168.74.76)
see Mysql1 Of VIP Address , see Mysql1 Of VIP Address 192.168.74.200 Whether there is , This VIP The address is not because manager Nodes stop MHA Service and disappear .

Add : To shut down manager service , You can use the following command .
3、 ... and 、 fault simulation
1、 fault simulation
(1) stay manager Monitoring observation logging on the node
MHAmanager(192.168.74.75)

(2) stay Master node Mysql1 Stop on mysql service
mysql1(192.168.74.76)

(3) see mysql2 Take over VIP
mysql2(192.168.74.71)


2、 Troubleshooting steps
(1) Repair mysql

(2) Fix the master-slave
In the current main database server Mysql2 View binaries and synchronization points
mysql2(192.168.74.71)

In the original master database server mysql1 Perform synchronous operation
mysql1(192.168.74.76)

(3) stay manager Modify the configuration file on the node app1.cnf
MHAmanager(192.168.74.75)
Add this record to it , Because it will automatically disappear when it fails to detect

(4) stay manager Start on the node MHA
MHAmanager(192.168.74.75)

To sum up , You must see clearly when authorizing , If it weren't for you ip, If it weren't for the domain name , If it is a domain name, you must do domain name resolution .
边栏推荐
- Wechat simulated geographical location_ Camouflage wechat location
- What are the solutions for session sharing of highly paid programmers & interview questions series 118?
- 6.30 simulation summary
- STM32 project practice (1) introduction and use of photosensitive resistor
- leetcode:329. 矩阵中的最长递增路径【dfs + cache + 无需回溯 + 优雅】
- 工具箱之 IKVM.NET 项目新进展
- 下半年还有很多事要做
- 高薪程序员&面试题精讲系列118之Session共享有哪些方案?
- Queue operation---
- Ansi/ul 94 VTM vertical burning test for thin materials
猜你喜欢

leetcode:329. 矩阵中的最长递增路径【dfs + cache + 无需回溯 + 优雅】

项目部署,一点也不难!

redis探索之缓存一致性

Share several tools for designing exquisite circuit diagrams
![[datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE](/img/8f/64fea641730795a2b5252cc2c8cdd2.png)
[datawhale202206] pytorch recommendation system: multi task learning esmm & MMOE

被锡膏坑了一把

BIM and safety in road maintenance-buildSmart Spain

I wish you all a happy reunion
![[speech signal processing] 3 speech signal visualization -- prosody](/img/06/5f57f9dfe3a0f2f70022706f7d4d17.jpg)
[speech signal processing] 3 speech signal visualization -- prosody

基于.NetCore开发博客项目 StarBlog - (13) 加入友情链接功能
随机推荐
6.30 simulation summary
腾讯黎巍:深耕“监管科技”,护航数字经济行稳致远
Common chart usage of Bi tools
2022-06-28-06-29
买卖其实也有风险
R语言使用yardstick包的conf_mat函数计算多分类(Multiclass)模型在每个交叉验证(或者重采样)的每一折fold上的混淆矩阵、并使用summary输出每个fold的其它详细指标
基因检测,如何帮助患者对抗疾病?
[JS] interview questions
leetcode:329. 矩阵中的最长递增路径【dfs + cache + 无需回溯 + 优雅】
【MAUI】为 Label、Image 等控件添加点击事件
Use Net core access wechat official account development
[speech signal processing] 3 speech signal visualization -- prosody
Four years after graduation: work, resign, get married, buy a house
VS Code 设置代码自动保存
关于NAND FLASH解扣的认识
网络socket的状态要怎么统计?
Digital signal processing -- Design of linear phase (Ⅱ, Ⅳ) FIR filter (2)
Application of stack -- bracket matching problem
2022-06-28-06-29
Wechat applet - 80 practical examples of wechat applet projects