mysql cluster 7.2在线添加数数据节点

本文主要是摘抄和翻译了一下官方文档,7.2是最新版本,集成mysq5.5,memcached的API。听说性能很好。因为资料不是不少,网络文档又怕有错误的地方。因此翻译了一下官方的manual。 html

在线添加数据节点大体分为如下几个步骤:node

1.       Edit the cluster configuration config.ini file, adding new [ndbd] sections corresponding to the nodes to be added. In the case where the cluster uses multiple management servers, these changes need to be made to all config.ini files used by the management servers.mysql

2.       Perform a rolling restart of all MySQL Cluster management servers. All management servers must be restarted with the --reload or --initial option to force the reading of the new configuration.sql

3.       Perform a rolling restart of all existing MySQL Cluster data nodes. It is not necessary (or usually even desirable) to use --initial when restarting the existing data nodes.  If you are using API nodes with dynamically allocated IDs matching any node IDs that you wish to assign to new data nodes, you must restart all API nodes (including SQL nodes) before restarting any of the data nodes processes in this step. This causes any API nodes with node IDs that were previously not explicitly assigned to relinquish those node IDs and acquire new ones.shell

4. Perform a rolling restart of any SQL or API nodes connected to the MySQL Cluster. 数据库

5. Perform an initial start of the new data nodes.   api

 

6. Execute one or more CREATE NODEGROUP commands in the MySQL Cluster management client to create the new node group or node groups to which the new data nodes will belong.服务器

7. Execute one or more CREATE NODEGROUP commands in the MySQL Cluster management client to create the new node group or node groups to which the new data nodes will belong.  This needs to be done only for tables already existing at the time the new node group is added. Data in tables created after the new node group is added is distributed automatically; however, data added to any given table tbl that existed before the new nodes were added is not distributed using the new nodes until that table has been reorganized using ALTER ONLINE TABLE tbl REORGANIZE PARTITION.网络

8. Reclaim the space freed on the “old” nodes by issuing, for each NDBCLUSTER table, an OPTIMIZE TABLE statement in the mysql client.多线程

 

一个例子:

假设如今的配置文件config.ini以下:

[ndbd default]
DataMemory = 100M
IndexMemory = 100M
NoOfReplicas = 2
DataDir = /usr/local/mysql/var/mysql-cluster
[ndbd]
Id = 1
HostName = 192.168.0.1
[ndbd]
Id = 2
HostName = 192.168.0.2
[mgm]
HostName = 192.168.0.10
Id = 10
[api]
Id=20
HostName = 192.168.0.2 
[api]
Id=21
HostName = 192.168.0.21

注意:咱们留下一个空白的序列在数据节点和其余节点。这样容易为新添加的数据服务器分配新的未使用的节点id

如今咱们show如下整个cluster的信息:

ndb_mgm> SHOW

 

Connected to Management Server at: 192.168.0.10:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=1    @192.168.0.1  (5.1.61-ndb-7.1.20, Nodegroup: 0, Master)
id=2    @192.168.0.2  (5.1.61-ndb-7.1.20, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=10   @192.168.0.10  (5.1.61-ndb-7.1.20)
[mysqld(API)]   2 node(s)
id=20   @192.168.0.20  (5.1.61-ndb-7.1.20)
id=21   @192.168.0.21  (5.1.61-ndb-7.1.20)

 

最终,咱们假设只有一张ndbcluster的表。

USE n;
CREATE TABLE ips (
    id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
    country_code CHAR(2) NOT NULL,
    type CHAR(4) NOT NULL,
    ip_address varchar(15) NOT NULL,
    addresses BIGINT UNSIGNED DEFAULT NULL,
    date BIGINT UNSIGNED DEFAULT NULL
)   ENGINE NDBCLUSTER;

注意:若是使用多线程的ndbmtd会出现bug(这里不知道翻译的对不对)。

 

步骤一

升级配置文件(config.ini

假设咱们新添加两个新数据节点192.168.0.3192.168.0.4

[ndbd default]
DataMemory = 100M
IndexMemory = 100M
NoOfReplicas = 2
DataDir = /usr/local/mysql/var/mysql-cluster
[ndbd]
Id = 1
HostName = 192.168.0.1
[ndbd]
Id = 2
HostName = 192.168.0.2

[ndbd]

Id = 3 

HostName = 192.168.0.3

[ndbd] 

Id = 4

HostName = 192.168.0.4
[mgm]
HostName = 192.168.0.10
Id = 10
[api]
Id=20
HostName = 192.168.0.20
[api]
Id=21
HostName = 192.168.0.21

红色字体为新添加的配置.

 

步骤二

重启管理节点

找到管理节点ID

 

ndb_mgm> 10 STOP

 

Node 10 has shut down.
Disconnecting to allow Management Server to shutdown

从新启动管理节点(使用—reload选项)

shell> 
ndb_mgmd -f config.ini --reload

如今再show一下:

ndb_mgm> SHOW

 

Connected to Management Server at: 192.168.0.10:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=1    @192.168.0.1  (5.1.61-ndb-7.1.20, Nodegroup: 0, Master)
id=2    @192.168.0.2  (5.1.61-ndb-7.1.20, Nodegroup: 0)
id=3 (not connected, accepting connect from 192.168.0.3)
id=4 (not connected, accepting connect from 192.168.0.4)
[ndb_mgmd(MGM)] 1 node(s)
id=10   @192.168.0.10  (5.1.61-ndb-7.1.20)
[mysqld(API)]   2 node(s)
id=20   @192.168.0.20  (5.1.61-ndb-7.1.20)
id=21   @192.168.0.21  (5.1.61-ndb-7.1.20)

看到新添加的节点已经被管理节点读取。

 

步骤三

对已经存在的数据节点执行环状重启

ndb_mgm> 1 RESTART

 

Node 1: Node shutdown initiated
Node 1: Node shutdown completed, restarting, no start.
Node 1 is being restarted
ndb_mgm> Node 1: Start initiated (version 7.1.20)
Node 1: Started (version 7.1.20)

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.1.20)
ndb_mgm> Node 2: Started (version 7.1.20)

注意:必定要等到管理端报告 Node X ….

 

步骤四

mysql节点执行环状重启

shell>service mysqld restart
步骤五
对新数据节点进行初始化启动

shell> 
ndbd -c 192.168.0.3 --initial

shell> 
ndbd -c 192.168.0.4 –initial
注意:这里不须要一个数据节点启动后在启动另外一个,能够同时启动
如今show一下:

ndb_mgm> SHOW

 

Connected to Management Server at: 192.168.0.10:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=1    @192.168.0.1  (5.1.61-ndb-7.1.20, Nodegroup: 0, Master)
id=2    @192.168.0.2  (5.1.61-ndb-7.1.20, Nodegroup: 0)
id=3    @192.168.0.3  (5.1.61-ndb-7.1.20, no nodegroup)
id=4    @192.168.0.4  (5.1.61-ndb-7.1.20, no nodegroup)
[ndb_mgmd(MGM)] 1 node(s)
id=10   @192.168.0.10  (5.1.61-ndb-7.1.20) 
[mysqld(API)]   2 node(s)
id=20   @192.168.0.20  (5.1.61-ndb-7.1.20)
id=21   @192.168.0.21  (5.1.61-ndb-7.1.20)
 
步骤六
为新数据节点分配新的组

ndb_mgm> CREATE NODEGROUP 3,4

 

Nodegroup 1 created
 

ndb_mgm> SHOW

 

Connected to Management Server at: 192.168.0.10:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=1    @192.168.0.1  (5.1.61-ndb-7.1.20, Nodegroup: 0, Master)
id=2    @192.168.0.2  (5.1.61-ndb-7.1.20, Nodegroup: 0)
id=3    @192.168.0.3  (5.1.61-ndb-7.1.20, Nodegroup: 1)
id=4    @192.168.0.4  (5.1.61-ndb-7.1.20, Nodegroup: 1)
[ndb_mgmd(MGM)] 1 node(s)
id=10   @192.168.0.10  (5.1.61-ndb-7.1.20) 
[mysqld(API)]   2 node(s)
id=20   @192.168.0.20  (5.1.61-ndb-7.1.20)
id=21   @192.168.0.21  (5.1.61-ndb-7.1.20)
 
步骤七
从新分配集群数据
当新加入数据节点时,已经存在的数据或者索引不会被自动分配到新的节点上,以下所示:

ndb_mgm> 
ALL REPORT MEMORY
Node 1: Data usage is 5%(177 32K pages of total 3200)
Node 1: Index usage is 0%(108 8K pages of total 12832)
Node 2: Data usage is 5%(177 32K pages of total 3200)
Node 2: Index usage is 0%(108 8K pages of total 12832)

Node 3: Data usage is 0%(0 32K pages of total 3200)

Node 3: Index usage is 0%(0 8K pages of total 12832) 

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

Node 4: Index usage is 0%(0 8K pages of total 12832)
使用ndb_desc –p 能够看到分区信息。拿上面的那张表为例,看到它仍是在使用2个分区:
 

shell> ndb_desc -c 192.168.0.10 -d n ips -p

 

-- ips --
Version: 1
Fragment type: 9
K Value: 6
Min load factor: 78
Max load factor: 80
Temporary table: no
Number of attributes: 6
Number of primary keys: 1
Length of frm data: 340
Row Checksum: 1
Row GCI: 1
SingleUserMode: 0
ForceVarPart: 1
FragmentCount: 2
TableStatus: Retrieved
-- Attributes --
id Bigint PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR
country_code Char(2;latin1_swedish_ci) NOT NULL AT=FIXED ST=MEMORY
type Char(4;latin1_swedish_ci) NOT NULL AT=FIXED ST=MEMORY
ip_address Varchar(15;latin1_swedish_ci) NOT NULL AT=SHORT_VAR ST=MEMORY
addresses Bigunsigned NULL AT=FIXED ST=MEMORY
date Bigunsigned NULL AT=FIXED ST=MEMORY
 
-- Indexes --
PRIMARY KEY(id) - UniqueHashIndex
PRIMARY(id) - OrderedIndex

-- Per partition info --

Partition   Row count   Commit count  Frag fixed memory   Frag varsized memory

0           26086       26086         1572864             557056

1           26329       26329         1605632             557056
NDBT_ProgramExit: 0 - OK
 
-c后面的地址是管理节点地址,-d后面是数据库,数据表
 
如今进行数据的从新分配
mysql节点上执行对全部的ndbcluster引擎的表:
Myql>alter online table … reorganize partition
 
如今在看一下上面那张表:

shell> ndb_desc -c 192.168.0.10 -d n ips -p

 

-- ips --
Version: 16777217
Fragment type: 9
K Value: 6
Min load factor: 78
Max load factor: 80
Temporary table: no
Number of attributes: 6
Number of primary keys: 1
Length of frm data: 341
Row Checksum: 1
Row GCI: 1
SingleUserMode: 0
ForceVarPart: 1
FragmentCount: 4
TableStatus: Retrieved
-- Attributes --
id Bigint PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCR
country_code Char(2;latin1_swedish_ci) NOT NULL AT=FIXED ST=MEMORY
type Char(4;latin1_swedish_ci) NOT NULL AT=FIXED ST=MEMORY
ip_address Varchar(15;latin1_swedish_ci) NOT NULL AT=SHORT_VAR ST=MEMORY
addresses Bigunsigned NULL AT=FIXED ST=MEMORY
date Bigunsigned NULL AT=FIXED ST=MEMORY
-- Indexes --
PRIMARY KEY(id) - UniqueHashIndex
PRIMARY(id) - OrderedInde

-- Per partition info --

Partition   Row count   Commit count  Frag fixed memory   Frag varsized memory

0           12981       52296         1572864             557056

1           13236       52515         1605632             557056

2           13105       13105         819200              294912 

3           13093       13093         819200              294912
NDBT_ProgramExit: 0 - OK
 
从新分配数据存储分区以后,常常使用 optimize table去掉浪费的空间 。
 
想获得全部使用ndbcluster引擎的表,可使用下面的查询:
Mysql>select table_schema,table_name from information_schema.tables where engine= ‘ndbcluster’;
如今使用 all report memory查看一下数据和索引的存储状况:

ndb_mgm> 
ALL REPORT MEMORY
Node 1: Data usage is 5%(176 32K pages of total 3200)
Node 1: Index usage is 0%(76 8K pages of total 12832)
Node 2: Data usage is 5%(176 32K pages of total 3200)
Node 2: Index usage is 0%(76 8K pages of total 12832)
Node 3: Data usage is 2%(80 32K pages of total 3200)
Node 3: Index usage is 0%(51 8K pages of total 12832)
Node 4: Data usage is 2%(80 32K pages of total 3200)
Node 4: Index usage is 0%(50 8K pages of total 12832)
相关文章
相关标签/搜索