Rumah > pangkalan data > tutorial mysql > Mysql高可用架构MHA搭建及测试故障转移_MySQL

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

WBOY
Lepaskan: 2016-06-01 13:17:28
asal
1306 orang telah melayarinya

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]<code class="bash plain">shell> yum update<code class="bash plain">shell> yum -y <code class="bash functions">install <code class="bash plain">perl-DBD-MySQL ncftp<code class="bash plain">shell> wget http:<code class="bash plain">//mysql-master-ha<code class="bash plain">.googlecode.com<code class="bash plain">/files/mha4mysql-node-0<code class="bash plain">.53-0.noarch.rpm<code class="bash plain">sehll> rpm -ivh mha4mysql-node-0.53-0.noarch.rpm<p>2.在manager机子上安装mha4mysql-manager</p>123456789101112131415161718192021<code class="bash plain">[manager]<code class="bash plain">shell> yum <code class="bash functions">install <code class="bash plain">perl<code class="bash plain">shell> yum <code class="bash functions">install <code class="bash plain">cpan<code class="bash plain">shell> rpm -ivh mha4mysql-manager-0.53-0.el6.noarch.rpm<code class="bash plain">error:<code class="bash plain">perl(Config::Tiny) is needed by mha4mysql-manager-0.53-0.noarch<code class="bash plain">perl(Log::Dispatch) is needed by mha4mysql-manager-0.53-0.noarch<code class="bash plain">perl(Log::Dispatch::File) is needed by mha4mysql-manager-0.53-0.noarch<code class="bash plain">perl(Log::Dispatch::Screen) is needed by mha4mysql-manager-0.53-0.noarch<code class="bash plain">perl(Parallel::ForkManager) is needed by mha4mysql-manager-0.53-0.noarch<code class="bash plain">perl(Time::HiRes) is needed by mha4mysql-manager-0.53-0.noarch<code class="bash plain">[solution]<code class="bash plain">shell> wget <code class="bash functions">ftp<code class="bash plain">:<code class="bash plain">//ftp<code class="bash plain">.muug.mb.ca<code class="bash plain">/mirror/centos/5<code class="bash plain">.10<code class="bash plain">/os/x86_64/CentOS/perl-5<code class="bash plain">.8.8-41.el5.x86_64.rpm<code class="bash plain">shell> wget <code class="bash functions">ftp<code class="bash plain">:<code class="bash plain">//ftp<code class="bash plain">.muug.mb.ca<code class="bash plain">/mirror/centos/6<code class="bash plain">.5<code class="bash plain">/os/x86_64/Packages/compat-db43-4<code class="bash plain">.3.29-15.el6.x86_64.rpm<code class="bash plain">shell> wget http:<code class="bash plain">//downloads<code class="bash plain">.naulinux.ru<code class="bash plain">/pub/NauLinux/6x/i386/sites/School/RPMS/perl-Log-Dispatch-2<code class="bash plain">.27-1.el6.noarch.rpm<code class="bash plain">shell> wget http:<code class="bash plain">//dl<code class="bash plain">.fedoraproject.org<code class="bash plain">/pub/epel/6/i386/perl-Parallel-ForkManager-0<code class="bash plain">.7.9-1.el6.noarch.rpm<code class="bash plain">shell> wget http:<code class="bash plain">//dl<code class="bash plain">.fedoraproject.org<code class="bash plain">/pub/epel/6/i386/perl-Mail-Sender-0<code class="bash plain">.8.16-3.el6.noarch.rpm<code class="bash plain">shell> wget http:<code class="bash plain">//dl<code class="bash plain">.fedoraproject.org<code class="bash plain">/pub/epel/6/i386/perl-Mail-Sendmail-0<code class="bash plain">.79-12.el6.noarch.rpm<code class="bash plain">shell> wget http:<code class="bash plain">//mirror<code class="bash plain">.centos.org<code class="bash plain">/centos/6/os/x86_64/Packages/perl-Time-HiRes-1<code class="bash plain">.9721-136.el6.x86_64.rpm<code class="bash plain">shell> 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.rpm<code class="bash plain">shell> rpm -ivh mha4mysql-manager-0.53-0.el6.noarch.rpm<p>四.建立master,slave1,slave2之间主从复制<br></p>12345678910111213141516171819<code class="bash plain">[master:156]<code class="bash plain">1.shell> vim <code class="bash plain">/etc/my<code class="bash plain">.cnf<code class="bash comments">#server-id 改为1<code class="bash plain">server-<code class="bash functions">id<code class="bash plain">=1<code class="bash plain">log-bin=mysql-bin<code class="bash plain">binlog_format=mixed<code class="bash comments">#授权操作<code class="bash plain">2.mysql> GRANT ALL PRIVILEGES ON *.* TO <code class="bash string">'rep'<code class="bash plain">@<code class="bash string">'10.10.54.%' <code class="bash plain">IDENTIFIED BY <code class="bash string">'rep123'<code class="bash plain">;<code class="bash plain">mysql> flush privileges;<code class="bash plain">3.mysql> show master status;<code class="bash plain">[slave1,slave2]<code class="bash plain">4.change master操作<code class="bash plain">mysql> change master to<code class="bash plain">master_host=<code class="bash string">'10.10.54.156'<code class="bash plain">,<code class="bash plain">master_port=3306,<code class="bash plain">master_user=<code class="bash string">'rep'<code class="bash plain">,<code class="bash plain">master_password=<code class="bash string">'rep123'<code class="bash plain">,<code class="bash plain">master_log_file=<code class="bash string">'mysql-bin.000001'<code class="bash plain">,<code class="bash plain">master_log_pos=112;<p>注意:slave1机子上也要授权,因为这个是备用master<br>[slave1:155]<br>5.mysql> GRANT ALL PRIVILEGES ON *.* TO 'rep'@'10.10.54.%' IDENTIFIED BY 'rep123';</p> <p><br>[master,slave1,slave2]<br>6.查看主从复制是否成功的一些命令<br>mysql> start slave;<br>mysql> stop slave;<br>mysql> reset slave;<br>mysql> show slave status/G;<br></p> <p>五.所有主机上设置复制权限帐号<br>mysql> GRANT ALL PRIVILEGES ON *.* TO 'mha_rep'@'10.10.2.10' IDENTIFIED BY '123456';</p> <p>六.manager上配置MHA文件,管理各个节点<br></p> <p>[manager:154]<br>shell> mkdir -p /masterha/app1<br>shell> mkdir /etc/masterha<br>shell> vim /etc/masterha/app1.cnf</p>12345678910111213141516171819202122232425<code class="bash plain">[server default]<code class="bash plain">user=mha_rep <code class="bash comments">##mysql管理用
Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan