首页 > 其他分享 >NDB Cluster基本操作

NDB Cluster基本操作

时间:2022-09-29 12:00:18浏览次数:77  
标签:Node ndb -- NDB Cluster mysql 基本操作 节点


  1. NDB Cluster启动

关闭和开启顺序相反是:管理节点-->数据节点-->SQL节点。

 

注意:在MySQL Cluster环境中,NDB节点和管理节点的关闭/启动都可以在管理节点的管理程序中完成,也可以分节点关闭,但是SQL节点无法通过管理节点来关闭/启动。所以,在关闭/启动整个MySQL Cluster环境或者关闭/启动某个SQL节点的时候,首先必须到SQL节点主机上来关闭/启动SQL节点程序。关闭方法和MySQL Server的关闭一样。

  1. 管理节点启动

[root@NDB-MGM ~]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini

MySQL Cluster Management Server mysql-5.7.20 ndb-7.5.8i

  1. 数据节点启动
  1. 通过管理节点启动

注意:使用管理节点启动数据节点是有条件的,数据节点必须已经使用--nostart或-n参数启动了。

  1. 以nostart方式打开

[root@NDB-DATA1 ~]# ndbd --nostart

2017-12-14 09:57:49 [ndbd] INFO     -- Angel connected to 'NDB-MGM:1186'

2017-12-14 09:57:49 [ndbd] INFO     -- Angel allocated nodeid: 2

  1. 查看集群的数据节点状态

id=2 @192.168.1.123  (mysql-5.7.20 ndb-7.5.8, not started)

  1. 在管理节点启动数据节点

ndb_mgm> 2 start;

Database node 2 is being started.

Node 2: Start initiated (version 7.5.8)

 

ndb_mgm> show

Cluster Configuration

---------------------

[ndbd(NDB)]    2 node(s)

id=2 @192.168.1.123  (mysql-5.7.20 ndb-7.5.8, starting, Nodegroup: 0)

可以看到已经启动了。

  1. 在数据节点直接启动

[root@NDB-DATA2 ~]# ndbd

2017-12-14 10:01:28 [ndbd] INFO     -- Angel connected to 'NDB-MGM:1186'

2017-12-14 10:01:28 [ndbd] INFO     -- Angel allocated nodeid: 3

  1. 查看集群状态

ndb_mgm> show

Cluster Configuration

---------------------

[ndbd(NDB)]    2 node(s)

id=2 @192.168.1.123  (mysql-5.7.20 ndb-7.5.8, Nodegroup: 0, *)

id=3 @192.168.1.124  (mysql-5.7.20 ndb-7.5.8, Nodegroup: 0)

 

  1. SQL节点启动

就是启动mysql服务。

[root@NDB-SQL1 mysql]service mysql.server stop

Shutting down MySQL..                                      [  OK  ]

[root@NDB-SQL1 mysql]/usr/local/mysql/support-files/mysql.server start

Shutting down MySQL..                                      [  OK  ]

 

更多管理NDB集群的信息,请查看官方文档:

​https://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-management.html​

  1. NDB Cluster关闭

关闭和开启顺序相反是:SQL节点-->数据节点-->管理节点。

注意:在MySQL Cluster环境中,NDB节点和管理节点的关闭都可以在管理节点的管理程序中完成,也可以分节点关闭,但是SQL节点无法通过管理节点来关闭。所以,在关闭整个MySQL Cluster环境或者关闭某个SQL节点的时候,首先必须到SQL节点主机上来关闭SQL节点程序。关闭方法和MySQL Server的关闭一样。

 

  1. SQL节点关闭

[root@NDB-SQL1 mysql]service mysql.server stop

Shutting down MySQL..                                      [  OK  ]

[root@NDB-SQL1 mysql]/usr/local/mysql/support-files/mysql.server start

Shutting down MySQL..                                      [  OK  ]

  1. 数据节点关闭

[root@NDB-DATA1 mysql]ndbd stop

2014-04-15 23:54:36 [ndbd] INFO     -- Angel connected to '192.168.0.30:1186'

2014-04-15 23:54:36 [ndbd] INFO     -- Angel allocated nodeid: 2

[root@NDB-DATA1 mysql]

  1. 管理节点关闭

ndb_mgm> shutdown

Node 2: Cluster shutdown initiated

Node 3: Cluster shutdown initiated

3 NDB Cluster node(s) have shutdown.

Disconnecting to allow management server to shutdown.

Node 3: Node shutdown completed.

ndb_mgm>

 

更多管理NDB集群的信息,请查看官方文档:

