美文网首页运维
MHA 高可用搭建

MHA 高可用搭建

作者: 麟之趾a | 来源:发表于2020-04-05 17:41 被阅读0次

环境准备

主机 IP地址 身份
db01 10.0.0.11 master
db02 10.0.0.12 slave
db02 10.0.0.13 slave

配置节点互信

db01:
rm -rf /root/.ssh 
ssh-keygen
cd /root/.ssh 
mv id_rsa.pub authorized_keys
scp  -r  /root/.ssh  10.0.0.12:/root 
scp  -r  /root/.ssh  10.0.0.13:/root 
各节点验证
db01:
ssh 10.0.0.11 date
ssh 10.0.0.12 date
ssh 10.0.0.13 date
db02:
ssh 10.0.0.11 date
ssh 10.0.0.12 date
ssh 10.0.0.13 date
db03:
ssh 10.0.0.11 date
ssh 10.0.0.12 date
ssh 10.0.0.13 date

下载mha软件

mha官网:https://code.google.com/archive/p/mysql-master-ha/
github下载地址:https://github.com/yoshinorim/mha4mysql-manager/wiki/Downloads

所有节点安装Node软件依赖包

yum install perl-DBD-MySQL -y
rpm -ivh mha4mysql-node-0.56-0.el6.noarch.rpm

在db01主库中创建mha需要的用户

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

Manager软件安装(db03)

yum install -y perl-Config-Tiny epel-release perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes
rpm -ivh mha4mysql-manager-0.56-0.el6.noarch.rpm

配置文件准备(db03)

创建配置文件目录
 mkdir -p /etc/mha
创建日志目录
 mkdir -p /var/log/mha/app1
编辑mha配置文件
vim /etc/mha/app1.cnf
[server default]
manager_log=/var/log/mha/app1/manager
manager_workdir=/var/log/mha/app1
master_binlog_dir=/data/binlog
user=mha
password=mha
ping_interval=2
repl_password=123
repl_user=repl
ssh_user=root
[server1]
hostname=10.0.0.11
port=3306
[server2]
hostname=10.0.0.12
port=3306
[server3]
hostname=10.0.0.13
port=3306

mha互信检查

masterha_check_ssh  --conf=/etc/mha/app1.cnf
Sun Apr  5 12:44:21 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sun Apr  5 12:44:21 2020 - [info] Reading application default configuration from /etc/mha/app1.cnf..
Sun Apr  5 12:44:21 2020 - [info] Reading server configuration from /etc/mha/app1.cnf..
Sun Apr  5 12:44:21 2020 - [info] Starting SSH connection tests..
Sun Apr  5 12:44:22 2020 - [debug] 
Sun Apr  5 12:44:21 2020 - [debug]  Connecting via SSH from root@10.0.0.11(10.0.0.11:22) to root@10.0.0.12(10.0.0.12:22)..
Sun Apr  5 12:44:21 2020 - [debug]   ok.
Sun Apr  5 12:44:21 2020 - [debug]  Connecting via SSH from root@10.0.0.11(10.0.0.11:22) to root@10.0.0.13(10.0.0.13:22)..
Sun Apr  5 12:44:22 2020 - [debug]   ok.
Sun Apr  5 12:44:23 2020 - [debug] 
Sun Apr  5 12:44:22 2020 - [debug]  Connecting via SSH from root@10.0.0.12(10.0.0.12:22) to root@10.0.0.11(10.0.0.11:22)..
Sun Apr  5 12:44:22 2020 - [debug]   ok.
Sun Apr  5 12:44:22 2020 - [debug]  Connecting via SSH from root@10.0.0.12(10.0.0.12:22) to root@10.0.0.13(10.0.0.13:22)..
Sun Apr  5 12:44:22 2020 - [debug]   ok.
Sun Apr  5 12:44:24 2020 - [debug] 
Sun Apr  5 12:44:22 2020 - [debug]  Connecting via SSH from root@10.0.0.13(10.0.0.13:22) to root@10.0.0.11(10.0.0.11:22)..
Warning: Permanently added '10.0.0.13' (ECDSA) to the list of known hosts.
Sun Apr  5 12:44:22 2020 - [debug]   ok.
Sun Apr  5 12:44:22 2020 - [debug]  Connecting via SSH from root@10.0.0.13(10.0.0.13:22) to root@10.0.0.12(10.0.0.12:22)..
Sun Apr  5 12:44:23 2020 - [debug]   ok.
Sun Apr  5 12:44:24 2020 - [info] All SSH connection tests passed successfully.

