MHA:Master High Availability
實現(xiàn)功能為對主節(jié)點進行監(jiān)控恐仑,可實現(xiàn)自動故障轉移至其他從節(jié)點;通過提升某一從節(jié)點稱為新的主節(jié)點竞膳,基于主從復制蹄殃,需要客戶端配合實現(xiàn),目前MHA主要支持一主多從架構
MHA管理端安裝
[root@localhost ~]# yum install mha4mysql-manager-0.58-0.el7.centos.noarch.rpm mha4mysql-node-0.58-0.el7.centos.noarch.rpm
[root@localhost ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:bFw1TVu4gjKkzqSD/W9xRRM8uUvrPkxeTTTyde12/dk root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| .+=..o|
| . .*oo+=|
| o .o +++=|
| ooo.. = ..*|
| o = So o + +=|
| . + o.. . + ..E|
| o o = . |
| . . = |
| o. ... |
+----[SHA256]-----+
[root@localhost ~]# ssh-copy-id 192.168.103.71
[root@localhost ~]# rsync -av .ssh 192.168.103.72:/root/
[root@localhost ~]# rsync -av .ssh 192.168.103.73:/root/
[root@localhost ~]# rsync -av .ssh 192.168.103.74:/root/
manage管理端
[root@localhost ~]# mkdir /etc/mastermha/
[root@localhost ~]# mkdir /data/mastermha/app1/ -pv
mkdir: created directory ‘/data/mastermha’
mkdir: created directory ‘/data/mastermha/app1/’
[root@localhost ~]# vim /etc/mastermha/app1.cnf
[server default]
user=mhauser
password=ptg123
manager_workdir=/data/mastermha/app1/
manager_log=/data/mastermha/app1/manager.log
remote_workdir=/data/mastermha/app1/
ssh_user=root
repl_user=repluser
repl_password=ptg123
ping_interval=1
[server1]
hostname=192.168.103.72
candidate_master=1
[server2]
hostname=192.168.103.73
candidate_master=1
[server3]
hostname=192.168.103.74
MASTER主節(jié)點
[mysqld]
log-bin
server_id=1
skip_name_resolve=1
mysql> show master logs
-> ;
+--------------------+-----------+
| Log_name | File_size |
+--------------------+-----------+
| mariadb-bin.000001 | 245 |
+--------------------+-----------+
1 row in set (0.00 sec)
mysql> grant replication slave on *.* to repluser@'192.168.103.%' identified by 'ptg123';
Query OK, 0 rows affected (0.00 sec)
mysql > grant all on *.* to mhauser@'192.168.103.%' identified by 'ptg123';
Query OK, 0 rows affected (0.00 sec)
slave節(jié)點配置袋倔,所有節(jié)點master必須一致并且都得創(chuàng)建賬號
server_id=2
log-bin
read_only
relay_log_purge=0
skip_name_resolve=1
mysql> CHANGE MASTER TO MASTER_HOST='192.168.103.72', MASTER_USER='repluser',MASTER_PASSWORD='ptg123', MASTER_LOG_FILE='mariadb
mysql> grant replication slave on *.* to repluser@'192.168.103.%' identified by 'ptg123';
Query OK, 0 rows affected (0.00 sec)
mysql > grant all on *.* to mhauser@'192.168.103.%' identified by 'ptg123';
Query OK, 0 rows affected (0.00 sec)bin.000001',MASTER_LOG_POS=542;
Query OK, 0 rows affected (0.01 sec)
在MHA上利用前臺監(jiān)視master DB
[root@localhost ~]# masterha_manager --conf=/etc/mastermha/app1.cnf
Sun Apr 25 20:41:10 2021 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sun Apr 25 20:41:10 2021 - [info] Reading application default configuration from /etc/mastermha/app1.cnf..
Sun Apr 25 20:41:10 2021 - [info] Reading server configuration from /etc/mastermha/app1.cnf..
![image.png](https://upload-images.jianshu.io/upload_images/25265206-fd41e33d8cf173c4.png?
主服務down了后會自動退出
image.png
imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)