​https://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-management.html​

  1. 日志管理

MySQL Cluster提供了两种日志,分别是集群日志(cluster log)和节点日志(node log)。前者记录了所有Cluster节点生成的日志,后者仅仅记录了数据节点的本地事件。在大多数情况下,一般推荐使用集群日志,因为它在一个地方记录了所有节点的数据,更方便进行管理。节点日志一般在开发过程中使用,或者用来调试程序代码。

 

clusterlog一般记录在配置文件(config.ini)所在的目录下,文件名格式为ndb_<nodeid>_cluster.log,其中nodeid为管理节点号。

 

下面是测试环境中的一段clusterlog:

 

[[email protected] mysql-cluster]# tail -n 10 ndb_1_cluster.log

 #Tablespaces: 0 #Logfilegroups: 0 #datafiles: 0 #undofiles: 0

2014-04-16 23:21:48 [MgmtSrvr] INFO     -- Node 6: Restore data: backup 3 from node 3 #Records: 3201 Data: 44814 bytes

2014-04-16 23:21:48 [MgmtSrvr] INFO     -- Node 6: Restore log: backup 3 from node 3 #Records: 0 Data: 0 bytes

2014-04-16 23:21:48 [MgmtSrvr] INFO     -- Node 6: Restore completed: backup 3 from node 3

2014-04-16 23:21:48 [MgmtSrvr] ALERT    -- Node 2: Node 6 Disconnected

2014-04-16 23:21:48 [MgmtSrvr] INFO     -- Node 2: Communication to Node 6 closed

2014-04-16 23:21:48 [MgmtSrvr] INFO     -- Node 3: Communication to Node 6 closed

2014-04-16 23:21:48 [MgmtSrvr] ALERT    -- Node 3: Node 6 Disconnected

2014-04-16 23:21:51 [MgmtSrvr] INFO     -- Node 3: Communication to Node 6 opened

2014-04-16 23:21:52 [MgmtSrvr] INFO     -- Node 2: Communication to Node 6 opened

[[email protected] mysql-cluster]#

  1. 使用ndb_mgm打开或者关闭日志

[[email protected] ~]# ndb_mgm

-- NDB Cluster -- Management Client --

ndb_mgm> clusterlog info

Connected to Management Server at: localhost:1186

Severities enabled: INFO WARNING ERROR CRITICAL ALERT

ndb_mgm>

  1. 当前日志是打开的,可以用clusterlog off命令关闭日志

ndb_mgm> clusterlog off

Cluster logging is disabled

ndb_mgm>

  1. 查看日志状态发现已关闭

ndb_mgm> clusterlog info

Cluster logging is disabled.

ndb_mgm>

  1. 执行命令clusterlog on将日志打开

ndb_mgm> clusterlog on

Cluster logging is enabled.

ndb_mgm> clusterlog info

Severities enabled: INFO WARNING ERROR CRITICAL ALERT

ndb_mgm>

  1. 日志类型

cluster中的日志有很多类型,可以按照如下类别进行过滤,使得日志只记录我们关心的信息。

 

(1)Category(类别):可以是STARTUP,SHUTDOWN,STATISTICS,CHECKPOINT,NODERESTART,CONNECTION,ERROR或者INFO中的任意值。具体的信息大家可以查阅mysql相关文档。

 

(2)Priority(优先级):由从1-15的数字表示,1表示最重要,而15表示最不重要。每种Category都有一个 默认的优先级阀值,如下面所示,优先级阀值以下的日志将被记录,反之,优先级阀值以上的日志将不会被记录。

 

类别            默认阀值(所有数据节点)

STARTUP                 7

SHUTDOWN                7

STATISTICS              7

CHECKPOINT              7

NODERESTART             7

CONNECTION              7

ERROR                   15

INFO                    7

(3)Severity Level(严重级别):可以是下面的值之一,ALERT,CRITICAL,ERROR,WARNING,INFO或DEBUG。这些值的含义如下:

 

严重级别                        事件定义

ALERT                   应立刻更正的情况,如损坏的系统数据库

CRITICAL                临界状况,如设备错误或资源不足

ERROR                   应予以更正的状况,如配置错误

WARNING                 不能称为错误的情况,但仍需要特别处理

INFO                    通报性信息

DEBUG                   调试信息,用于NDB Cluster开发

 

这3种分类可以让我们从3个不同的角度来对日志进行过滤。过滤的方法可以用ndb_mgm工具来完成,具体设置方法如下。

 

(1)node_id CLUSTERLOG category=threshold:用于小于等于threshold的优先级将category事件记录到cluster日志。node_id可以为ALL(所有节点)。或者只指定某个节点。

 