mha主从检查

[root@db03 ~]# masterha_check_repl --conf=/etc/mha/app1.cnf
Sun Apr  5 12:45:39 2020 - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.
Sun Apr  5 12:45:39 2020 - [info] Reading application default configuration from /etc/mha/app1.cnf..
Sun Apr  5 12:45:39 2020 - [info] Reading server configuration from /etc/mha/app1.cnf..
Sun Apr  5 12:45:39 2020 - [info] MHA::MasterMonitor version 0.56.
Sun Apr  5 12:45:40 2020 - [info] GTID failover mode = 1
Sun Apr  5 12:45:40 2020 - [info] Dead Servers:
Sun Apr  5 12:45:40 2020 - [info] Alive Servers:
Sun Apr  5 12:45:40 2020 - [info]   10.0.0.11(10.0.0.11:3306)
Sun Apr  5 12:45:40 2020 - [info]   10.0.0.12(10.0.0.12:3306)
Sun Apr  5 12:45:40 2020 - [info]   10.0.0.13(10.0.0.13:3306)
Sun Apr  5 12:45:40 2020 - [info] Alive Slaves:
Sun Apr  5 12:45:40 2020 - [info]   10.0.0.12(10.0.0.12:3306)  Version=5.7.26-log (oldest major version between slaves) log-bin:enabled
Sun Apr  5 12:45:40 2020 - [info]     GTID ON
Sun Apr  5 12:45:40 2020 - [info]     Replicating from 10.0.0.11(10.0.0.11:3306)
Sun Apr  5 12:45:40 2020 - [info]   10.0.0.13(10.0.0.13:3306)  Version=5.7.26-log (oldest major version between slaves) log-bin:enabled
Sun Apr  5 12:45:40 2020 - [info]     GTID ON
Sun Apr  5 12:45:40 2020 - [info]     Replicating from 10.0.0.11(10.0.0.11:3306)
Sun Apr  5 12:45:40 2020 - [info] Current Alive Master: 10.0.0.11(10.0.0.11:3306)
Sun Apr  5 12:45:40 2020 - [info] Checking slave configurations..
Sun Apr  5 12:45:40 2020 - [info]  read_only=1 is not set on slave 10.0.0.12(10.0.0.12:3306).
Sun Apr  5 12:45:40 2020 - [info]  read_only=1 is not set on slave 10.0.0.13(10.0.0.13:3306).
Sun Apr  5 12:45:40 2020 - [info] Checking replication filtering settings..
Sun Apr  5 12:45:40 2020 - [info]  binlog_do_db= , binlog_ignore_db= 
Sun Apr  5 12:45:40 2020 - [info]  Replication filtering check ok.
Sun Apr  5 12:45:40 2020 - [info] GTID (with auto-pos) is supported. Skipping all SSH and Node package checking.
Sun Apr  5 12:45:40 2020 - [info] Checking SSH publickey authentication settings on the current master..
Sun Apr  5 12:45:40 2020 - [info] HealthCheck: SSH to 10.0.0.11 is reachable.
Sun Apr  5 12:45:40 2020 - [info] 
10.0.0.11(10.0.0.11:3306) (current master)
 +--10.0.0.12(10.0.0.12:3306)
 +--10.0.0.13(10.0.0.13:3306)

Sun Apr  5 12:45:40 2020 - [info] Checking replication health on 10.0.0.12..
Sun Apr  5 12:45:40 2020 - [info]  ok.
Sun Apr  5 12:45:40 2020 - [info] Checking replication health on 10.0.0.13..
Sun Apr  5 12:45:40 2020 - [info]  ok.
Sun Apr  5 12:45:40 2020 - [warning] master_ip_failover_script is not defined.
Sun Apr  5 12:45:40 2020 - [warning] shutdown_script is not defined.
Sun Apr  5 12:45:40 2020 - [info] Got exit code 0 (Not master dead).

MySQL Replication Health is OK.

开启mha

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 &

mha状态检查

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

相关文章

网友评论

    本文标题:MHA 高可用搭建

    本文链接:https://www.haomeiwen.com/subject/mkzuphtx.html