MySQL集群核心概念

MySQL Cluster Core Concepts

NDBCLUSTER (also known as NDB) is an in-memory storage engine offering high-availability and data-persistence features.

NDBCLUSTER(也叫做NDB)是一种提供了高可用性和数据持久性特征的内存式存储引擎。

The NDBCLUSTER storage engine can be configured with a range of failover and load-balancing options, but it is easiest to start with the storage engine at the cluster level. MySQL Cluster's NDB storage engine contains a complete set of data, dependent only on other data within the cluster itself.

NDBCLUSTER存储引擎能够配置一系列的故障切换和负载均衡功能,然而它也是在集群级别下最容易入手的存储引擎。MySQL集群的NDB存储引擎包含一套完整的数据集,它仅依赖于在集群本身中的其他数据。

The Cluster portion of MySQL Cluster is configured independently of the MySQL servers. In a MySQL Cluster, each part of the cluster is considered to be a node.

MySQL集群的Cluster部分是独立配置在MySQL服务上面的。在MySQL集群中,集群的每个部分都被看做是一个节点(node)


Note

In many contexts, the term node is used to indicate a computer, but when discussing MySQL Cluster it means a process. It is possible to run multiple nodes on a single computer; for a computer on which one or more cluster nodes are being run we use the term cluster host.


注解:

在多数情况下,node这个术语用于表示一台计算机,但是当讨论MySQL集群时,则它意味着是一个进程。在一台单独的PC机上能够运行多个node节点;在PC机上正在运行的一个或多个集群节点,我们通常把他称为集群主机(cluster host)

There are three types of cluster nodes, and in a minimal MySQL Cluster configuration, there will be at least three nodes, one of each of these types:

集群的节点有三种类型,在最低限度的MySQL集群配置中,每一种类型的节点要有一个,至少要有三个节点:

  • Management node: The role of this type of node is to manage the other nodes within the MySQL Cluster, performing such functions as providing configuration data, starting and stopping nodes, running backup, and so forth. Because this node type manages the configuration of the other nodes, a node of this type should be started first, before any other node. An MGM node is started with the command ndb_mgmd.

管理节点(Management node):这种节点的任务主要是在MySQL集群中管理其他节点。执行诸如提供配置数据,打开节点,关闭节点,运行备份等等相应功能。由于这种类型的节点管理着其他节点的配置,因此该节点应先于其他节点启动。一个MGM节点是通过ndb_mgmd命令来启动的。


  • Data node: This type of node stores cluster data. There are as many data nodes as there are replicas, times the number of fragments (see Section 18.1.2, “MySQL Cluster Nodes, Node Groups, Replicas, and Partitions”). For example, with two replicas, each having two fragments, you need four data nodes. One replica is sufficient for data storage, but provides no redundancy; therefore, it is recommended to have 2 (or more) replicas to provide redundancy, and thus high availability. A data node is started with the command ndbd (see Section 18.4.1, “ndbd — The MySQL Cluster Data Node Daemon”) or ndbmtd (see Section 18.4.3, “ndbmtd — The MySQL Cluster Data Node Daemon (Multi-Threaded)”).

    MySQL Cluster tables are normally stored completely in memory rather than on disk (this is why we refer to MySQL Cluster as an in-memory database). However, some MySQL Cluster data can be stored on disk; see Section 18.5.12, “MySQL Cluster Disk Data Tables”, for more information.


数据节点(Data node):这种类型的节点用于存储集群数据。很多的数据节点都有它们的副本,是该分段的一倍。例如,每两个分段就有两个副本,你就需要有四个数据节点。对于数据存储,一个副本是足够的,但是它不提供冗余。因此,我们推荐用两个(或更多)副本去提供冗余,从而实现高可用性。一个数据节点是通过ndbd或ndbmtd命令来启动的。

MySQL集群表通常是完整的存储在内存中的,而不是在硬盘上(这就是为什么我们把MySQL集群称为内存式数据库)。然而,有一些MySQL集群数据是可以存储在硬盘上的。

  • SQL node: This is a node that accesses the cluster data. In the case of MySQL Cluster, an SQL node is a traditional MySQL server that uses the NDBCLUSTER storage engine. An SQL node is a mysqld process started with the --ndbcluster and --ndb-connectstring options, which are explained elsewhere in this chapter, possibly with additional MySQL server options as well.

    An SQL node is actually just a specialized type of API node, which designates any application which accesses MySQL Cluster data. Another example of an API node is the ndb_restore utility that is used to restore a cluster backup. It is possible to write such applications using the NDB API. For basic information about the NDB API, see Getting Started with the NDB API.

SQL节点(SQL node):这种节点是用于访问集群数据的。对于MySQL集群来讲,一个SQL节点是一个传统的MySQL服务,它使用NDBCLUSTER存储引擎。一个SQL节点是通过mysqld命令的--ndbcluster和--ndb-connectstring参数来启动的进程,该选项在本章的其他地方会解释到,用其他的MySQL服务选项也可以做到。

一个SQL节点实际上只是API node的一种专用类型,该类型的节点指定了任何可以访问MySQL集群数据的应用程序。API node的另外一个例子是node_restore功能,它能够被用来恢复一个集群备份。用NDB API去写应用程序是有可能做到的,有关于NDB API的基本信息,请见Getting Started with the NDB API.

Important

It is not realistic to expect to employ a three-node setup in a production environment. Such a configuration provides no redundancy; to benefit from MySQL Cluster's high-availability features, you must use multiple data and SQL nodes. The use of multiple management nodes is also highly recommended.

重要性

在生产环境中使用三个节点去进行设置是不现实的。诸如提供一个没有冗余的配置;想要发挥MySQL集群高可用性的优点,你必须使用多数据和多SQL节点。多管理节点的使用同样也被强烈推荐。


For a brief introduction to the relationships between nodes, node groups, replicas, and partitions in MySQL Cluster, see Section 18.1.2, “MySQL Cluster Nodes, Node Groups, Replicas, and Partitions”.


关于在MySQL集群中的节点,节点组,副本以及分区之间的关系的简单介绍,请见Section 18.1.2,“MySQL Cluster Nodes, Node Groups, Replicas, and Partitions”.


Configuration of a cluster involves configuring each individual node in the cluster and setting up individual communication links between nodes. MySQL Cluster is currently designed with the intention that data nodes are homogeneous in terms of processor power, memory space, and bandwidth. In addition, to provide a single point of configuration, all configuration data for the cluster as a whole is located in one configuration file.

在集群中,集群的配置包括配置每一个单独的节点,并且在节点之间需要设置单独的通讯链接。MySQL集群当前的设计意图是依据处理器功率,内存空间以及带宽来将数据节点均匀分布的。此外,对于提供配置的一个单一节点,在集群中所有的配置数据都是作为一个整体存在于一个配置文件上的。


The management server manages the cluster configuration file and the cluster log. Each node in the cluster retrieves the configuration data from the management server, and so requires a way to determine where the management server resides. When interesting events occur in the data nodes, the nodes transfer information about these events to the management server, which then writes the information to the cluster log.

服务管理器管理着集群的配置文件和日志。在集群中的每一个节点都会从服务管理器中去检索配置数据,因此需要通过一种方法来确定服务管理器所在的位置。当我们把注意力关注在数据节点上发生的事件时,对于服务管理器来讲,数据节点将传输关于这些事件的信息,然后把该信息写到集群日志里面。


In addition, there can be any number of cluster client processes or applications. These include standard MySQL clients, NDB-specific API programs, and management clients. These are described in the next few paragraphs.

此外,还有很多集群客户端进程或应用程序。他们包含了标准的MySQL客户端,NDB-特定的API程序,和管理客户端。这些将在接下来的段落中进行介绍。

Standard MySQL clients.  MySQL Cluster can be used with existing MySQL applications written in PHP, Perl, C, C++, Java, Python, Ruby, and so on. Such client applications send SQL statements to and receive responses from MySQL servers acting as MySQL Cluster SQL nodes in much the same way that they interact with standalone MySQL servers.

标准的MySQL客户端:MySQL集群能够和已存在的用PHP,Perl,C,C++,Java,Python,Ruby等语言实现的MySQL应用程序一起使用。诸如客户端发送SQL语句并从以MySQL集群节点为代理的MySQL服务器上去接受响应,该节点以同样的方式去和MySQL服务器独立的进行交互。


MySQL clients using a MySQL Cluster as a data source can be modified to take advantage of the ability to connect with multiple MySQL servers to achieve load balancing and failover. For example, Java clients using Connector/J 5.0.6 and later can use jdbc:mysql:loadbalance:// URLs (improved in Connector/J 5.1.7) to achieve load balancing transparently; for more information about using Connector/J with MySQL Cluster, see Using Connector/J with MySQL Cluster.

MySQL客户端将MySQL集群作为一个数据源,利用它能够被修改的能力来和多个MySQL服务器去实现负载均衡和故障转移。例如,Java客户端利用Connector/J 5.0.6和以后使用jdbc:mysql:loadbalance:// URLs(在Connector/J 5.1.7中有所提高)能够显而易见的去实现负载均衡;有关和MySQL集群去使用Connector/J的更多信息,见Using Connector/J with MySQL Cluster.