(2)CLUSTERLOG TOGGLE severity_level:使得指定的severity_level打开或者关闭。

 

例如,要将测试环境中的节点2的STARTUP事件只记录级别为3以下的日志,可以进入ndb_mgm后执行命令:

 

ndb_mgm> 2 clusterlog startup=3

Executing CLUSTERLOG STARTUP=3 on node 2 OK!

 

ndb_mgm>

如果要在cluster中过滤掉DEBUG和INFO信息,可以执行如下命令:

 

ndb_mgm> clusterlog toggle debug info

DEBUG enabled

INFO disabled

ndb_mgm>

 

然后查看日志状态,发现DEBUG和INFO信息已经不存在了。

ndb_mgm> clusterlog info

Severities enabled: DEBUG WARNING ERROR CRITICAL ALERT

ndb_mgm>

  1. 查看集群备份,内存,事件日志信息
  1. 查看正在进行的备份状态

ndb_mgm> ALL REPORT BACKUP;

Node 2: Backup not started

Node 3: Backup not started

  1. 查看数据内存和索引内存使用情况

ndb_mgm> ALL REPORT MEMORY

Node 2: Data usage is 1%(31 32K pages of total 2560)

Node 2: Index usage is 1%(26 8K pages of total 2336)

Node 3: Data usage is 1%(31 32K pages of total 2560)

Node 3: Index usage is 1%(26 8K pages of total 2336)

  1. 查看事件日志

ndb_mgm> ALL REPORT EVENT;

2017-12-14 09:59:44 Node 2: Communication to Node 3 opened

2017-12-14 10:01:15 Node 2: create object id: 2 version: 1 (from 2)

2017-12-14 10:01:15 Node 2: create object id: 3 version: 1 (from 2)

2017-12-14 10:01:15 Node 2: create object id: 4 version: 1 (from 2)

2017-12-14 10:01:15 Node 2: create object id: 5 version: 1 (from 2)

2017-12-14 10:01:15 Node 2: create object id: 6 version: 1 (from 2)

2017-12-14 10:01:15 Node 2: create object id: 7 version: 1 (from 2)

2017-12-14 10:01:15 Node 2: create object id: 9 version: 1 (from 2)

2017-12-14 10:01:15 Node 2: create object id: 10 version: 3 (from 2)

2017-12-14 10:01:15 Node 2: create object id: 8 version: 1 (from 2)

2017-12-14 10:01:15 Node 2: Log part: 3 phase: 0 run redo from  gci: 6397 (file: 0 mb: 0) to  gci: 6936 (file: 0 mb: 0)

2017-12-14 10:01:15 Node 2: Log part: 3 phase: 0 found stop  gci: 6936 (file: 0 mb: 0)

2017-12-14 10:01:15 Node 2: Log part: 1 phase: 0 found stop  gci: 6936 (file: 0 mb: 0)

2017-12-14 10:01:15 Node 2: Log part: 2 phase: 0 found stop  gci: 6936 (file: 0 mb: 0)

2017-12-14 10:01:16 Node 2: Log part: 0 phase: 0 found stop  gci: 6936 (file: 0 mb: 0)

......略

  1. 在线添加数据节点

官方文档:​​https://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-online-add-node.html​

 

在线添加很明显就是不要关闭集群,或重启集群。

注意:现在,只能向一个新的节点组中加入新的数据节点,而不能向已经存在的节点组中加入新的数据节点。而且不能在线修改数据的冗余数。

  1. 在线添加数据节点的限制

1).数据的重新分布:在加入新的数据节点之后,数据的重新平衡分布是不会自动完成的,需要在SQL节点或者Mysql客户端执行SQL语句来完成,如:ALTER TABLE ... REORGANIZE PARTITION。但是在加入新的数据节点后,新插入的数据,索引会自动分布。Table reorganization of both in-memory and Disk Data tables is supported. This redistribution does not currently include unique indexes (only ordered indexes are redistributed).而且只支持Table reorganization of both in-memory and Disk Data tables。唯一性索引也不支持,只支持排序索引。

 

2).集群部分节点启动:没有启动所有新的数据节点,也可以添加一个新的节点组。

还可以将一个新的节点组添加到降级的集群中——即仅部分节点启动的集群,或者一个或多个数据节点没有运行的集群。在后一种情况下,在添加新的节点组之前,集群必须有足够的节点在运行。

 

