MySQL MHA high availability architecture

The principle and function of 0, MHA's

       1), monitoring node (all nodes obtain information via the configuration file)

                  System, network

                   From the master state

        2) election of the main policies

                1) If it is determined from the library (position or gtid), there is difference data, the closest to the slave master, become the main alternatives;

                2) If it is determined from the library (position or gtid) data match the installation profile configuration server sequentially selected (default)

                3) If the right to set the weight (candidate_master = 1), according to their weights enforce the alternate master

                      1), by default, if a slave relay logs behind the master 100M of it, even if it will not have the right to re-elect it;

                      2) If check_repl_delay = 0, even if the log far behind, which is also forced to select an alternative primary

       3) Data compensation strategies

              1) When the ssh connectable, on the primary database gtid or position number, the binary log holding immediately from the library and applied to each slave node (save_binary_logs);

              2) When the connection can not ssh, from the comparison between the difference relaylog library (apply_diff_relay_logs)

      4) Failover 

           The main alternative identity switch, to provide services outside the remainder confirm the new master-slave relationship from the library and new main library

     5) transparent to the application (VIP)

     

     6) notification mechanism (send_report)

 

     7) the second compensation data (binlog_server)

    8) healing (to be developed in .......)

 

 

 

 

               

1, 2 the MHA from the main environment, from the environment to ensure that the main normal

Download mha-node and mha-manage

Download: https://github.com/yoshinorim/mha4mysql-node/releases

2, the configuration from the master trust between ssh

ssh-keygen -t rsa -P  ' '  

ssh-copy-id 

Interoperable nodes in three mutual authentication and

3, create a soft link

ln -s /app/mysql/bin/mysqlbinlog  /usr/bin/mysqlbinlog

ln -s /app/mysql/bin/mysql  /usr/bin/mysql

4, the software installation node (three nodes are installed)

yum install perl-DBD-MySQL -y
yum localinstall mha4mysql-node-0.58-0.el7.centos.noarch.rpm 

 

5, select one of the servers as the server manager software and install the following

yum install -y perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManger perl-Time-HiRes

Compiler need to install the following libraries (yum install perl-CPAN * -y) installation

yum localinstall mha4mysql-manager-0.58-0.el7.centos.noarch.rpm  -y

 

6, MHA create user-specific monitoring and management (creation can be directly in the main library)

grant all privileges on *.* to 'mha'@'192.168.1.%' identified by '123';

flush privileges;

7, viewed on three different nodes mha whether the user is successful

select user,host from mysql.user;

8, the configuration manager node configuration file manager

Create a configuration directory

mkdir  -p /etc/mha

Create a log directory

mkdir -p / var / log / MHA

Edit the configuration file mha

[server default]
manager_log=/var/log/mha/app1/manager
manager_workdir=/var/log/mha/app1
master_binlog_dir=/data/mysql/binlog
user=mha
password=mha
ping_interval=2
repl_password=123.com
repl_user=repl
ssh_user=root
[server1]
hostname=192.168.1.130
port=3306
[server2]
hostname=192.168.1.141
port=3306
[server3]
hostname=192.168.1.145
port=3306
 

9, using the built-in command mha tool to verify ssh trust (all ok, shows normal environment)

master_check_ssh --conf=/etc/mha/app1.conf

10, verify that the master copy from

master_check_repl --conf=/etc/mha/app1.conf

11, start manager

nohup masterha_manager --conf = / etc / mha / app1.cnf --remove_dead_master_conf --ignore_last_failover </ dev / null> /var/log/mha/app1/manager.log 2> & 1 &
verify the success of start  

masterha_check_status --conf=/etc/mha/app1.cnf 
 

 


 

 

Guess you like

Origin blog.csdn.net/pang_2899/article/details/93464656