search
HomeDatabaseMysql TutorialMySQL原生HA方案 – Fabric感受之旅

MySQL原生HA方案 – Fabric体验之旅 关键字:MySQL原生HA方案 – Fabric体验之旅 tag:云计算MySQL FabricHA方案. 转自:http://www.csdn.net/article/2014-08-20/2821300 摘要:众所周知,Fabric能提供MySQL的HA和Sharding方案,但是并没有具体的介绍其具体的

MySQL原生HA方案 – Fabric体验之旅
关键字:MySQL原生HA方案 – Fabric体验之旅
tag:云计算MySQL FabricHA方案.

转自:http://www.csdn.net/article/2014-08-20/2821300

摘要:众所周知,Fabric能提供MySQL的HA和Sharding方案,但是并没有具体的介绍其具体的表现和搭建部署流程。笔者所在团队亲身体验了此过程,虽然过程简单但是却充满着无穷的乐趣,也为未来的应用带来了福音。


还在为MySQL HA方案的选型头疼吗?现在不用了,自从2014年5月28日Oracle发布Fabric之后,一切都变得如此简单。因为是原生的官方产品,可以放心使用,由于这款产品大力的增强了HA效率,可以看出Oracle对云计算的支持力度,说明Oracle这个大象也可跳舞,而且还挺灵活的。

官方对Fabric的介绍主要是它提供了MySQL的HA和Sharding方案,本文主要讨论Fabric在MySQL HA方面的表现以及搭建部署流程。我的团队试着搭建了一下,简直无法再简单了,这对于DBA来说绝对是一个大福音,这个产品在接下来的几年中必然会被大量应用到生产环境中去,我的团队对这个产品的未来充满信心。

接下来我们将循序渐进的带领大家感受Fabric带来的乐趣。

一、实验环境

本例的实验环境是在一台CentOS主机中做的,机器上有3个MySQL实例,分别是3306、3691和3692,我们要做的就是用这3个实例达成HA效果











二、下载

Fabric目前是被打包到了MySQL Utilities中,所以大家下载MySQL Utilities就可以了,下载地址是: http://dev.mysql.com/downloads/utilities/,目前版本是:1.4.4,在本例中我们下载的是 mysql-utilities-1.4.4-1.el6.noarch.rpm。


三、安装MySQL Utilities

rpm包的安装还是挺简单的,具体如下:

rpm -ivh mysql-utilities-1.4.4-1.el6.noarch.rpm
Preparing...                ########################################### [100%]
    1:mysql-utilities        ########################################### [100%]
