MySQL Cluster (五) --- 动态增加数据节点配置步骤

系统:Centos6.1
mysql软件: mysql-cluster-gpl-7.2.6-linux2.6-x86_64.tar.gz

集群具体配置请参考前一篇文章  3台机器搭建集群环境


一. 原始集群配置如下
(3台机器)

管理节点:192.168.6.134
数据节点1192.168.6.135
数据节点2192.168.6.136
sql节点1:192.168.6.135
sql节点2:192.168.6.136

我使用3台机器进行配置,其中两台机器上的数据节点与sql节点在一起

现在需要动态添加二台 
数据节点3:192.168.6.137
数据节点4:192.168.6.132

原始 管理节点(192.168.6.134)配置如下:
vi /var/lib/mysql-cluster/config.ini
[ndbd default]
NoOfReplicas=2
DataMemory=80M
IndexMemory=18M
[ndb_mgmd]
NodeId=1
Hostname=192.168.6.134
datadir=/usr/local/mysql/logs
[ndbd]
NodeId=2
Hostname=192.168.6.135
datadir=/usr/local/mysql/data/
[ndbd]
NodeId=3
Hostname=192.168.6.136
datadir=/usr/local/mysql/data/
[MYSQLD]
[MYSQLD]

查看管理节点状态
shell> /usr/local/mysql/bin/ndb_mgm
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.6.135  (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0, Master)
id=3    @192.168.6.136  (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.6.134  (mysql-5.5.22 ndb-7.2.6)

[mysqld(API)]   2 node(s)
id=4    @192.168.6.135  (mysql-5.5.22 ndb-7.2.6)
id=5    @192.168.6.136  (mysql-5.5.22 ndb-7.2.6)


二. 进行动态添加节点

第一步:更新管理节点config.ini配置文件
[ndbd default]
NoOfReplicas=2
DataMemory=80M
IndexMemory=18M
[ndb_mgmd]
NodeId=1
Hostname=192.168.6.134
datadir=/usr/local/mysql/logs
[ndbd]
NodeId=2
Hostname=192.168.6.135
datadir=/usr/local/mysql/data/
[ndbd]
NodeId=3
Hostname=192.168.6.136
datadir=/usr/local/mysql/data/
[ndbd]
NodeId=4
Hostname=192.168.6.137
datadir=/usr/local/mysql/data/
[ndbd]
NodeId=5
Hostname=192.168.6.132
datadir=/usr/local/mysql/data/
[MYSQLD]
NodeId=10
Hostname=192.168.6.135
[MYSQLD]
NodeId=11
Hostname=192.168.6.136


第二步:重新启动管理节点服务

1. 停止管理节点
ndb_mgm> 1 stop
Node 1 has shutdown.
Disconnecting to allow Management Server to shutdown

2. 重新加载配置文件
shell> /usr/local/mysql/bin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini --reload
MySQL Cluster Management Server mysql-5.5.22 ndb-7.2.6

3. 查看集群状态
ndb_mgm> show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     4 node(s)
id=2    @192.168.6.135  (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0, Master)
id=3    @192.168.6.136  (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0)
id=4 (not connected, accepting connect from 192.168.6.137)
id=5 (not connected, accepting connect from 192.168.6.132)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.6.134  (mysql-5.5.22 ndb-7.2.6)

[mysqld(API)]   2 node(s)
id=10   @192.168.6.135  (mysql-5.5.22 ndb-7.2.6)
id=11   @192.168.6.136  (mysql-5.5.22 ndb-7.2.6)

第三步:轮流重新启动连接的数据节点
在ndg_mgm(192.168.6.134)控制台
重启节点2
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: Started (version 7.2.6)

重启节点3
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: Started (version 7.2.6)

第四步:轮流重新启动连接的数据节点
在192.168.6.135与192.168.6.136
shell> service mysqld restart

第五步:初始化新的数据节点
在新增的数据节点上192.168.6.137和192.168.6.132上执行安装启动操作,安装步骤,详见上一篇文章
启动数据节点
shell> /usr/local/mysql/bin/ndbd -c 192.168.6.134 --initial

登陆管理节点查看集群状态
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]     4 node(s)
id=2    @192.168.6.135  (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0, Master)
id=3    @192.168.6.136  (mysql-5.5.22 ndb-7.2.6, Nodegroup: 0)
id=4    @192.168.6.137  (mysql-5.5.22 ndb-7.2.6, starting, no nodegroup)  //这两个是新添加的,no nodegroup
id=5    @192.168.6.132  (mysql-5.5.22 ndb-7.2.6, starting, no nodegroup)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.6.134  (mysql-5.5.22 ndb-7.2.6)

[mysqld(API)]   2 node(s)
id=10   @192.168.6.135  (mysql-5.5.22 ndb-7.2.6)
id=11   @192.168.6.136  (mysql-5.5.22 ndb-7.2.6)

第六步: 创建一个新的节点组
ndb_mgm>CREATE NODEGROUP 4,5
Nodegroup 1 created

第七步: 数据重新分配
对于新增的数据节点一些访问量较高的数据和比较重要的数据需要从新分配。

分发数据命令:

Alter online table ips reorganize partition;

查看数据的分配情况:

ndb_mgm>ALL REPORT MEMORY



参考:  http://dev.mysql.com/doc/mysql-cluster-excerpt/5.1/en/mysql-cluster-online-add-node-example.html

你可能感兴趣的:(mysql,server,集群,shell,centos,api)