3).对正在进行的操作影响:在创建或添加新的节点组或表(reorganization)重组的时候,正常的DML操作不会有影响。但是表(reorganization)重组不能和DDL操作同时进行,也就是在执行 ALTER TABLE ... REORGANIZE PARTITION语句时,将不能执行其他所有DDL操作。另外在执行ALTER TABLE ... REORGANIZE PARTITION语句时候,不要重启集群。

 

4).失败处理:直接贴官方文档

Failure occurs during:

Failure occurs in:

“Old” data nodes

“New” data nodes

System

Node group creation

If a node other than the master fails:  The creation of the node group is always rolled forward.

If the master fails: 

If the internal commit point has been reached: The creation of the node group is rolled forward.

If the internal commit point has not yet been reached. The creation of the node group is rolled back

If a node other than the master fails:  The creation of the node group is always rolled forward.

If the master fails: 

If the internal commit point has been reached: The creation of the node group is rolled forward.

If the internal commit point has not yet been reached. The creation of the node group is rolled back

If the execution of CREATE NODEGROUP has reached the internal commit point:  When restarted, the cluster includes the new node group. Otherwise it without.

If the execution of CREATE NODEGROUP has not yet reached the internal commit point:  When restarted, the cluster does not include the new node group.

Table reorganization

If a node other than the master fails:  The table reorganization is always rolled forward.

If the master fails: 

If the internal commit point has been reached: The table reorganization is rolled forward.

If the internal commit point has not yet been reached. The table reorganization is rolled back.

If a node other than the master fails:  The table reorganization is always rolled forward.

If the master fails:

If the internal commit point has been reached: The table reorganization is rolled forward.

If the internal commit point has not yet been reached. The table reorganization is rolled back.

If the execution of an ALTER TABLE ... REORGANIZE PARTITION statement has reached the internal commit point:  When the cluster is restarted, the data and indexes belonging to ​table​are distributed using the “new” data nodes.

 

If the execution of an ALTER TABLE ... REORGANIZE PARTITION statement has not yet reached the internal commit point:  When the cluster is restarted, the data and indexes belonging to ​table​are distributed using only the “old” data nodes.

 

5).删除节点组:只有当前节点组中的数据节点不包含任何数据的情况下才可以删除。目前没有方法清空一个数据节点或节点组中的数据。删除节点组只有下面两种情况可以进行:

  1. 在执行CREATE NODEGROUP语句之后,在ALTER TABLE ... REORGANIZE PARTITION语句之前。
  2. 使用DROP TABLE删除所有NDBCLUSTER的表之后
  1. 在线添加NDB Cluster数据节点步骤
  1. 修改配置文件config.ini

添加一个新的[ndbd]模块,nodeid不要和已经存在的节点重复。

[ndbd]

NodeId=6

HostName=NDB-DATA3  --主机名/IP

DataDir=/usr/local/mysql/data

注意:/etc/hosts文件中也要加入新的主机IP和主机名。

 

新的配置文件:

[ndbd default]

NoOfReplicas=2

DataMemory=80M

IndexMemory=18M

 

[ndb_mgmd]

NodeId=1

HostName=NDB-MGM

DataDir=/var/lib/mysql-cluster

 

[ndbd]

NodeId=2

HostName=NDB-DATA1

DataDir=/usr/local/mysql/data

 

[ndbd]

NodeId=3

HostName=NDB-DATA2

DataDir=/usr/local/mysql/data

 

[ndbd]

NodeId=4

HostName=NDB-DATA3

DataDir=/usr/local/mysql/data

 

[ndbd]

NodeId=5

HostName=NDB-DATA4

DataDir=/usr/local/mysql/data

 

[mysqld]

NodeId=10  --修改为10,方便已经扩展

HostName=NDB-SQL1

 

[mysqld]

NodeId=20  --修改为20

HostName=NDB-SQL2

 

[mysqld]

注意:

  1. NodeID一定是要有小到大,要不无法生效。这里官方文档也说明了,但是在安装部分并没有强调,导致现在添加节点就稍微麻烦了。只能重启所有节点了。而且要使用--initial参数来启动集群。
  2. 由于NoOfReplicas=2,所以新的节点组中必须至少添加两个数据节点

官方文档:

We have left a gap in the sequence between data node IDs and other nodes. This make it easier later to assign node IDs that are not already in use to data nodes which are newly added.

  1. 重启NDB Cluster管理节点

        使用--reload or --initial参数强行读取已经修改的配置文件。

  1. 查看当前集群状态

ndb_mgm> show

Cluster Configuration

---------------------

[ndbd(NDB)]    2 node(s)

