MHA of MySQL Cluster High Availability Architecture

Foreword introduction
I remember I posted an article before, called "Analysis of MySQL High Availability Architecture", after that, many friends have been asking me in the background of the official account or other channels when there are related in-depth configuration management articles. Therefore, Brother migrant workers, we will also sort out the various structures in front of them one by one, and then publish them. Then the overall planning and configuration operation of the MHA that will be released today and in the future.

 

Architecture Introduction
MHA (Master High Availability) is currently a relatively mature solution in MySQL high availability, as a high availability software for failover and master-slave promotion in MySQL high availability environment. In the process of MySQL failover, MHA can automatically complete the failover operation of the database within 0~30 seconds, and in the process of failover, MHA can ensure the consistency of data to the greatest extent, in order to achieve true High availability in a sense.

 

The software consists of two parts: MHA Manager (management node) and MHA Node (data node). MHA Manager can be deployed on an independent machine to manage multiple master-slave clusters, or it can be deployed on a slave node. MHA Node runs on each MySQL server, MHA Manager will periodically detect the master node in the cluster, when the master fails, it can automatically promote the latest data slave to the new master, and then re-point all other slaves to the new master the master. The entire failover process is completely transparent to the application.

 

At present, MHA mainly supports the architecture of one master and multiple slaves. To build MHA, there must be at least three database servers in a replication cluster, one master and two slaves, that is, one acts as the master, one acts as the standby master, and the other acts as the slave database. , since at least three servers are required

 

**Installation and deployment planning**

 

system message

 

[root@db250 ~]# cat /etc/redhat-release

 

CentOS release 6.8 (Final)

 

[root@db250 ~]# uname -r

 

2.6.32-642.el6.x86_64

 

Database version

 

mysql-5.7.17

 

environmental planning

 

Db250 cluster management node 192.168.4.250

 

Db251 main library 192.168.4.251

 

Db253 slave library (standby master library) 192.168.4.253

 

Db254 from library 192.168.4.254

 

The architecture diagram is as follows
35b7fc126ad94053b6618520aa45abc7.jpg

 

Install and configure SSH password-free login and HOSTS fileConfigure
hosts file

 

cat>>/etc/hosts<

 

192.168.4.250 db250

 

192.168.4.251 db251

 

192.168.4.253 db253

 

192.168.4.254 db254

 

EOF

 

Check after configuration is complete

 

[root@db254 ~]# tail -4 /etc/hosts

 

192.168.4.250 db250

 

192.168.4.251 db251

 

192.168.4.253 db253

 

192.168.4.254 db254

 

Configure SSH keyless login

 

ssh-keygen -t rsa
f6e7f187cc144368bc4c1605623f9223.jpg
ssh-copy-id 192.168.4.251

 

ssh-copy-id 192.168.4.253

 

ssh-copy-id 192.168.4.254

 

—— The above two steps to configure all servers need to be configured

 

Install MYSQL and configure master-slave synchronization to
install mysql database service

 

rpm -ivh mysql57-community-release-el6-9.noarch.rpm

 

yum install mysql-community-server -y

 

/etc/init.d/mysqld start

 

The default password is

 

[root@db254 ~]# grep ‘temporary password’ /var/log/mysqld.log

 

2017-08-30T08:08:05.956867Z 1 [Note] A temporary password is generated for root@localhost: f;2YK51qXlo/

 

Modify the default password, for the convenience of later operation

 

mysql> alter user ‘root’@‘localhost’ identified by ‘123456’;

 

——- All three database servers need to be configured for the above configuration

 

Configure master-slave synchronization

 

Both Db251 and db253 configuration files need to be configured to enable binlog

 

server_id=251

 

log_bin=master-bin

 

log_bin_index=master-bin.index

 

server_id=253

 

log_bin=slave-bin

 

log_bin_index=slave-bin.index

 

log-slave-updates

 

relay_log_index=slave-relay-bin.index

 

relay_log=slave-relay-bin

 

server_id=254

 

relay_log_index=slave-relay-bin.index

 

relay_log=slave-relay-bin

 

Synchronize the master database data to the slave database, please refer to the previous article for master-slave synchronization operation

 

Linux system MySQL database master-slave synchronization actual combat process

 

Check master-slave synchronization status

 

mysql -uroot -p123456 -e “show slave status\G”|egrep “Slave_IO_Running|Slave_SQL_Running”
8f3c0a5ae7fc4dc7978c592625c81a5d-7.jpg

 

Install and configure MHA management and node nodes

 

Install dependencies

 

yum install perl-DBD-MySQL perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes –y

 

Manage Node Installation

 

rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

 

yum localinstall -y mha4mysql-manager-0.52-0.noarch.rpm

 

