当前位置:Gxlcms > mysql > Mysql高可用架构MHA搭建及测试故障转移_MySQL

Mysql高可用架构MHA搭建及测试故障转移_MySQL

时间:2021-07-01 10:21:17 帮助过:26人阅读

MHA项目网站

https://code.google.com/p/mysql-master-ha/

一.环境介绍

1.主机部署

manager机:10.10.54.154
master机:10.10.54.156
slave1机:10.10.54.155(备用master)

slave2机:10.10.54.157

2.大致步骤
A.首先用ssh-keygen实现四台主机之间相互免密钥登录
B.安装MHAmha4mysql-node,mha4mysql-manager 软件包
C.建立master,slave1,slave2之间主从复制
D.管理机manager上配置MHA文件
E.masterha_check_ssh工具验证ssh信任登录是否成功
F.masterha_check_repl工具验证mysql复制是否成功
G.启动MHA manager,并监控日志文件
H.测试master(156)宕机后,是否会自动切换

3.说明:下面中括号中的主机名说明了当前操作是在哪台机子上进行的

二.首先用ssh-keygen实现四台主机之间相互免密钥登录

[manager机]
shell> ssh-keygen -t rsa -b 2048
shell> scp-copy-id root@10.10.54.155

shell> scp-copy-id root@10.10.54.156

shell> scp-copy-id root@10.10.54.157

在另外三台机子重复此步骤,使四台机子中的任何两台之间可以免密码登录

三.安装MHAmha4mysql-node,mha4mysql-manager 软件包

1.四台主机上安装MHAmha4mysql-node

12345[manager,master,slave1,slave2]shell> yum updateshell> yum -y install perl-DBD-MySQL ncftpshell> wget http://mysql-master-ha.googlecode.com/files/mha4mysql-node-0.53-0.noarch.rpmsehll> rpm -ivh mha4mysql-node-0.53-0.noarch.rpm

2.在manager机子上安装mha4mysql-manager

123456789101112131415161718192021[manager]shell> yum install perlshell> yum install cpanshell> rpm -ivh mha4mysql-manager-0.53-0.el6.noarch.rpmerror:perl(Config::Tiny) is needed by mha4mysql-manager-0.53-0.noarchperl(Log::Dispatch) is needed by mha4mysql-manager-0.53-0.noarchperl(Log::Dispatch::File) is needed by mha4mysql-manager-0.53-0.noarchperl(Log::Dispatch::Screen) is needed by mha4mysql-manager-0.53-0.noarchperl(Parallel::ForkManager) is needed by mha4mysql-manager-0.53-0.noarchperl(Time::HiRes) is needed by mha4mysql-manager-0.53-0.noarch[solution]shell> wget ftp://ftp.muug.mb.ca/mirror/centos/5.10/os/x86_64/CentOS/perl-5.8.8-41.el5.x86_64.rpmshell> wget ftp://ftp.muug.mb.ca/mirror/centos/6.5/os/x86_64/Packages/compat-db43-4.3.29-15.el6.x86_64.rpmshell> wget http://downloads.naulinux.ru/pub/NauLinux/6x/i386/sites/School/RPMS/perl-Log-Dispatch-2.27-1.el6.noarch.rpmshell> wget http://dl.fedoraproject.org/pub/epel/6/i386/perl-Parallel-ForkManager-0.7.9-1.el6.noarch.rpmshell> wget http://dl.fedoraproject.org/pub/epel/6/i386/perl-Mail-Sender-0.8.16-3.el6.noarch.rpmshell> wget http://dl.fedoraproject.org/pub/epel/6/i386/perl-Mail-Sendmail-0.79-12.el6.noarch.rpmshell> wget http://mirror.centos.org/centos/6/os/x86_64/Packages/perl-Time-HiRes-1.9721-136.el6.x86_64.rpmshell> rpm -ivh perl-Parallel-ForkManager-0.7.9-1.el6.noarch.rpm perl-Log-Dispatch-2.27-1.el6.noarch.rpm perl-Mail-Sender-0.8.16-3.el6.noarch.rpm perl-Mail-Sendmail-0.79-12.el6.noarch.rpm perl-Time-HiRes-1.9721-136.el6.x86_64.rpmshell> rpm -ivh mha4mysql-manager-0.53-0.el6.noarch.rpm

四.建立master,slave1,slave2之间主从复制

12345678910111213141516171819[master:156]1.shell> vim /etc/my.cnf#server-id 改为1server-id=1log-bin=mysql-binbinlog_format=mixed#授权操作2.mysql> GRANT ALL PRIVILEGES ON *.* TO 'rep'@'10.10.54.%' IDENTIFIED BY 'rep123';mysql> flush privileges;3.mysql> show master status;[slave1,slave2]4.change master操作mysql> change master tomaster_host='10.10.54.156',master_port=3306,master_user='rep',master_password='rep123',master_log_file='mysql-bin.000001',master_log_pos=112;

注意:slave1机子上也要授权,因为这个是备用master
[slave1:155]
5.mysql> GRANT ALL PRIVILEGES ON *.* TO 'rep'@'10.10.54.%' IDENTIFIED BY 'rep123';


[master,slave1,slave2]
6.查看主从复制是否成功的一些命令
mysql> start slave;
mysql> stop slave;
mysql> reset slave;
mysql> show slave status/G;

五.所有主机上设置复制权限帐号
mysql> GRANT ALL PRIVILEGES ON *.* TO 'mha_rep'@'10.10.2.10' IDENTIFIED BY '123456';

六.manager上配置MHA文件,管理各个节点

[manager:154]
shell> mkdir -p /masterha/app1
shell> mkdir /etc/masterha
shell> vim /etc/masterha/app1.cnf

12345678910111213141516171819202122232425[server default]user=mha_rep ##mysql管理用

人气教程排行