视频1 视频21 视频41 视频61 视频文章1 视频文章21 视频文章41 视频文章61 推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37 推荐39 推荐41 推荐43 推荐45 推荐47 推荐49 关键词1 关键词101 关键词201 关键词301 关键词401 关键词501 关键词601 关键词701 关键词801 关键词901 关键词1001 关键词1101 关键词1201 关键词1301 关键词1401 关键词1501 关键词1601 关键词1701 关键词1801 关键词1901 视频扩展1 视频扩展6 视频扩展11 视频扩展16 文章1 文章201 文章401 文章601 文章801 文章1001 资讯1 资讯501 资讯1001 资讯1501 标签1 标签501 标签1001 关键词1 关键词501 关键词1001 关键词1501 专题2001
Mysql高可用架构MHA搭建及测试故障转移_MySQL
2020-11-09 19:10:11 责编:小采
文档


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

1234567101112131415161718192021[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_/CentOS/perl-5.8.8-41.el5.x86_.rpmshell> wget ftp://ftp.muug.mb.ca/mirror/centos/6.5/os/x86_/Packages/compat-db43-4.3.29-15.el6.x86_.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_/Packages/perl-Time-HiRes-1.9721-136.el6.x86_.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_.rpmshell> rpm -ivh mha4mysql-manager-0.53-0.el6.noarch.rpm

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

123456710111213141516171819[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

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

下载本文
显示全文