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

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

Jun 01, 2016 pm 01:17 PM
manager master Host website project

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管理用
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
Is there any website for learning C language? Is there any website for learning C language? Jan 30, 2024 pm 02:38 PM

Websites for learning C language: 1. C Language Chinese Website; 2. Rookie Tutorial; 3. C Language Forum; 4. C Language Empire; 5. Script House; 6. Tianji.com; 7. Red and Black Alliance; 8, 51 Self-study network; 9. Likou; 10. C Programming. Detailed introduction: 1. C language Chinese website, which is a website dedicated to providing C language learning materials for beginners. It is rich in content, including basic grammar, pointers, arrays, functions, structures and other modules; 2. Rookie tutorials, This is a comprehensive programming learning website and more.

Can AI conquer Fermat's last theorem? Mathematician gave up 5 years of his career to turn 100 pages of proof into code Can AI conquer Fermat's last theorem? Mathematician gave up 5 years of his career to turn 100 pages of proof into code Apr 09, 2024 pm 03:20 PM

Fermat's last theorem, about to be conquered by AI? And the most meaningful part of the whole thing is that Fermat’s Last Theorem, which AI is about to solve, is precisely to prove that AI is useless. Once upon a time, mathematics belonged to the realm of pure human intelligence; now, this territory is being deciphered and trampled by advanced algorithms. Image Fermat's Last Theorem is a "notorious" puzzle that has puzzled mathematicians for centuries. It was proven in 1993, and now mathematicians have a big plan: to recreate the proof using computers. They hope that any logical errors in this version of the proof can be checked by a computer. Project address: https://github.com/riccardobrasca/flt

Share an easy way to package PyCharm projects Share an easy way to package PyCharm projects Dec 30, 2023 am 09:34 AM

Share the simple and easy-to-understand PyCharm project packaging method. With the popularity of Python, more and more developers use PyCharm as the main tool for Python development. PyCharm is a powerful integrated development environment that provides many convenient functions to help us improve development efficiency. One of the important functions is project packaging. This article will introduce how to package projects in PyCharm in a simple and easy-to-understand way, and provide specific code examples. Why package projects? Developed in Python

PyCharm Practical Tips: Convert Project to Executable EXE File PyCharm Practical Tips: Convert Project to Executable EXE File Feb 23, 2024 am 09:33 AM

PyCharm is a powerful Python integrated development environment that provides a wealth of development tools and environment configurations, allowing developers to write and debug code more efficiently. In the process of using PyCharm for Python project development, sometimes we need to package the project into an executable EXE file to run on a computer that does not have a Python environment installed. This article will introduce how to use PyCharm to convert a project into an executable EXE file, and give specific code examples. head

A closer look at PyCharm: a quick way to delete projects A closer look at PyCharm: a quick way to delete projects Feb 26, 2024 pm 04:21 PM

Title: Learn more about PyCharm: An efficient way to delete projects. In recent years, Python, as a powerful and flexible programming language, has been favored by more and more developers. In the development of Python projects, it is crucial to choose an efficient integrated development environment. As a powerful integrated development environment, PyCharm provides Python developers with many convenient functions and tools, including deleting project directories quickly and efficiently. The following will focus on how to use delete in PyCharm

Lenovo YOGA Portal mini host officially announced on July 27, released by ChinaJoy, with built-in 350W power supply Lenovo YOGA Portal mini host officially announced on July 27, released by ChinaJoy, with built-in 350W power supply Jul 23, 2024 pm 01:47 PM

According to news from this site on July 23, Lenovo’s YOGA Portal high-performance desktop computer, which has been exposed for a long time, is now confirmed to be officially released at ChinaJoy in Shanghai on July 27. It is claimed to be a mini host designed for professional AI creation. It is a performance master and an expert in AI creation of 3D digital people. The AI ​​virtual background is based on the on-site pictures provided by our friend @yuP in Shanghai. The volume of this small host is only 3.7L. It is made of anodized aluminum and is equipped with Intel Core. i7-14700 processor, equipped with 32GBDDR5 memory and 1TB solid state drive. YOGA Portal is both a host and an all-in-one AI creation machine. The high-performance host is combined with an algorithm-optimized camera to form an integrated solution. Just stand in front of the camera i.e.

MSI showcases MEG Vision MSI showcases MEG Vision Jun 09, 2024 am 11:15 AM

According to news from this site on June 5, MSI participated in the 2024 Taipei International Computer Show and showcased a new flagship gaming computer called MEGVisionXAI. This game console is an extension of the existing Vision series and uses a very eye-catching surround glass design, with internal components clearly visible. The most attractive part is that the front of the host is equipped with an oversized touch screen. MSI staff said that it can synchronize MSI’s exclusive AI applications to further enhance various AI functions. The relevant pictures attached to this site are as follows: MSI has not yet explained more details. From the pictures shared, you can see that a local AI chatbot is running on the screen. Users can interact with it and ask it to complete AI tasks and locate locally stored documents. wait. Source of the above picture:

Basic tutorial: Create a Maven project using IDEA Basic tutorial: Create a Maven project using IDEA Feb 19, 2024 pm 04:43 PM

IDEA (IntelliJIDEA) is a powerful integrated development environment that can help developers develop various Java applications quickly and efficiently. In Java project development, using Maven as a project management tool can help us better manage dependent libraries, build projects, etc. This article will detail the basic steps on how to create a Maven project in IDEA, while providing specific code examples. Step 1: Open IDEA and create a new project Open IntelliJIDEA

See all articles