1. 程式人生 > 實用技巧 >MySQL MHA安裝配置

MySQL MHA安裝配置

1.環境規劃

192.168.12.131 node01
192.168.12.132 node02
192.168.12.133 node03

2.環境準備

一主兩從GTID,略。

3.配置關鍵程式軟連線(所有節點)

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

4.配置各節點互信(金鑰對)

rm -rf mv /home/mysql/.ssh
ssh‐keygen
cd /home/mysql/.ssh
mv id_rsa.pub authorized_keys
scp ‐r /root/.ssh 192.168.12.132:/home/mysql
scp ‐r /root/.ssh 192.168.12.133:/home/mysql

驗證:
node1:
ssh 192.168.12.132 date
ssh 192.168.12.133 date

node2:
ssh 192.168.12.131 date
ssh 192.168.12.133 date

node3:
ssh 192.168.12.131 date
ssh 192.168.12.132 date

5.安裝軟體

#node軟體和manager軟體下載連線:
https://github.com/yoshinorim/mha4mysql-manager/releases/tag/v0.58
https://github.com/yoshinorim/mha4mysql-node/releases/tag/v0.58

#所有節點安裝node軟體依賴包
yum install perl‐DBD‐MySQL ‐y

#安裝node軟體
rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch

#在主庫中建立mha需要的使用者 
grant all privileges on *.* to mha@'192.168.12.%' identified by 'mha'; 

#node03節點安裝manager軟體依賴包
yum install ‐y perl‐Config‐Tiny epel‐release perl‐Log‐Dispatch perl‐Parallel‐ForkManager perl‐Time‐HiRes 

#安裝manager軟體
rpm -ivh mha4mysql-manager-0.58-0.el7.centos.noarch

  

6.Manager配置檔案準備

#建立配置檔案目錄 
mkdir ‐p /etc/mha 
#建立日誌目錄 
mkdir ‐p /var/log/mha/app1 
#編輯mha配置檔案 
[root@node03 ~]# vim /etc/mha/app1.cnf
[server default]
manager_log=/var/log/mha/app1/manager
manager_workdir=/var/log/mha/app1
master_binlog_dir=/mysql/binlog
user=mha
password=mysql
ping_interval=2
repl_password=mysql
repl_user=repl
ssh_user=mysql
[server1]
hostname=192.168.12.131
port=3306
[server2]
hostname=192.168.12.132
port=3306
[server3]
hostname=192.168.12.133
port=3306

7.狀態檢查

檢查互信:
[mysql@node3 ~]$ masterha_check_ssh --conf=/etc/mha/app1.cnf                                                  
Sat Jul 11 20:02:04 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sat Jul 11 20:02:04 2020 - [info] Reading application default configuration from /etc/mha/app1.cnf..
Sat Jul 11 20:02:04 2020 - [info] Reading server configuration from /etc/mha/app1.cnf..
Sat Jul 11 20:02:04 2020 - [info] Starting SSH connection tests..
Sat Jul 11 20:02:05 2020 - [debug]
Sat Jul 11 20:02:04 2020 - [debug]  Connecting via SSH from [email protected](192.168.12.131:22) to [email protected](192.168.12.132:22)..
Sat Jul 11 20:02:05 2020 - [debug]   ok.
Sat Jul 11 20:02:05 2020 - [debug]  Connecting via SSH from [email protected](192.168.12.131:22) to [email protected](192.168.12.133:22)..
Sat Jul 11 20:02:05 2020 - [debug]   ok.
Sat Jul 11 20:02:06 2020 - [debug]
Sat Jul 11 20:02:05 2020 - [debug]  Connecting via SSH from [email protected](192.168.12.132:22) to [email protected](192.168.12.131:22)..
Sat Jul 11 20:02:05 2020 - [debug]   ok.
Sat Jul 11 20:02:05 2020 - [debug]  Connecting via SSH from [email protected](192.168.12.132:22) to [email protected](192.168.12.133:22)..
Sat Jul 11 20:02:06 2020 - [debug]   ok.
Sat Jul 11 20:02:07 2020 - [debug]
Sat Jul 11 20:02:05 2020 - [debug]  Connecting via SSH from [email protected](192.168.12.133:22) to [email protected](192.168.12.131:22)..
Sat Jul 11 20:02:06 2020 - [debug]   ok.
Sat Jul 11 20:02:06 2020 - [debug]  Connecting via SSH from [email protected](192.168.12.133:22) to [email protected](192.168.12.132:22)..
Sat Jul 11 20:02:06 2020 - [debug]   ok.
Sat Jul 11 20:02:07 2020 - [info] All SSH connection tests passed successfully.


檢查主從複製狀態:
[mysql@node3 ~]$ masterha_check_repl --conf=/etc/mha/app1.cnf                                                 
Sat Jul 11 20:03:29 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sat Jul 11 20:03:29 2020 - [info] Reading application default configuration from /etc/mha/app1.cnf..
Sat Jul 11 20:03:29 2020 - [info] Reading server configuration from /etc/mha/app1.cnf..
Sat Jul 11 20:03:29 2020 - [info] MHA::MasterMonitor version 0.58.
Sat Jul 11 20:03:30 2020 - [info] GTID failover mode = 1
Sat Jul 11 20:03:30 2020 - [info] Dead Servers:
Sat Jul 11 20:03:30 2020 - [info] Alive Servers:
Sat Jul 11 20:03:30 2020 - [info]   192.168.12.131(192.168.12.131:3306)
Sat Jul 11 20:03:30 2020 - [info]   192.168.12.132(192.168.12.132:3306)
Sat Jul 11 20:03:30 2020 - [info]   192.168.12.133(192.168.12.133:3306)
Sat Jul 11 20:03:30 2020 - [info] Alive Slaves:
Sat Jul 11 20:03:30 2020 - [info]   192.168.12.132(192.168.12.132:3306)  Version=5.7.29-log (oldest major version between slaves) log-bin:enabled
Sat Jul 11 20:03:30 2020 - [info]     GTID ON
Sat Jul 11 20:03:30 2020 - [info]     Replicating from 192.168.12.131(192.168.12.131:3306)
Sat Jul 11 20:03:30 2020 - [info]   192.168.12.133(192.168.12.133:3306)  Version=5.7.29-log (oldest major version between slaves) log-bin:enabled
Sat Jul 11 20:03:30 2020 - [info]     GTID ON
Sat Jul 11 20:03:30 2020 - [info]     Replicating from 192.168.12.131(192.168.12.131:3306)
Sat Jul 11 20:03:30 2020 - [info] Current Alive Master: 192.168.12.131(192.168.12.131:3306)
Sat Jul 11 20:03:30 2020 - [info] Checking slave configurations..
Sat Jul 11 20:03:30 2020 - [info]  read_only=1 is not set on slave 192.168.12.132(192.168.12.132:3306).
Sat Jul 11 20:03:30 2020 - [info]  read_only=1 is not set on slave 192.168.12.133(192.168.12.133:3306).
Sat Jul 11 20:03:30 2020 - [info] Checking replication filtering settings..
Sat Jul 11 20:03:30 2020 - [info]  binlog_do_db= , binlog_ignore_db=
Sat Jul 11 20:03:30 2020 - [info]  Replication filtering check ok.
Sat Jul 11 20:03:30 2020 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Sat Jul 11 20:03:30 2020 - [info] Checking SSH publickey authentication settings on the current master..
Sat Jul 11 20:03:31 2020 - [info] HealthCheck: SSH to 192.168.12.131 is reachable.
Sat Jul 11 20:03:31 2020 - [info]
192.168.12.131(192.168.12.131:3306) (current master)
 +--192.168.12.132(192.168.12.132:3306)
 +--192.168.12.133(192.168.12.133:3306)

Sat Jul 11 20:03:31 2020 - [info] Checking replication health on 192.168.12.132..
Sat Jul 11 20:03:31 2020 - [info]  ok.
Sat Jul 11 20:03:31 2020 - [info] Checking replication health on 192.168.12.133..
Sat Jul 11 20:03:31 2020 - [info]  ok.
Sat Jul 11 20:03:31 2020 - [warning] master_ip_failover_script is not defined.
Sat Jul 11 20:03:31 2020 - [warning] shutdown_script is not defined.
Sat Jul 11 20:03:31 2020 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.

  

  

8.開啟MHA-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 &

10.檢視MHA狀態

[root@node03 ~]# masterha_check_status --conf=/etc/mha/app1.cnf
app1 (pid:1827) is running(0:PING_OK), master:192.168.12.131