MySQL Cluster -- NDB Cluster

MySQL Cluster --  NDB Cluster

 

The engine used for tables in MySQL cluster is ndbcluster, or ndb for short.

It means: "Network database". NDB (also called NDB Cluster or NDBCLUSTER), use it to allow MySQL to support clustering.

 

  • To get MySQL Cluster functionality, the mysql-server and mysql-max RPMs must be installed
  • Memory Database
  • It consists of multiple nodes, each node has corresponding memory and disk, and there is no single point of failure.
  • MySQL Cluster can configure the NDB storage engine with various failover and load balancing options

 


 

 

 

 

I have learned about MySQL master-slave before. Now the cluster must be distinguished from the master-slave. The difference between the two is:

 

  • In a replicated system, a MySQL master updates one or more slaves. Transactions are committed sequentially, so a slow transaction can cause the slave to lag behind the master for a period of time. This also means that if the master fails If it fails, the slave server may be missing the last small part of the transaction log. If a transaction-safe storage engine is used, such as InnoDB, then the transaction log will be completely recorded to the slave server or not recorded at all, but the replication There is no guarantee that the data on the master and slave servers will always be consistent.
  • In a MySQL cluster, all data is always synchronized, and transactions submitted on any data node are synchronized to all other data nodes. If one data node fails, other normal data nodes can still keep the data. consistency.

 

To put it simply, the master-slave will cause the transaction of the slave database to be slower. When the transaction fails, the slave server will not execute it, causing the master server to have an error log, but the slave server does not. In this way, the log data is inconsistent (for the timeliness of data, integrity is optimized).

 

 

 

Cluster Recommendations

 

      The cluster requires at least 3 computers. However, we recommend 4 computers; there are 2 computers running the management node and SQL node respectively, and the other 2 computers are used as data nodes. The purpose of adopting 2 data nodes is to improve data redundancy. The management node is placed on a separate host to ensure arbitration services in the event of a data node failure.

 

 

 

The role of each node in the cluster

 

      MySQL集群既有物理也有逻辑组织,每台计算机都作为物理基础元素.集群中的逻辑基础元素称为 节点,集群中的每个逻辑和功能基础元素也称为 集群主机.共有3中节点类型,每个在集群中都有对应的不同角色,分别如下:



 

  • 管理节点(MGM node): 提供整个集群的管理服务,包括启动,关闭,备份,数据配置等.管理节点是由 ndb_mgmd 应用程序来提供的;管理节点的客户端用 ndb_mgm。
  • 数据节点: 存储和复制数据,系统会尽量将数据放在内存中,由进程(ndbd 来处理的。
  • SQL 节点: 这是用来访问数据节点的,一个SQL节点就是一个使用NDB引擎的mysql server进程(mysqld),用于供外部应用提供集群数据的访问入口。

启动节点

 

需要按以下顺序分别启动集群中的各个节点:

 

  • 用 ndb_mgmd 命令启动管理节点.
  • 用 ndbd 分别启动每个数据节点.
  • 用 mysqld_safe --user=mysql & 命令启动每个SQL节点.

上面的命令都需要在系统的shell下运行(在服务器上执行或通过终端都可以).可以在管理节点上的 ndb_mgm 客户端工具中执行 SHOW 或 ALL STATUS 命令来确认集群是否在运行状态。

 

 

停止节点

 

在 MGM 客户端中运行 SHUTDOWN 命令即可关闭运行中的集群.另外,也可以在管理节点主机中执行一下命令来关闭:

 

shell> ndb_mgm -e "SHUTDOWN"

注意,括号中的内容可以是别的,并且 SHUTDOWN 可以不区分大小写.

 

这些命令的任何一个都能平和地关闭 ndb_mgm, ndb_mgmd(笔误?), ndbd 中的任何进程.运行MySQL集群的SQL节点服务器则通过 mysqladmin shutdown 来关闭.

 

 

 

 

缺点

 

      NDB的事务隔离级别只支持Read Committed,而Innodb支持所有的事务隔离级别,默认使用Repeatable Read。

 

 

 

 

使用集群时遇到的问题

 

ERROR 1114: The table 'my_cluster_table' is full

 

原因

很有可能是因为你设置的内存不足以装下所有的数据表及其索引,包括 NDB 存储引擎中所需的主键以及如果没有定义主键时自动创建的索引.

 

所有的数据节点的内存大小都要一样,由于集群中任何数据节点都不能使用比其他数据节点最小内存还多的内存.换句话说,如果集群中有4台计算机,如果有3台计算机的内存都是3GB,而另外一台只有1GB,那么每个数据节点最多只能拿出1GB内存用于集群。

 

 

 

MySQL集群的局限性

 

MySQL 5.0中的 NDB 表存在以下局限性:

 

  • 不支持临时表;执行 CREATE TEMPORARY TABLE 语句时如果指定 ENGINE=NDB 或者ENGINE=NDBCLUSTER 参数就会报错.
  • 不支持 FULLTEXT 索引以及前缀索引.只能对整个字段进行索引.
  • 不支持空间数据类型.详情请看 Chapter 16, Spatial Extensions.
  • 只支持完全的回滚事务.不支持部分回滚和回滚到保存点也不支持.
  • 一个表最大的属性数为128,并且每个属性名不能超过31个字符.对每个表来说,数据库和表明的联合长度最大是122个字符.
  • 表中一条记录最大值为8KB,不包含 BLOB 的值.表的大小取决于各种制约因素,尤其是每个数据节点最大的可用内存.
  • NDB 存储引擎不支持外键.跟 MyISAM 一样,它们都不支持.

 

 

 

MySQL集群数据类型

 

MySQL集群支持所有常用的数据类型,除了跟MySQL相关的空间扩展类型

 

另外,NDB

表的索引也有些不同. 注意: MySQL集群表(即 NDB 或 NDBCLUSTER 类型表)只支持固定长度记录.这也意味着(举例)如果有一条记录包含有 VARCHAR(255) 字段,那么它就会需要用到255个字符的空间(和数据表使用的字符集和校验所要求的空间一样大),而不管实际存储的字符数.这个问题在未来的发行版中会得到解决.

 

 

 

集群停止后,数据会怎样?

 

本来保存在内存中的集群数据都会写到磁盘中,下次集群启动的时候就会重新载入到内存中.

 

 

 

参考:

http://imysql.cn/node/161

https://www.2cto.com/database/201504/387166.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326405759&siteId=291194637