yum localinstall -y mha4mysql-node-0.52-0.noarch.rpm

 

Installation of other nodes

 

yum localinstall -y mha4mysql-node-0.52-0.noarch.rpm

 

Errors may be reported during the installation process, follow the prompts to solve

 

The configuration process is as follows:

 

[root@db250 ~]# mkdir /mha

 

[root@db250 ~]# vim /etc/masterha_default.cnf

 

[server default]

 

#The mysql management username just authorized

 

user=mha

 

password=123456

 

manager_workdir=/mha

 

manager_log=/mha/manager.log

 

remote_workdir=/mha

 

#ssh Account name for keyless login

 

ssh_user=root

 

#mysql replication account, used to synchronize binary logs between master and slave machines, etc.

 

repl_user=slave

 

repl_password=123456

 

#ping interval, used to detect whether the master is normal

 

ping_interval= 1

 

[server1]

 

hostname=db251

 

master_binlog_dir=/var/lib/mysql

 

#When the candidate master hangs up, let it be the top priority

 

candidate_master=1

 

[server2]

 

hostname=db253

 

master_binlog_dir=/var/lib/mysql/

 

candidate_master=1

 

[server3]

 

hostname=db254

 

master_binlog_dir=/var/lib/mysql/

 

no_master=1

 

#Cannot become master
4cfd01474ee3455dba24c2d05107d320-configfile.jpg

 

——The relevant detection commands are as follows————

 

masterha_check_ssh Check the SSH configuration status of MHA

 

masterha_check_repl checks MySQL replication status

 

masterha_manger starts MHA

 

masterha_check_status checks the current MHA running status

 

masterha_master_monitor detects whether the master is down

 

masterha_master_switch controls failover (automatic or manual)

 

masterha_conf_host Add or delete configured server information

 

Detect SSH password-free login
75b464e7918748a187b0baa3191bc098-sshcheck.jpg
detection synchronization
38ad0ae92fbe425385ee7fcd42cd053a-checkrep01.jpg
ec35747b8df04399a1db225adcd24cd6-checkrep02.jpg

 

Start the MHA service and observe the log information
[root@db250 ~]# masterha_manager –conf=/etc/masterha_default.cnf &

 

[1] 2035Fri Sep 1 01:52:25 2017 - [info] Reading default configuratoins from /etc/masterha_default.cnf..

 

Fri Sep 1 01:52:25 2017 - [info] Reading application default configurations from /etc/masterha_default.cnf..

 

Fri Sep 1 01:52:25 2017 - [info] Reading server configurations from /etc/masterha_default.cnf..
6e8f9b268670455a9b9c0c8149bf68b2-log01.jpg
d5373997b68d4478bf094a702ecd2a86-log02.jpg

 

Test automatic failover
Next simulate the failure and turn off db251

 

[root@db251 ~]# /etc/init.d/mysqld stop

 

Stopping mysqld: [OK]

 

Check the log
72742638617d467bab6626cffe937344-downlog01.jpg
a68f8bad6b1047658b7eee02bfd8efa3-downlog02.jpg
7374122cf610442ca941fcb2022833b4-downlog03.jpg
13750980e04d42db97fffd6bfa395847-downlog04.jpg
8d86ac0e22e348d99ba189cb72085c01-downlog05.jpg
and find that the new master library has been switched to the db253 server. Next, check the master-slave synchronization.
a75e6260725143dcb8d5959c6af414ab-newmaster.jpg

 

When the original master server is faulty and repaired, you need to manually change the original master to the slave

 

[root@db250 ~]# grep -i"All other slaves should start" /mha/manager.log

 

Fri Sep 1 01:59:05 2017 - [info] All other replicas should start replication from here. Statement should be: CHANGE MASTER TO MASTER_HOST='db253 or192.168.4.253', MASTER_PORT=3306,MASTER_LOG_FILE='slave-bin. 000003', MASTER_LOG_POS=760546, MASTER_USER='slave', MASTER_PASSWORD='xxx';
c3a7c232a38d47eaafb4c81e3cf3c8e7-masterslave.jpg
Check the log
adf3066096ab4d4b9ca0280f3fe3dd17-oldmasterstart01.jpg
9da93d72a36d4f688bc421de59098d09-oldmasterstart02.jpg
and find that the original master library has become a new slave library after being repaired and online, and then synchronize with DB253 to
08b85892756b4e1e8e5b6e921bff8398-test01.jpg
2ab74794a8ed4a1e8fa873b591f82729-test02.jpg
d8e36167990f4213be5ed568b8042a6b-test03.jpg
find that the data is normal and can be synchronized

 

From the technical public account: Migrant workers Linux operation and maintenance

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326207317&siteId=291194637