NDB client programs.  Client programs can be written that access MySQL Cluster data directly from the NDBCLUSTER storage engine, bypassing any MySQL Servers that may connected to the cluster, using the NDB API, a high-level C++ API. Such applications may be useful for specialized purposes where an SQL interface to the data is not needed. For more information, see The NDB API.

NDB客户端程序:客户端程序能够编写为从NDBCLUSTER存储引擎中直接去访问MySQL集群数据,绕过许多能够连接到集群的MySQL服务器,使用NDB API,一个高级别的C++ API。

这样的应用程序,对于数据来讲SQL接口是不需要,通过这种特定的目的,它可能是有用的。想了解更多的信息,见The NDB API.


NDB-specific Java applications can also be written for MySQL Cluster using the MySQL Cluster Connector for Java. This MySQL Cluster Connector includes ClusterJ, a high-level database API similar to object-relational mapping persistence frameworks such as Hibernate and JPA that connect directly to NDBCLUSTER, and so does not require access to a MySQL Server. Support is also provided in MySQL Cluster NDB 7.1 and later for ClusterJPA, an OpenJPA implementation for MySQL Cluster that leverages the strengths of ClusterJ and JDBC; ID lookups and other fast operations are performed using ClusterJ (bypassing the MySQL Server), while more complex queries that can benefit from MySQL's query optimizer are sent through the MySQL Server, using JDBC. See Java and MySQL Cluster, and The ClusterJ API and Data Object Model, for more information.

具有NDB特性的Java应用程序同样也能利用MySQL Cluster Connector forJava编写出MySQL集群。这种MySQL集群连接器包括ClusterJ,一个直接连接NDBCLUSTER的类似于Hibernate和JPA的对象-关系型持久层框架的高级别数据库API,因此它不需要去访问MySQL服务。对于ClusterJPA,在MySQLCluster NDB 7.1和以后的版本中同样支持,OpenJPA利用了ClusterJ和JDBC的优势实现了MySQL的集群。ID查找和其他快速操作是通过ClusterJ来执行的(不通过MySQLServer),而更复杂的查询是受益于MySQL的查询优化器通过MySQL服务用JDBC进行发送操作而得到的好处。见 Javaand MySQL Cluster, 和The ClusterJ API and Data Object Model, 以便获得更多的信息。

MySQL Cluster NDB 7.3 also supports applications written in JavaScript using Node.js. The MySQL Connector for JavaScript includes adapters for direct access to the NDB storage engine and as well as for the MySQL Server. Applications using this Connector are typically event-driven and use a domain object model similar in many ways to that employed by ClusterJ. For more information, see MySQL NoSQL Connector for JavaScript.

MySQL Cluster NDB 7.3同样支持在应用程序中用Node.js去编写JavaScript。对于JavaScript,MySQL连接器包含可以直接访问NDB存储引擎和MySQL服务的适配器。使用该连接器的应用程序通常是事件驱动的并且利用ClusterJ服务的多种方式去使用类似的域对象模型。想要了解更多的信息,请见MySQL NoSQL Connector for JavaScript.


The Memcache API for MySQL Cluster, implemented as the loadable ndbmemcache storage engine for memcached version 1.6 and later, can be used to provide a persistent MySQL Cluster data store, accessed using the memcache protocol.

对于MySQL集群,Memcached 1.6和以后的版本实现了可加载的ndbmemcache存储引擎,它能够被用来提供一个持久的MySQL集群数据存储,并利用memcache协议来进行访问。


The standard memcached caching engine is included in the MySQL Cluster NDB 7.3 distribution. Each memcached server has direct access to data stored in MySQL Cluster, but is also able to cache data locally and to serve (some) requests from this local cache.

标准的memcached缓存引擎是包含在MySQLCluster NDB 7.3分布上的。在MySQL集群中,每个memcached服务都可以直接去访问所存储的数据,但同样能够从本地缓存中去请求本地化的缓存数据和(一些)服务。


For more information, see ndbmemcache—Memcache API for MySQL Cluster.

想了解更多信息,请见ndbmemcache—Memcache API for MySQL Cluster.


Management clients.  These clients connect to the management server and provide commands for starting and stopping nodes gracefully, starting and stopping message tracing (debug versions only), showing node versions and status, starting and stopping backups, and so on. An example of this type of program is the ndb_mgm management client supplied with MySQL Cluster (see Section 18.4.5, “ ndb_mgm — The MySQL Cluster Management Client”). Such applications can be written using the MGM API, a C-language API that communicates directly with one or more MySQL Cluster management servers. For more information, see The MGM API.

