MHA profile:
MHA (Master High Availability) currently in terms of high availability MySQL is a relatively mature solution that youshimaton by the Japanese company DeNA (Facebook now working in the company) to develop, is a good case as a failure MySQL high availability environment and the main switch from an elevated high availability software. In MySQL failover process, the MHA can be done automatically in 30 seconds from 0 to the fault switching operation of the database, and performing the handover procedure failure, the MHA to ensure consistency of the data to the maximum extent, in order to achieve real availability of meaning.
MHA also offers online master library function switch can be switched safely to the main library currently running a new main library (library by lifting from the main library), it can be completed within about 0.5-2 seconds.
MHA works:
Simply draw a bit
Preparing the Environment
centos7 version of the above
cat /etc/redhat-release
Kernel above 3.10
uname -r
Machine name | IP configuration | Server Role | Remark |
---|---|---|---|
Manager | 10.0.0.41 | Manager | For the monitoring and management |
Master | 10.0.0.42 | Primary database server | Open bin-log relay-log close relay_log_purge |
Slave1 | 10.0.0.43 | From the database server | Open bin-log relay-log close relay_log_purge |
Slave2 | 10.0.0.44 | From the database server | Open bin-log relay-log close relay_log_purge |
In order to set free secret login convenience, within etc / hosts file on each node in the configuration of add about content:
10.0.0.41 node1.keer.com node1
10.0.0.42 node1.keer.com node2
10.0.0.43 node1.keer.com node3
10.0.0.44 node1.keer.com node4
As FIG.
From a multi-master configuration
A multi-master from what I can learn, you can do your own configuration from a multi-master and very detailed
- Configuring ssh-free dense Login
ssh-keygen -t rsa
After executing the commands you need to enter a carriage return himself three times
ll -a
cd .ssh
ssh-copy-id [email protected]
ssh-copy-id [email protected]
ssh-copy-id [email protected]
- On Manager server
- On the Master Server
- Slave1 on the server
- On Slave2 server
The above operation begins configure ssh login-free dense, each node needs to perform again, in addition to IP needs a change.
- MHA installation package
Manager requires two packages below
Three other nodes only need to install a packet as in FIG.
Required packages can go to my Web site to download: the installation package of MHA
MHA and three other nodes require installation package
- Set MHA Management ProfilesMHANode operation
mkdir /etc/mha_master
vim /etc/mha_master/mha.cnf
Configuration files are as follows
[server default]
user=mhaadmi #Master设置的管理用户
password=123456 #Master设置的管理用户的密码
manager_workdir=/etc/mha_master/app1
manager_log=/etc/mha_master/manager.log
remote_workdir=/mydata/mha_master/app1
ssh_user=root #ssh的免密认证
repl_user=root #数据库授权的用户
repl_password=123456 #数据库授权的的密码
ping_interval=1
[server1]
hostname=10.0.0.42 #Master的ip
ssh_port=22
candidate_master=1
[server2]
hostname=10.0.0.43 #Slave1的ip
ssh_port=22
candidate_master=1
[server3]
hostname=10.0.0.44 #Slave2的ip
ssh_port=22
candidate_master=1
- Ssh trust communication between nodes detected configuration is okOperation on MHA
masterha_check_ssh -conf=/etc/mha_master/mha.cnf
- Connection configuration parameters MySQL replication cluster management to check whether the OK to execute on the Master node
grant all on *.* to 'mhaadmi'@'10.0.%.%' identified by '123456';
flush privileges;
masterha_check_repl -conf=/etc/mha_master/mha.cnf
Below the last row of executing the display MySQL Replication Health is OK. To
- Start MHA
executed on MHA node
nohup masterha_manager -conf=/etc/mha_master/mha.cnf &> /etc/mha_master/manager.log &
FIG been executed as follows
- Look at the state after the start
masterha_check_status -conf=/etc/mha_master/mha.cnf
FIG been executed as follows
- MHA test failover
in the Master node closed Mariadb service, analog Master node goes down
systemctl stop mariadb
Check node status in Manager
masterha_check_status -conf=/etc/mha_master/mha.cnf
FIG been executed as follows
- View Slave2 master-slave synchronization
Now Slave2 show the Lord's IP is an IP Slave1 then show success