MySQL的高可用解决方案其实有很多种(想了解自行百度),这里只说其中一种:MHA。这也是当前比较主流的方案。
在搭建MHA之前应该先保证已经安装配置好了MySQL的主从/集群。因为既然是高可用架构,那么针对的肯定是多台设备,单机的话谈不上高可用。
MySQL的主从搭建过程这里就不说了,可以看这里: MySQL搭建主从架构
本次搭建环境:centos7.8 + mysql5.7.31
现在的架构是 :
101:主节点
102:从节点1
103:从节点2
手动将101的MySQL主节点关闭,在102的节点上查看VIP,发现配置的VIP:192.168.232.105已经从101节点漂移到102节点了。
然后在103的节点上可以看到主节点确实已经变成了 102
到此,MHA 搭建大功告成啦!
MHA 的切换过程,共包括以下的步骤:
最后说明一点,宕机的节点,重启后由于MySQL机制问题不会自动加入到集群中,需要我们手动加入。
安装基本环境:master:192.168.0.1
node:192.168.0.2192.168.0.3
vip:192.168.0.101
master: https://github.com/yoshinorim/mha4mysql-manager/releases
node: https://github.com/yoshinorim/mha4mysql-node/releases
安装epel源
yum install -y epel-release
安装perl
yum install perl-DBD-MySQL
yum install perl-Config-Tiny
yum install perl-Log-Dispatch
yum install perl-Parallel-ForkManager
master 192.168.0.1 >>slave:192.168.0.2 192.168.0.3
创建mha账号
在manager节点和node节点中都需要安装mha node
rpm包安装方式:
yum localinstall -y mha4mysql-node-0.58-0.el7.centos.noarch.rpm
只在manager节点上安装
rpm包安装方式:
yum localinstall -y mha4mysql-manager-0.58-0.el7.centos.noarch.rpm
mkdir /etc/masterha
vim /etc/masterha/app1.conf
全局配置文件
vim /etc/masterha/masterha_defaults.conf
绑定和删除vip节点
master_ip_failover: https://github.com/yoshinorim/mha4mysql-manager/blob/master/samples/scripts/master_ip_failover
master_ip_online_change: https://github.com/yoshinorim/mha4mysql-manager/blob/master/samples/scripts/master_ip_online_change
根据作者的脚本来进行改写配置。
报错:
[/usr/local/share/perl5/MHA/MasterMonitor.pm,ln205] Slaves settings check failed!
[/usr/local/share/perl5/MHA/MasterMonitor.pm,ln413] Slave configuration failed.
[/usr/local/share/perl5/MHA/MasterMonitor.pm,ln424] Error happened on checking configurations. at /usr/local/bin/masterha_check_repl line 48
[/usr/local/share/perl5/MHA/MasterMonitor.pm,ln523] Error happened on monitoring servers.
[info] Got exit code 1 (Not master dead).
MySQL Replication Health is NOT OK!
在所有节点执行:
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
执行后再次报错:
[info] Connecting to root@192.168.0.1(192.168.0.1:22)..
Can't exec "mysqlbinlog": No suchfile or directory at /usr/local/share/perl5/MHA/BinlogManager.pm line 106.
mysqlbinlog version command failed with rc1:0, please verify PATH, LD_LIBRARY_PATH, and client options
at/usr/local/bin/apply_diff_relay_logs line 493
[/usr/local/share/perl5/MHA/MasterMonitor.pm,ln205] Slaves settings check failed!
[/usr/local/share/perl5/MHA/MasterMonitor.pm,ln413] Slave configuration failed.
[/usr/local/share/perl5/MHA/MasterMonitor.pm,ln424] Error happened on checking configurations. at /usr/local/bin/masterha_check_repl line 48
[/usr/local/share/perl5/MHA/MasterMonitor.pm,ln523] Error happened on monitoring servers.
Got exit code 1 (Not master dead).
MySQL Replication Health is NOT OK!
在所有节点执行
[root@master masterha]#type mysqlbinlog
[root@master masterha]#mysqlbinlog is/usr/local/mysql/bin/mysqlbinlog
[root@master masterha]#ln -s/usr/local/mysql/bin/mysqlbinlog /usr/bin/mysqlbinlog
原因:都是没有在指定位置找到相应的文件,所以做一个软链
启动:
第一次,手动绑定vip
sh /etc/masterha/init_vip.sh
检查MHA是否启动和状态
cat /var/log/masterha/app1.log
停止:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)