id=2 @192.168.1.123  (mysql-5.7.20 ndb-7.5.8, Nodegroup: 0)

id=3 @192.168.1.124  (mysql-5.7.20 ndb-7.5.8, Nodegroup: 0, *)

 

[ndb_mgmd(MGM)]        1 node(s)

id=1 @192.168.1.120  (mysql-5.7.20 ndb-7.5.8)

 

[mysqld(API)]  3 node(s)

id=4 @192.168.1.121  (mysql-5.7.20 ndb-7.5.8)

id=5 @192.168.1.122  (mysql-5.7.20 ndb-7.5.8)

id=6 (not connected, accepting connect from any host)

  1. 关闭管理节点

ndb_mgm> 1 stop;

Node 1 has shutdown.

Disconnecting to allow Management Server to shutdown

关闭管理节点不会对SQL节点上的操作造成影响。

SQL节点读取数据正常:

mysql> select * from sihong;

+------+-----------+

| id   | name      |

+------+-----------+

|    3 | dongsheng |

|    2 | wenqing   |

|    1 | ruyan     |

|    4 | dongsheng |

+------+-----------+

4 rows in set (0.05 sec)

  1. 重新加载配置启动管理节点

[root@NDB-MGM mysql-cluster]# ndb_mgmd -f config.ini --reload

MySQL Cluster Management Server mysql-5.7.20 ndb-7.5.8

  1. 查看集群状态

[root@NDB-MGM mysql-cluster]# ndb_mgm

-- NDB Cluster -- Management Client --

ndb_mgm> show

Cluster Configuration

---------------------

[ndbd(NDB)]    4 node(s)

id=2 @192.168.1.123  (mysql-5.7.20 ndb-7.5.8, Nodegroup: 0)

id=3 @192.168.1.124  (mysql-5.7.20 ndb-7.5.8, Nodegroup: 0, *)

id=4 (not connected, accepting connect from NDB-DATA3)

id=5 (not connected, accepting connect from NDB-DATA4)

 

[ndb_mgmd(MGM)]        1 node(s)

id=1 @192.168.1.120  (mysql-5.7.20 ndb-7.5.8)

 

[mysqld(API)]  3 node(s)

id=10        @192.168.1.121  (mysql-5.7.20 ndb-7.5.8)

id=20        @192.168.1.122  (mysql-5.7.20 ndb-7.5.8)

id=21 (not connected, accepting connect from any host)

  1. 滚动重启之前的数据节点

#重启nodeid是2的数据节点1,一定要等待重启完成,再重启另外的数据节点。

ndb_mgm> 2 restart;

Node 2: Node shutdown initiated

Node 2: Node shutdown completed, restarting, no start.

Node 2 is being restarted

 

ndb_mgm> Node 2: Start initiated (version 7.5.8)

Node 2: Started (version 7.5.8)

 

#重启nodeid是3的数据节点2

ndb_mgm> 3 restart;

Node 3: Node shutdown initiated

Node 3: Node shutdown completed, restarting, no start.

Node 3 is being restarted

 

ndb_mgm> Node 3: Start initiated (version 7.5.8)

Node 3: Started (version 7.5.8)

  1. 滚动重启SQL计算节点

分别到每个SQL节点执行重启mysql服务即可。一台一台重启,千万不能同时重启。

#重启SQL节点1

[root@NDB-SQL1 mysql]# bin/mysqladmin -uroot -pcndba shutdown

mysqladmin: [Warning] Using a password on the command line interface can be insecure.

 

[root@NDB-SQL1 mysql]# bin/mysqld_safe --ndbcluster --ndb-connectstring=192.168.1.120 &

[1] 4770

[root@NDB-SQL1 mysql]# 2017-12-14T06:28:47.898530Z mysqld_safe Logging to '/usr/local/mysql/data/NDB-SQL1.err'.

2017-12-14T06:28:47.930825Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

 

#重启SQL节点2

[root@NDB-SQL2 mysql]# bin/mysqladmin -uroot -pcndba shutdown

mysqladmin: [Warning] Using a password on the command line interface can be insecure.

 

[root@NDB-SQL2 mysql]# bin/mysqld_safe --ndbcluster --ndb-connectstring=192.168.1.120 &

[1] 4770

[root@NDB-SQL1 mysql]# 2017-12-14T06:28:47.898530Z mysqld_safe Logging to '/usr/local/mysql/data/NDB-SQL1.err'.

2017-12-14T06:28:47.930825Z mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

注意:只能通过这种方式来关闭和打开mysql服务。不能通过其他方式来重启。

  1. (可选,代替5.2.3和5.2.4)-不用滚动重启数据节点和SQL节点
  1. 配置文件有所不同
在每个数据节点的模块中加入“Nodegroup = 65536 ”

[ndbd]

NodeId=4

HostName=NDB-DATA3

DataDir=/usr/local/mysql/data

Nodegroup = 65536

 

[ndbd]

NodeId=5

HostName=NDB-DATA4

DataDir=/usr/local/mysql/data

Nodegroup = 65536

 

通过Nodegroup = 65536 参数,会将数据节点online。
  1. 初始化启动新的数据节点

#数据节点3(192.168.1.125)

[root@NDB-DATA3 ~]# ndbd -c 192.168.1.120 --initial

2017-12-14 14:31:19 [ndbd] INFO     -- Angel connected to '192.168.1.120:1186'

2017-12-14 14:31:19 [ndbd] INFO     -- Angel allocated nodeid: 4

#数据节点4(192.168.1.126)

[root@NDB-DATA4 ~]# ndbd -c 192.168.1.120 --initial

2017-12-14 14:31:50 [ndbd] INFO     -- Angel connected to '192.168.1.120:1186'

2017-12-14 14:31:50 [ndbd] INFO     -- Angel allocated nodeid: 5

  1. 查看集群状态

ndb_mgm> show

Cluster Configuration

---------------------

[ndbd(NDB)]    4 node(s)

id=2 @192.168.1.123  (mysql-5.7.20 ndb-7.5.8, Nodegroup: 0, *)

id=3 @192.168.1.124  (mysql-5.7.20 ndb-7.5.8, Nodegroup: 0)

id=4 @192.168.1.125  (mysql-5.7.20 ndb-7.5.8, no nodegroup)  --可以看到是 no nodegroup,不属于之前的节点组。

id=5 @192.168.1.126  (mysql-5.7.20 ndb-7.5.8, no nodegroup)

 

[ndb_mgmd(MGM)]        1 node(s)

id=1 @192.168.1.120  (mysql-5.7.20 ndb-7.5.8)

 

[mysqld(API)]  3 node(s)

id=10        @192.168.1.121  (mysql-5.7.20 ndb-7.5.8)

id=20        @192.168.1.122  (mysql-5.7.20 ndb-7.5.8)

id=21 (not connected, accepting connect from any host)

  1. 创建新的节点组

ndb_mgm> CREATE NODEGROUP 4,5  --表示nodeid4,5加入到新的节点组中。

Nodegroup 1 created

  1. 再次查看集群状态

ndb_mgm> show

Cluster Configuration

---------------------

[ndbd(NDB)]    4 node(s)

id=2 @192.168.1.123  (mysql-5.7.20 ndb-7.5.8, Nodegroup: 0, *)

id=3 @192.168.1.124  (mysql-5.7.20 ndb-7.5.8, Nodegroup: 0)

id=4 @192.168.1.125  (mysql-5.7.20 ndb-7.5.8, Nodegroup: 1)  --可以看到加入到节点组1中。

id=5 @192.168.1.126  (mysql-5.7.20 ndb-7.5.8, Nodegroup: 1)

 

[ndb_mgmd(MGM)]        1 node(s)

id=1 @192.168.1.120  (mysql-5.7.20 ndb-7.5.8)

 

[mysqld(API)]  3 node(s)

id=10        @192.168.1.121  (mysql-5.7.20 ndb-7.5.8)

id=20        @192.168.1.122  (mysql-5.7.20 ndb-7.5.8)

id=21 (not connected, accepting connect from any host)

  1. 重新分布集群数据
  1. 查看当前数据节点的空间使用情况

ndb_mgm> ALL REPORT MEMORY

Node 2: Data usage is 1%(31 32K pages of total 2560)

Node 2: Index usage is 1%(26 8K pages of total 2336)

Node 3: Data usage is 1%(31 32K pages of total 2560)

Node 3: Index usage is 1%(26 8K pages of total 2336)

Node 4: Data usage is 0%(16 32K pages of total 2560)

Node 4: Index usage is 0%(0 8K pages of total 2336)

Node 5: Data usage is 0%(16 32K pages of total 2560)

Node 5: Index usage is 0%(0 8K pages of total 2336)  --可以看到数据节点4,5使用0%,表示没有数据。

  1. ndb_desc查看当前数据分布情况

语法:

  1. ndb_desc -c connection_string tbl_name -d db_name [options]
  2. ndb_desc -c connection_string index_name -d db_name -t tbl_name

[root@NDB-DATA1 ~]# ndb_desc -c 192.168.1.120 sihong -d cndba -p

-- sihong --

Version: 3

Fragment type: HashMapPartition

K Value: 6

Min load factor: 78

Max load factor: 80

Temporary table: no

Number of attributes: 3

Number of primary keys: 1

Length of frm data: 231

Max Rows: 0

Row Checksum: 1

Row GCI: 1

SingleUserMode: 0

ForceVarPart: 1

PartitionCount: 2

FragmentCount: 2

PartitionBalance: FOR_RP_BY_LDM

ExtraRowGciBits: 0

ExtraRowAuthorBits: 0

TableStatus: Retrieved

Table options:

HashMap: DEFAULT-HASHMAP-3840-2

-- Attributes --

id Int NULL AT=FIXED ST=MEMORY

name Varchar(50;latin1_swedish_ci) NULL AT=SHORT_VAR ST=MEMORY

$PK Bigunsigned PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR

-- Indexes --

PRIMARY KEY($PK) - UniqueHashIndex

-- Per partition info --

Partition

0

1

可以看到只有两个分区上有数据,新加的两个数据节点上没有数据。

  1. ALTER TABLE来重新分布表数据

mysql> ALTER TABLE sihong ALGORITHM=INPLACE, REORGANIZE PARTITION;

Query OK, 0 rows affected (7.98 sec)

Records: 0  Duplicates: 0  Warnings: 0

  1. 查看数据的分布情况

[root@NDB-DATA1 ~]# ndb_desc -c 192.168.1.120 sihong -d cndba -p

-- sihong --

Version: 16777219

Fragment type: HashMapPartition

K Value: 6

Min load factor: 78

Max load factor: 80

Temporary table: no

Number of attributes: 3

Number of primary keys: 1

Length of frm data: 231

Max Rows: 0

Row Checksum: 1

Row GCI: 1

SingleUserMode: 0

ForceVarPart: 1

PartitionCount: 4

FragmentCount: 4

PartitionBalance: FOR_RP_BY_LDM

ExtraRowGciBits: 0

ExtraRowAuthorBits: 0

TableStatus: Retrieved

Table options:

HashMap: DEFAULT-HASHMAP-3840-4

-- Attributes --

id Int NULL AT=FIXED ST=MEMORY

name Varchar(50;latin1_swedish_ci) NULL AT=SHORT_VAR ST=MEMORY

$PK Bigunsigned PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR

-- Indexes --

PRIMARY KEY($PK) - UniqueHashIndex

-- Per partition info --

Partition  Row count

0        1               4                    32768                   32768                        0                   0                    

2

3

 

NDBT_ProgramExit: 0 - OK

 

只看到在数据存储在三个数据节点上,分别存储1,1,2行数据。该表一共四条数据,再插入几条数据看看。

mysql> insert into sihong select * from sihong;

Query OK, 4 rows affected (0.00 sec)

Records: 4  Duplicates: 0  Warnings: 0

 

mysql> select * from sihong;

+------+-----------+

| id   | name      |

+------+-----------+

|    2 | wenqing   |

|    3 | dongsheng |

|    2 | wenqing   |

|    3 | dongsheng |

|    1 | ruyan     |

|    1 | ruyan     |

|    4 | dongsheng |

|    4 | dongsheng |

+------+-----------+

8 rows in set (0.04 sec)

  1. #再看数据分布

[root@NDB-DATA1 ~]# ndb_desc -c 192.168.1.120 sihong -d cndba -p

-- sihong --

Version: 16777219

Fragment type: HashMapPartition

K Value: 6

Min load factor: 78

Max load factor: 80

Temporary table: no

Number of attributes: 3

Number of primary keys: 1

Length of frm data: 231

Max Rows: 0

Row Checksum: 1

Row GCI: 1

SingleUserMode: 0

ForceVarPart: 1

PartitionCount: 4

FragmentCount: 4

PartitionBalance: FOR_RP_BY_LDM

ExtraRowGciBits: 0

ExtraRowAuthorBits: 0

TableStatus: Retrieved

Table options:

HashMap: DEFAULT-HASHMAP-3840-4

-- Attributes --

id Int NULL AT=FIXED ST=MEMORY

name Varchar(50;latin1_swedish_ci) NULL AT=SHORT_VAR ST=MEMORY

$PK Bigunsigned PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR

-- Indexes --

PRIMARY KEY($PK) - UniqueHashIndex

-- Per partition info --

Partition  Row count        Commit count Frag fixed memory  Frag varsized memory     Extent_space         Free extent_space 

0        3               6                    32768                   32768                        0                   0                    

1        1               7                    32768                   32768                        0                   0                    

2        1               1                    32768                   32768                        0                   0                    

3        3               3                    32768                   32768                        0                   0                    

NDBT_ProgramExit: 0 - OK

可以看到,四个数据节点上都有数据了。

  1. 查看所有NDNCLUSTER引擎的表

mysql> SELECT TABLE_SCHEMA, TABLE_NAME

    ->     FROM INFORMATION_SCHEMA.TABLES

    ->     WHERE ENGINE = 'NDBCLUSTER';

+--------------+-----------------------+

| TABLE_SCHEMA | TABLE_NAME            |

+--------------+-----------------------+

| cndba        | sihong                |

| mysql        | ndb_apply_status      |

| mysql        | ndb_index_stat_head   |

| mysql        | ndb_index_stat_sample |

+--------------+-----------------------+

这些表都需要执行ALERT TABLE。

  1. 问题记录
  1. 问题1

错误信息:

[root@NDB-MGM mysql-cluster]# ndb_mgmd -f config.ini --initial

MySQL Cluster Management Server mysql-5.7.20 ndb-7.5.8

2017-12-14 13:52:54 [MgmtSrvr] ERROR    -- at line 32: Nodegroup 1 has 1 members, NoOfReplicas=2

2017-12-14 13:52:54 [MgmtSrvr] ERROR    -- Could not load configuration from 'config.ini'

原因:

由于当前冗余是2,所以新的节点组中至少添加两个数据节点。

 

解决方法:

同时添加两个数据节点

  1. 问题2

错误信息:

[root@NDB-SQL1 mysql]# service mysql.server start

Starting MySQL.The server quit without updating PID file (/[FAILED]l/mysql/data/NDB-SQL1.pid).

 

原因:

/etc/hosts文件内容不一致

 

解决方法:

集群中所有节点/etc/hosts文件保持一致。

标签:Node,ndb,--,NDB,Cluster,mysql,基本操作,节点
From: https://blog.51cto.com/u_12946336/5722454

相关文章

  • ApplicationDbContext配置
    一、appsetting.json声明连接字符串"ConnectionStrings":{"DefaultConnection":"Server=DESKTOP-DABHN6U\\MSSQLSERVER2014;uid=sa;pwd=Lz38275292;database=SP......
  • mmdetection使用wandb查看训练日志
    mmdetection查看日志之前一直是在用TextLoggerHook,已经觉得挺方便的了,自从用了wandb之后,发现wandb真不错,看log更方便了,回不去了。wandb的简单配置:wandb官网:https://wandb......
  • HandBrake for Mac中文版mac视频解码器软件
    HandBrakeforMac是一款适用于Mac系统的视频解码器。用户可以使用HandBrakemac版将各种类型的DVD快速转换为MPEG,而且支持任何类似的VIDEO_TS文件夹、.VOB、.TS文件等DVD的......
  • 使用windbg查看dump和排查问题
    使用windbg查看dump和排查问题1、安装与配置windbg的symbol(符号)1)下载WinDBGhttps://dl.pconline.com.cn/download/770876.html2)双击下载的文件安装windbg......
  • django项目 admin管理后台 基本操作(表注册/中英文切换/表名展示为中文)
    登录:使用创建的超级用户才可以登录注册:告诉admin有多少张表:在admin.py文件中注册admin.py文件:表注册完成后,admin中会显示表信息1fromdjango.contribimportadmin......
  • MyBatis-Plus基本操作使用
    参考:https://www.cnblogs.com/l-y-h/p/12859477.html#_label0官方文档:https://mp.baomidou.com/一)简单了解1、简介:MyBatis-Plus(简称MP)是一个MyBatis的增强工具,在MyBa......
  • 栈的基本操作
    栈的顺序存储结构顺序栈的实现#include"iostream"#defineMaxSize50//栈的结构体structStack{intdata[MaxSize];inttop;}stack;//初始化栈voi......
  • SQL server 基本操作
     1、添加字段altertable表名add字段名typenotnulldefault02、修改字段名altertable表名 rename columnAtoB3、修改字段类型altertable表名modif......
  • MongoDB基本操作
     //返回指定字段:1表示返回,0表示不返回//默认返回_id,如果不想返回,加上_id:0//db.表名.find({条件},{返回字段:1})db.navigation_clicks.find({   "type":1},{......
  • redis的字符串String类型基本操作
    1、首先连上你的redis以下一些命令很简单,或者执行命令后效果也无法体现的就没有进行截图展示2、String相关操作-------------------设置值-------------------设置指......