管理客户端:这些连接到管理服务器上的客户端提供了开始和停止节点的命令,开始和停止信息跟踪(仅debug版本),显示节点的版本和状态,开始和停止备份等等。举例说明,某种类型的程序在MySQL集群中提供了ndb_mgm管理客户端(见Section 18.4.5,“ndb_mgm — The MySQL ClusterManagement Client”)。该程序能够使用MGM API来进行编写,一个C语言的API能够直接和一个或多个MySQL集群管理服务器进行交互。想了解更多信息,见The MGM API。


Oracle also makes available MySQL Cluster Manager, which provides an advanced command-line interface simplifying many complex MySQL Cluster management tasks, such restarting a MySQL Cluster with a large number of nodes. The MySQL Cluster Manager client also supports commands for getting and setting the values of most node configuration parameters as well as mysqld server options and variables relating to MySQL Cluster. MySQL Cluster Manager 1.1 provides support for adding data nodes online. See the MySQL Cluster Manager User Manual, for more information.

Oracle同样提供了MySQL集群管理器,它提供一种高级的命令行接口,去简化了复杂的MySQL集群管理任务,如用大量的节点去重新启动一个MySQL集群。MySQL集群管理客户端同样支持命令来设置和获得许多节点配置的参数值和mysqld服务选项以及和MySQL集群有关的变量。MySQL集群管理器1.1版本提供了支持增加在线数据节点。想了解更多信息,见MySQL Cluster Manager User Manual。


Event logs.  MySQL Cluster logs events by category (startup, shutdown, errors, checkpoints, and so on), priority, and severity. A complete listing of all reportable events may be found in Section 18.5.6, “Event Reports Generated in MySQL Cluster”. Event logs are of the two types listed here:

  • Cluster log: Keeps a record of all desired reportable events for the cluster as a whole.

  • Node log: A separate log which is also kept for each individual node.

事件日志:MySQL集群通过种类(启动,关机,错误,检查点等等),优先级和严重性的事件产生日志。一个有关完整的报告性事件的监听,可以在Section 18.5.6,“Event Reports Generated in MySQL Cluster”文章中找到。事件日志在这里有两种类型:

 

集群日志:针对于集群,以保存一份期望的可报告性的事件记录作为一个整体。

节点日志:一个单独的日志维护着每一个单一的节点。


Note

Under normal circumstances, it is necessary and sufficient to keep and examine only the cluster log. The node logs need be consulted only for application development and debugging purposes.

注意:

一般情况下,充分的去保存和检查集群日志是很有必要的。而节点日志则仅仅是作为开发和调试目的去检查的。


Checkpoint.  Generally speaking, when data is saved to disk, it is said that a checkpoint has been reached. More specific to MySQL Cluster, a checkpoint is a point in time where all committed transactions are stored on disk. With regard to the NDB storage engine, there are two types of checkpoints which work together to ensure that a consistent view of the cluster's data is maintained. These are shown in the following list:

检查点:一般而言,当数据存到硬盘上时,Checkpoint就已经存在了。对于MySQL集群更明确的讲,一个检查点就是一个存储在硬盘上及时提交事务的点。对于NDB存储引擎来讲,这两种类型的检查点是一起工作的,并确保了集群数据的一致性视图是可维护的。这些会显示在以下列表中:

Local Checkpoint (LCP): This is a checkpoint that is specific to a single node; however, LCPs take place for all nodes in the cluster more or less concurrently. An LCP involves saving all of a node's data to disk, and so usually occurs every few minutes. The precise interval varies, and depends upon the amount of data stored by the node, the level of cluster activity, and other factors.

本地检查点(LCP):对于一个单一的节点来说,这是一个特殊的检查点。然而,LCPs在集群的所有节点中或多或少是同时发生的。一个LCP在硬盘上涉及到了所保留的所有数据节点,因此在通常每隔几分钟都会发生。精确的时间间距各不相同,并且需要通过节点依赖于大量所存储的数据,集群的级别是活跃的,或者其他因素。


Global Checkpoint (GCP): A GCP occurs every few seconds, when transactions for all nodes are synchronized and the redo-log is flushed to disk.

全局检查点(GCP):一个GCP每隔几秒就会发生一次,此时所有节点的事务是同步的,并且重写的日志会刷新到硬盘上。


For more information about the files and directories created by local checkpoints and global checkpoints, see MySQL Cluster Data Node FileSystemDir Files.

关于通过本地检查点和全局检查点创建的文件和目录的更多信息,请见MySQL Cluster Data Node FileSystemDir Files


该文章摘自http://dev.mysql.com/doc/refman/5.6/en/mysql-cluster-basics.html


你可能感兴趣的:(mysql,api)