当前位置:网站首页>[teacher Zhao Yuqiang] MySQL high availability architecture: MHA
[teacher Zhao Yuqiang] MySQL high availability architecture: MHA
2022-07-03 05:45:00 【Teacher zhaoyuqiang】

MHA(Master HA) It's an open source MySQL High availability program for , It's for MySQL The master-slave replication architecture provides automating master failover function .MHA It's monitoring master Node failure , It's going to improve the ones with the latest data slave Nodes become new master node , in the meantime ,MHA Consistency issues can be avoided by getting additional information from other nodes .MHA It also provides master Online switching function of nodes , Switch on demand master/slave node .
MHA It was by the Japanese yoshinorim( I used to work in DeNA Now I work in FaceBook) The development is relatively mature MySQL High availability solution .MHA In the 30 Fail over in seconds , And it can be used in the process of fail over , Ensure data consistency as much as possible . At present, Taobao is also developing similar products TMHA, At present, it supports one master and one subordinate .
One 、MHA The composition of
( One )MHA The role of
MHA There are two roles of service , MHA Manager( The management node ) and MHA Node( Data nodes ):
- MHA Manager: Usually deployed separately on a single machine to manage multiple master/slave colony ( Group ), Every master/slave A cluster is called a application, It is used to manage and coordinate the whole cluster .
- MHA Node: Run on each MySQL Server (master/slave/manager), It has parsing and cleaning through monitoring logs Feature scripts to speed failover . It is mainly the agent that receives instructions from the management node , Agents need to run on every mysql Node . In short node It is used to collect the generated data from the node server bin-log. Compare whether the slave node that intends to be promoted to the new master node owns and completes the operation , If it is not sent to the new master node, it will be promoted to the master node after local application .
( Two )MHA Tools provided
MHA There are many tools available , The common ones are as follows :
- Manager node

- Node node ( These tools are usually made of MHA Manager The script triggers , There is no need for human operation )

Two 、MHA How it works

- From the crash of master Save binary log events (binlog events);
- Identify those with the latest updates slave ;
- Apply differential relay logs (relay log) To other slave ;
- Application from master Saved binary log events (binlog events);
- Upgrade one slave As new master ;
- Use other slave Connect new master replicate .
3、 ... and 、 Deploy MHA
( One ) Prepare the experimental environment
- Three hosts :mysql111、mysql112、mysql113
- operating system :CentOS
- Configure host name (/etc/hosts)
- Configure password free login
- Each host is installed with MySQL
( Two ) Build master-slave environment
- Each station MySQL Turn on binlog, Set up server-id
vi /etc/my.cnf
log-bin=mysql-binlog
server-id=1 ( Be careful : Each station MySQL Set up different server-id)
show variables like '%log_bin%';
- On all machines , Create a master-slave copy account
create user 'repl'@'192.168.79.%' identified by 'Welcome_1';
grant replication slave on *.* to 'repl'@'192.168.79.%';
flush privileges;
- On all machines , Create an administrative account
create user 'myadmin'@'192.168.79.%' identified by 'Welcome_1';
grant all privileges on *.* to 'myadmin'@'192.168.79.%';
flush privileges;
- On the master and slave Libraries , Enable GTID
set @@GLOBAL.ENFORCE_GTID_CONSISTENCY = ON;
set @@GLOBAL.GTID_MODE = OFF_PERMISSIVE;
set @@GLOBAL.GTID_MODE = ON_PERMISSIVE;
set @@GLOBAL.GTID_MODE = ON;
Parameter description :
GTID yes MySQL 5.6 New features , Its full name is Global Transaction Identifier, Can be simplified MySQL Master slave switching and Failover.GTID Used in binlog Uniquely identifies a transaction in . When the transaction commits ,MySQL Server Writing binlog When , Will write a special Binlog Event, The type is GTID_Event, Specifies the next transaction GTID, And then write the transaction Binlog. Master slave synchronization GTID_Event And business Binlog Will be passed to the slave Library , The same is used in the execution of the slave library GTID Write binlog, After the master-slave synchronization , Can be through GTID Confirm the location of synchronization from the library to . in other words , Whether it's cascading , It's still one master and many subordinates , Both can pass GTID Find something automatically , You don't have to go through it like before File_name and File_position I have some .
- Configure the master-slave copy command on the slave database and turn on the master-slave synchronization
change master to master_host='mysql111',master_user='repl',\
master_password='Welcome_1',master_auto_position=1;
start slave;
- Check the status of master-slave replication on the slave library
show slave status\G;

( 3、 ... and ) install MHA
- All nodes are installed node Software dependency packages and node Software
yum -y install perl-DBD-MySQL
rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch.rpm
- stay mysql111 Install on manager Software dependency packages
yum install -y perl-Config-Tiny
yum install -y epel-release
yum install -y perl-Log-Dispatch
yum install -y perl-Parallel-ForkManager
yum install -y perl-Time-HiRes
- stay mysql111 Install on manager Software
rpm -ivh mha4mysql-manager-0.58-0.el7.centos.noarch.rpm
( Four ) establish Manager Configuration file for
# Create a directory of configuration files 、 Log directory
mkdir -p /etc/mha
mkdir -p /var/log/mha/log
# edit mha The configuration file vi /etc/mha/mha.cnf
[server default]
manager_log=/var/log/mha/log/manager
manager_workdir=/var/log/mha/log
master_binlog_dir=/var/lib/mysql
user=myadmin
password=Welcome_1
ping_interval=2
repl_user=repl
repl_password=Welcome_1
ssh_user=root
[server1]
hostname=mysql111
port=3306
[server2]
hostname=mysql112
port=3306
[server3]
hostname=mysql113
port=3306
( 5、 ... and ) Check status , And open MHA
- Check mutual trust
masterha_check_ssh --conf=/etc/mha/mha.cnf

- Check master-slave replication status
masterha_check_repl --conf=/etc/mha/mha.cnf

- Turn on MHA-manager
nohup masterha_manager --conf=/etc/mha/mha.cnf > /var/log/mha/log/manager.log < /dev/null 2>&1 &
- see MHA state
masterha_check_status --conf=/etc/mha/mha.cnf

- test HA Highly available automatic switching
stay mysql111 On , perform shutdown operation
mysqladmin -uroot -pWelcome_1 shutdown
MHA It will automatically switch between master and slave . After switching ,MHA The process will automatically stop running .
stay mysql112 and mysql113 Upper observation , Execute the following statement :
show slave status\G;

边栏推荐
- Final review (day3)
- 期末复习(DAY7)
- Gan network thought
- Primary school campus IP network broadcasting - Design of primary school IP digital broadcasting system based on campus LAN
- 2022.DAY592
- 2022.6.30DAY591
- 为什么网站打开速度慢?
- 一起上水碩系列】Day 9
- SimpleITK学习笔记
- Explanation of several points needing attention in final (tested by the author)
猜你喜欢

Win10 install pytullet and test

Deploy crawl detection network using tensorrt (I)

Why should we rewrite hashcode when we rewrite the equals method?

"C and pointer" - Chapter 13 advanced pointer int * (* (* (*f) () [6]) ()

Disassembly and installation of Lenovo r7000 graphics card

How to use source insight

Altaro virtual machine replication failed: "unsupported file type vmgs"
![[advanced pointer (2)] | [function pointer, function pointer array, callback function] key analysis + code explanation](/img/9b/a309607c037b0a18ff6b234a866f9f.jpg)
[advanced pointer (2)] | [function pointer, function pointer array, callback function] key analysis + code explanation

SimpleITK学习笔记

Apache+PHP+MySQL环境搭建超详细!!!
随机推荐
Redis encountered noauth authentication required
Complete set of C language file operation functions (super detailed)
ROS Compilation Principle
獲取並監控遠程服務器日志
Installing altaro VM backup
Qt读写Excel--QXlsx插入图表5
Final review (Day2)
6.23 warehouse operation on Thursday
Apache+php+mysql environment construction is super detailed!!!
How to set up altaro offsite server for replication
Deep embedding and alignment of Google | protein sequences
MySQL startup error: several solutions to the server quit without updating PID file
Skip table: principle introduction, advantages and disadvantages of skiplist
Exception when introducing redistemplate: noclassdeffounderror: com/fasterxml/jackson/core/jsonprocessingexception
kubernetes资源对象介绍及常用命令(五)-(ConfigMap)
Troubleshooting of 32GB Jetson Orin SOM failure to brush
2022.7.2day594
Beaucoup de CTO ont été tués aujourd'hui parce qu'il n'a pas fait d'affaires
Shanghai daoning, together with American /n software, will provide you with more powerful Internet enterprise communication and security component services
Apt update and apt upgrade commands - what is the difference?
