MySQL MHA高可用环境搭建

一、安装MHA基本环境
1. 安装MHA node
(1) 基本环境说明,本文参考互联网文章学习,搭建MHA与测试如下。
参考文档:
角色                IP地址            主机名   
=============================================   
Master              192.168.1.121    node1   
Slave              192.168.1.122    node2   
Slave              192.168.1.123    node3   
Monitor host        192.168.1.125    node5


(2) 在node1,node2,node3,node5操作:
# vi /etc/hosts
192.168.1.121  node1 
192.168.1.122  node2   
192.168.1.123  node3   
192.168.1.125  node5
安装MHA node节点软件包:
# rpm -ivh Fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm   
# yum install perl-DBD-MySQL perl-CPAN -y   
# tar xf mha4mysql-node-0.56.tar.gz   
# cd mha4mysql-node-0.56   
# perl Makefile.PL       
# make && make install   
 
2. 安装MHA Manager
在node5管理节点上操作:注:MHA Manager主机也是需要安装MHA Node,MHA Manger
# yum install perl-DBD-MySQL perl-CPAN perl-Config-Tiny perl-Log-Dispatch perl-Parallel-ForkManager perl-Time-HiRes -y 
# tar xf mha4mysql-manager-0.56.tar.gz   
# cd mha4mysql-manager-0.56   
# perl Makefile.PL   
# make && make install
#说明:安装的脚本程序都在/usr/local/bin/目录下。 
 
3. 节点间配置SSH登录无密码验证(MHA主机之间使用key登录)
在node5(Monitor):
# ssh-keygen -t rsa 
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node1   
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node2   
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node3
在node1(Master):
# ssh-keygen -t rsa 
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node2   
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node3   
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node5
在node2 (slave):
# ssh-keygen -t rsa 
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node1   
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node3   
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node5
在node3 (slave):
# ssh-keygen -t rsa 
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node1   
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node2   
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node5


二、搭建主从复制环境
1. 主从复制环境配置过程
(1) mysql安装过程略,但是三节点要创建如下链接
node1(主),node2(主备从),node3(从)
注意:创建如下链接: 
ln -s /usr/local/mysql/bin/* /usr/local/bin/
node1 my.cnf
server-id              = 1 
binlog-format          = ROW   
log-bin                = master-bin   
log-bin-index          = master-bin.index   
log-slave-updates      = true   
relay_log_purge        = 0
node2 my.cnf
server-id              = 2 
binlog-format          = ROW   
log-bin                = master-bin   
log-bin-index          = master-bin.index   
log-slave-updates      = true   
relay_log_purge        = 0
node3 my.cnf
binlog-format          = ROW 
log-bin                = mysql-bin   
relay-log              = slave-relay-bin   
relay-log-index        = slave-relay-bin.index   
log-slave-updates      = true   
server-id              = 11   
skip-name-resolve   
relay_log_purge        = 0


(2) 在node1 (Master)上备份一份完整的数据:
# mysqldump -uroot -p123456 --master-data=2 --single-transaction -R --triggers -A > all.sql
其中--master-data=2代表备份时刻记录master的Binlog位置和Position。


(3) 在node1 (Master)上创建复制用户:
mysql> grant replication slave on *.* to 'repl'@'192.168.1.%' identified by '123456';   
mysql> flush privileges;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/33f1d15d8837f955282f8c830e136209.html