环境准备:四台Linux环境服务器(CentOS7),其中三台安装mysql,三台mysql服务器一台作为主库,另外两台作为从库,实现主从复制
*注:建议最好使用CentOS7,本人开始使用的是CentOS8,但是在安装mha4mysql-manager的过程中出现了各种依赖问题
ssh-keygen -t rsa
ssh-copy-id 192.168.132.132
cat /root/.ssh/authorized_keys
cat /root/.ssh/id_rsa_pub >> /root/.ssh/authorized_keys
scp /root/.ssh/authorized_keys root@192.168.132.128:/root/.ssh/authorized_keys
scp /root/.ssh/authorized_keys root@192.168.132.129:/root/.ssh/authorized_keys
scp /root/.ssh/authorized_keys root@192.168.132.130:/root/.ssh/authorized_keys
ssh 192.168.132.128
以下示例在连网环境下进行,未连网环境下,需要前往http://rpm.pbone.net/自行下载安装包
yum install -y perl-DBD-MySQL
wget https://github.com/yoshinorim/mha4mysql-node/releases/download/v0.58/mha4mysql-node-0.58-0.el7.centos.noarch.rpm
rpm -ivh mha4mysql-node-0.58-0.el7.centos.noarch.rpm
*注:perl-Log-Dispatch和perl-Parallel-ForkManager这两个被依赖包在yum仓库找不到,因此安装epel-release
wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -ivh epel-release-latest-7.noarch.rpm
yum install -y perl-Config-Tiny
yum install -y perl-Log-Dispatch
yum install -y perl-Parallel-ForkManager
wget https://github.com/yoshinorim/mha4mysql-manager/releases/download/v0.58/mha4mysql-manager-0.58-0.el7.centos.noarch.rpm
rpm -ivh mha4mysql-manager-0.58-0.el7.centos.noarch.rpm
MHA Manager服务器需要为每个监控的服务器提供一个专用的配置文件
vim /etc/masterha_default.cnf
vi /etc/mha/app1.cnf
masterha_check_ssh --conf=/etc/mha/app1.cnf
masterha_check_repl --conf=/etc/mha/app1.cnf
*注:主、从库相关配置参数需保持一致,如:log_bin、binlog-ignore-db等参数,否则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 &
masterha_check_status --conf=/etc/mha/app1.cnf
tail -n20 /var/log/mha/app1/manager.log