[root@

装完后执行

mysqlfabric

如果有回显说明安装完毕。

四、建立Backing Store帐号

Backing Store用于存储整个HA集群的服务器等相关配置,它需要一个MySQL实例来存储这些信息,这个实例的版本需要跟其它在HA中的MySQL实例版本保持一致,而且必须是5.6.10及更高的版本,我们在本例中选择3306实例来使用。

首先,你需要一个帐号来连接Backing Store的MySQL实例,这个帐号需要有对fabric数据库的管理员级权限,我们在3306端口的实例上建帐号,具体如下:

CREATE USER 'fabric'@'10.165.17.175' IDENTIFIED BY 'secret';
GRANT ALL ON fabric.* TO 'fabric'@'10.165.17.175';


五、Fabric配置文件

Fabric配置文件默认位置是:/etc/mysql/fabric.cfg

修改其中的[storage]部分,具体如下:

[storage]
auth_plugin = mysql_native_password
database = fabric
user = fabric
address = 10.165.17.175:3306
connection_delay = 1
connection_timeout = 6
password = secret
connection_attempts = 6

其中address = 10.165.17.175:3306是Backing Store的MySQL实例,password = secret是上一步中建立连接fabric数据库的用户密码。

修改其中的[servers]部分,具体如下:

[servers]
password = secret
user = fabric


其中是password = secret 是HA环境中各实例的连接密码。

六、填充Backing Store信息

我们通过Fabric来填充3306端口实例中的fabric数据库,具体如下:

mysqlfabric manage setup
[INFO] 1408115689.486792 - MainThread - Initializing persister: user (fabric), server (10.165.17.175:3306), database (fabric).
Finishing initial setup
=======================
Password for admin user is not yet set.
Password for admin/xmlrpc:
Repeat Password:
Password set.

操作期间会提示Fabric的管理员帐户admin没有设置密码,咱们按提示将密码设置成admin就可以了。

我们再查看3306端口的实例里面发生了什么变化,具体如下:

mysql> show databases;
+--------------------+
| Database    |
+--------------------+
| information_schema |
| 51linux.net        |
| fabric             |
| mysql              |
| performance_schema |
+--------------------+
5 rows in set (0.00 sec)

mysql>


可以看到多了一个fabric数据库,它里面存储的就是Fabric的一些配置信息。

七、配置HA中主从MySQL节点帐号

本例中3691和3692实例是需要做成HA的,它们也要建个管理员权限的帐号,注意,帐号名也要跟3306实例保持一致,也需要是fabric,具体如下:

CREATE USER 'fabric'@'10.165.17.175' IDENTIFIED BY 'secret';
GRANT ALL ON *.* TO 'fabric'@'10.165.17.175';


同时,由于fabric是基于GTID主从复制,所以这些实例中必须要启用GTID,它们的配置文件要有这些参数:

log-bin
gtid-mode=ON
enforce-gtid-consistency
log_slave_updates


八、启动fabric

我们用下面的命令来启动fabric:

mysqlfabric manage start
[INFO] 1408116209.229260 - MainThread - Initializing persister: user (fabric), server (10.165.17.175:3306), database (fabric).
[INFO] 1408116209.233982 - MainThread - Loading Services.
[INFO] 1408116209.253620 - MainThread - Fabric node starting.
[INFO] 1408116209.261853 - MainThread - Starting Executor.
[INFO] 1408116209.262001 - MainThread - Setting 5 executor(s).
[INFO] 1408116209.262691 - Executor-0 - Started.
[INFO] 1408116209.264825 - Executor-1 - Started.
[INFO] 1408116209.266648 - Executor-2 - Started.
[INFO] 1408116209.268395 - Executor-3 - Started.
[INFO] 1408116209.269961 - MainThread - Executor started.
[INFO] 1408116209.273374 - MainThread - Starting failure detector.
[INFO] 1408116209.274144 - Executor-4 - Started.
[INFO] 1408116209.275816 - XML-RPC-Server - XML-RPC protocol server ('127.0.0.1', 32274) started.
[INFO] 1408116209.276112 - XML-RPC-Server - Setting 5 XML-RPC session(s).
[INFO] 1408116209.276654 - XML-RPC-Session-0 - Started XML-RPC-Session.
[INFO] 1408116209.278426 - XML-RPC-Session-1 - Started XML-RPC-Session.
[INFO] 1408116209.280368 - XML-RPC-Session-2 - Started XML-RPC-Session.
[INFO] 1408116209.281599 - XML-RPC-Session-3 - Started XML-RPC-Session.
[INFO] 1408116209.282699 - XML-RPC-Session-4 - Started XML-RPC-Session.


九、建立HA服务器组

这个HA服务器组,用于把参与HA的所有MySQL实例都填加进来:

mysqlfabric group create my_group
Password for admin:
Procedure :
{ uuid        = 292621fd-cddc-4cbb-8c0d-d8a264156679,
  finished    = True,
  success     = True,
  return      = True,
  activities  =
}


这样我们就创建了一个组名为my_group的HA服务器组。

十、填加HA组的成员

我们首先填加3691,具体如下:

mysqlfabric group add my_group 10.165.17.175:3691
Password for admin:
Procedure :
{ uuid        = 8d1c11f8-adc4-4321-8307-6296caeb07c1,
  finished    = True,
  success     = True,
  return      = True,
  activities  =
}


接下来填3692,具体如下:

mysqlfabric group add my_group 10.165.17.175:3692
Password for admin:
Procedure :
{ uuid        = b1fa3cb9-b86f-4b1a-88cb-e84babb2ab02,
  finished    = True,
  success     = True,
  return      = True,
  activities  =
}


如果屏幕回显示无error,那么说明成功填加了成员。我们也可以查看一下my_group里面的成员信息,具体如下:

mysqlfabric group lookup_servers my_group
Password for admin:
Command :
{ success     = True
  return      = [{'status': 'SECONDARY', 'server_uuid': '6914a176-2370-11e4-af48-00163e004141', 'mode': 'READ_ONLY', 'weight': 1.0, 'address': '10.165.17.175:3691'}, {'status': 'SECONDARY', 'server_uuid': 'a8a69428-2366-11e4-af09-00163e004141', 'mode': 'READ_ONLY', 'weight': 1.0, 'address': '10.165.17.175:3692'}]
  activities  =
}


大家可以看到,这2个实例都不是PRIMARY,说明刚刚搭建完的环境,系统是不会选举出PRIMARY的。

十一、选举一个主库

选举的方法也非常简单,具体如下:

mysqlfabric group promote my_group
Password for admin:
Procedure :
{ uuid        = 529380b9-10ef-409f-a1a9-9430ab9845a3,
  finished    = True,
  success     = True,
  return      = True,
  activities  =
}


可见执行成功了,并没有返回error。

接下来我们再次验证一下HA集群中各服务器情况。

mysqlfabric group lookup_servers my_group
Password for admin:
Command :
{ success     = True
  return      = [{'status': 'SECONDARY', 'server_uuid': '6914a176-2370-11e4-af48-00163e004141', 'mode': 'READ_ONLY', 'weight': 1.0, 'address': '10.165.17.175:3691, {'status': 'PRIMARY', 'server_uuid': 'a8a69428-2366-11e4-af09-00163e004141', 'mode': 'READ_WRITE', 'weight': 1.0, 'address': '10.165.17.175:3692}]
  activities  =
}


可见Fabric已经随机选举了一个Master角色。

十二、激活故障自动切换

即使Fabric选出了Master角色,但当这个Master宕机时,Fabric并不会自动将Secondary角色切换成Master角色,所以我们需要将HA配置成可以自动切换角色的样子,具体如下:

mysqlfabric group activate my_group
Password for admin:
Procedure :
{ uuid        = 518b7dad-06a4-45a8-bfd5-241396706b88,
  finished    = True,
  success     = True,
  return      = True,
  activities  =
}


  当然,我们也可以依据具体需求取消Fabric故障自动切换。

十三、测试HA

在这个实验中,我们将3691实例停止,再看看Fabric的状态:

mysqlfabric group lookup_servers my_group
Password for admin:
Command :
{ success     = True
  return      = [{'status': 'PRIMARY', 'server_uuid': '6914a176-2370-11e4-af48-00163e004141', 'mode': 'READ_WRITE', 'weight': 1.0, 'address': '10.165.17.175:3691}, {'status': 'FAULTY', 'server_uuid': 'a8a69428-2366-11e4-af09-00163e004141', 'mode': 'READ_WRITE', 'weight': 1.0, 'address': '10.165.17.175:3692}]
  activities  =
}


其中3692实例的状态已经变成了“FAULTY”,可以看出Fabric自动检测到了这个故障,并且选举了slave重新当了primary角色。我不得不说就是这个功能,是它吸引我的原因之一。

十四、后续学习

关于后续的学习,大家要看看官网的用户手册,里面还有很多HA维护的方法,如增减节点等问题,同时目前Fabric也提供了phtyon和Java的API,可以供软件开发人员直接使用,以后的软件开发人员,不是再直接连接到MySQL实例,而是连接到Fabric,由Fabric来统一分发请求,这有些象MySQL Proxy,但它的应用前景要比MySQL Proxy更宽更广。

作者简介:

盘古,目前主要推动公益性IT项目的发展,51linux.net联合创建人,该网站主要为那些学习linux或数据库技术的同学提供免费linux服务器。


转自:http://www.csdn.net/article/2014-08-20/2821300
Statement
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
Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Apr 16, 2025 am 12:20 AM

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL: Database Management System vs. Programming LanguageMySQL: Database Management System vs. Programming LanguageApr 16, 2025 am 12:19 AM

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL: Managing Data with SQL CommandsMySQL: Managing Data with SQL CommandsApr 16, 2025 am 12:19 AM

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.

MySQL's Purpose: Storing and Managing Data EffectivelyMySQL's Purpose: Storing and Managing Data EffectivelyApr 16, 2025 am 12:16 AM

MySQL is an efficient relational database management system suitable for storing and managing data. Its advantages include high-performance queries, flexible transaction processing and rich data types. In practical applications, MySQL is often used in e-commerce platforms, social networks and content management systems, but attention should be paid to performance optimization, data security and scalability.

SQL and MySQL: Understanding the RelationshipSQL and MySQL: Understanding the RelationshipApr 16, 2025 am 12:14 AM

The relationship between SQL and MySQL is the relationship between standard languages ​​and specific implementations. 1.SQL is a standard language used to manage and operate relational databases, allowing data addition, deletion, modification and query. 2.MySQL is a specific database management system that uses SQL as its operating language and provides efficient data storage and management.

Explain the role of InnoDB redo logs and undo logs.Explain the role of InnoDB redo logs and undo logs.Apr 15, 2025 am 12:16 AM

InnoDB uses redologs and undologs to ensure data consistency and reliability. 1.redologs record data page modification to ensure crash recovery and transaction persistence. 2.undologs records the original data value and supports transaction rollback and MVCC.

What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?What are the key metrics to look for in an EXPLAIN output (type, key, rows, Extra)?Apr 15, 2025 am 12:15 AM

Key metrics for EXPLAIN commands include type, key, rows, and Extra. 1) The type reflects the access type of the query. The higher the value, the higher the efficiency, such as const is better than ALL. 2) The key displays the index used, and NULL indicates no index. 3) rows estimates the number of scanned rows, affecting query performance. 4) Extra provides additional information, such as Usingfilesort prompts that it needs to be optimized.

What is the Using temporary status in EXPLAIN and how to avoid it?What is the Using temporary status in EXPLAIN and how to avoid it?Apr 15, 2025 am 12:14 AM

Usingtemporary indicates that the need to create temporary tables in MySQL queries, which are commonly found in ORDERBY using DISTINCT, GROUPBY, or non-indexed columns. You can avoid the occurrence of indexes and rewrite queries and improve query performance. Specifically, when Usingtemporary appears in EXPLAIN output, it means that MySQL needs to create temporary tables to handle queries. This usually occurs when: 1) deduplication or grouping when using DISTINCT or GROUPBY; 2) sort when ORDERBY contains non-index columns; 3) use complex subquery or join operations. Optimization methods include: 1) ORDERBY and GROUPB

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor