Mysql Cluster水平扩展-添加数据节点

一:实验环境

 Mysql Cluster水平扩展-添加数据节点_第1张图片

 

已搭建好mysql cluster(一个管理节点,2sql节点及2个数据节点),搭建步骤请参考:http://blog.csdn.net/yabingshi_tech/article/details/47952135,现要在此基础上添加

192.168.6.70,192.168.6.71作为数据节点。(由于副本集参数已经配置成了2,所以必须一次添加2个数据节点)


二:实验步骤


2.1:解压cluster安装包


tar -xvf mysql-cluster-gpl-7.2.15-linux2.6-x86_64.tar.gz 

mv mysql-cluster-gpl-7.2.15-linux2.6-x86_64 /usr/local/mysql

 

2.2:修改管理节点配置文件

cd /data/mysql/mysql-cluster

 

修改全局配置文件vi mgmd.cnf,修改后的配置文件如下:

[ndbd default]
 
NoOfReplicas=2
 
DataMemory=80M
 
IndexMemory=18M
 
[ndb_mgmd]
 
hostname=192.168.6.66
datadir=/data/mysql/mysql-cluster
 
[ndbd]
 
hostname=192.168.6.68
 
datadir=/usr/local/mysql/data
 
[ndbd]
 
hostname=192.168.6.69
 
datadir=/usr/local/mysql/data
 
[ndbd]
 
hostname=192.168.6.70
 
datadir=/usr/local/mysql/data
 
[ndbd]
 
hostname=192.168.6.71
 
datadir=/usr/local/mysql/data
 
[mysqld]
 
hostname=192.168.6.66
 
[mysqld]
 
hostname=192.168.6.67
 

 

2.3重新启动管理节点服务

 

2.3.1 停止管理节点

 

ndb_mgm> 1 stop  

Node 1 has shutdown.  

Disconnecting to allow Management Server to shutdown  

 

--停止管理节点不影响sql节点的正常访问。

 

2.3.2 重新加载配置文件

[root@ser6-66 mysql-cluster]# ndb_mgmd -f mgmd.cnf --initial

MySQL Cluster Management Server mysql-5.5.35 ndb-7.2.15

/*

用initial或者reload参数重新加载

如果只在配置文件中新增一个数据节点,会报错:

[root@ser6-66 mysql-cluster]#  ndb_mgmd -f mgmd.cnf --initial

MySQL Cluster Management Server mysql-5.5.35 ndb-7.2.15

2015-08-18 16:18:37 [MgmtSrvr] ERROR    -- at line 38: Nodegroup 1 has 1 members, NoOfReplicas=2

2015-08-18 16:18:37 [MgmtSrvr] ERROR    -- Could not load configuration from 'mgmd.cnf'

*/

 

2.3.4 查看集群状态

 

[root@ser6-66 mysql-cluster]# ndb_mgm 192.168.6.66
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at: 192.168.6.66:1186
Cluster Configuration
---------------------
[ndbd(NDB)]4 node(s)
[email protected]  (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0)
[email protected]  (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0, *)
id=4 (not connected, accepting connect from 192.168.6.70)
id=5 (not connected, accepting connect from 192.168.6.71)
 
[ndb_mgmd(MGM)]1 node(s)
[email protected]  (mysql-5.5.35 ndb-7.2.15)
 
[mysqld(API)]2 node(s)
id=6 (not connected, accepting connect from 192.168.6.66)
id=7 (not connected, accepting connect from 192.168.6.67)


发现我的两个sql节点not connect了,网上别人的都没断啊。以保万一,这个还是晚上访问量比较少的时候添数据节点加比较好。


2.4:修改配置文件/etc/my.cnf

192.168.6.70,192.168.6.71

编辑/etc/my.cnf

内容如下:

[mysqld]
ndbcluster                          #运行NDB存储引擎
ndb-connectstring=192.168.6.66    #定位管理节点
[mysql_cluster]
ndb-connectstring=192.168.6.66    #定位管理节点


2.5轮流重新启动已连接的数据节点

ndb_mgm> 2 stop
Node 2: Node shutdown initiated
Node 2: Node shutdown completed.
Node 2 has shutdown.

[root@ser6-68 ~]# /usr/local/mysql/bin/ndbd   --ndb-connectstring=192.168.6.66
2015-08-18 16:56:31 [ndbd] INFO     -- Angel connected to '192.168.6.66:1186'
2015-08-18 16:56:31 [ndbd] INFO     -- Angel allocated nodeid: 2
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]4 node(s)
[email protected]  (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0)
[email protected]  (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0, *)
id=4 (not connected, accepting connect from 192.168.6.70)
id=5 (not connected, accepting connect from 192.168.6.71)
 
[ndb_mgmd(MGM)]1 node(s)
[email protected]  (mysql-5.5.35 ndb-7.2.15)
 
[mysqld(API)]3 node(s)
[email protected]  (mysql-5.5.35 ndb-7.2.15)
id=7 (not connected, accepting connect from 192.168.6.67)
id=8 (not connected, accepting connect from any host)
--发现sql节点也起来了一个。
ndb_mgm> 3 stop
Node 3: Node shutdown initiated
Node 3: Node shutdown completed.
Node 3 has shutdown.
[root@ser6-69 download]# /usr/local/mysql/bin/ndbd   --ndb-connectstring=192.168.6.66
2015-08-18 16:57:54 [ndbd] INFO     -- Angel connected to '192.168.6.66:1186'
2015-08-18 16:57:54 [ndbd] INFO     -- Angel allocated nodeid: 3
 
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]	4 node(s)
id=2	@192.168.6.68  (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0, *)
id=3	@192.168.6.69  (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0)
id=4 (not connected, accepting connect from 192.168.6.70)
id=5 (not connected, accepting connect from 192.168.6.71)
 
[ndb_mgmd(MGM)]	1 node(s)
id=1	@192.168.6.66  (mysql-5.5.35 ndb-7.2.15)
 
[mysqld(API)]	3 node(s)
id=6	@192.168.6.66  (mysql-5.5.35 ndb-7.2.15)
id=7	@192.168.6.67  (mysql-5.5.35 ndb-7.2.15)
id=8 (not connected, accepting connect from any host)
 
此时发现id=7的sql节点也自动连接上了。

 

2.6轮流重新启动连接的sql节点

service mysql restart
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]4 node(s)
[email protected]  (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0, *)
[email protected]  (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0)
id=4 (not connected, accepting connect from 192.168.6.70)
id=5 (not connected, accepting connect from 192.168.6.71)
 
[ndb_mgmd(MGM)]1 node(s)
[email protected]  (mysql-5.5.35 ndb-7.2.15)
 
[mysqld(API)]3 node(s)
id=6 (not connected, accepting connect from 192.168.6.66)
[email protected]  (mysql-5.5.35 ndb-7.2.15)
[email protected]  (mysql-5.5.35 ndb-7.2.15)

 

2.7初始化新的数据节点

在192.168.6.70,192.168.6.71上分别:
 /usr/local/mysql/bin/ndbd  --initial --ndb-connectstring=192.168.6.66
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]4 node(s)
[email protected]  (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0, *)
[email protected]  (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0)
[email protected]  (mysql-5.5.35 ndb-7.2.15, no nodegroup)
[email protected]  (mysql-5.5.35 ndb-7.2.15, no nodegroup)
 
[ndb_mgmd(MGM)]1 node(s)
[email protected]  (mysql-5.5.35 ndb-7.2.15)
 
[mysqld(API)]3 node(s)
id=6 (not connected, accepting connect from 192.168.6.66)
[email protected]  (mysql-5.5.35 ndb-7.2.15)
[email protected]  (mysql-5.5.35 ndb-7.2.15)
/*
mycluster 中没有参数设置节点组数. 节点组数=节点数/NoOfReplicas.
所以你如果总共有两个数据节点,如果NoOfReplicas设为2, 那么意味着只有一个节点组. 如果NoOfReplicas=1,那么就有两个节点组。
*/
 
ndb_mgm> CREATE NODEGROUP 4,5
Nodegroup 1 created
 
这个数字不是随意设置的,是指你要添加哪些node到nodegroup中,这里是id=4,id=5的数据节点。
 
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]4 node(s)
[email protected]  (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0, *)
[email protected]  (mysql-5.5.35 ndb-7.2.15, Nodegroup: 0)
[email protected]  (mysql-5.5.35 ndb-7.2.15, Nodegroup: 1)
[email protected]  (mysql-5.5.35 ndb-7.2.15, Nodegroup: 1)
 
[ndb_mgmd(MGM)]1 node(s)
[email protected]  (mysql-5.5.35 ndb-7.2.15)
 
[mysqld(API)]3 node(s)
id=6 (not connected, accepting connect from 192.168.6.66)
[email protected]  (mysql-5.5.35 ndb-7.2.15)
[email protected]  (mysql-5.5.35 ndb-7.2.15)
 
mysql> ALTER ONLINE TABLE t2 REORGANIZE PARTITION;
Query OK, 0 rows affected (7.99 sec)
Records: 0  Duplicates: 0  Warnings: 0
 
mysql> select partition_name,table_rows from information_schema.PARTITIONS where     table_name='t2' and table_schema='dba';
+----------------+------------+
| partition_name | table_rows |
+----------------+------------+
| p0             |          3 |
| p1             |          0 |
| p2             |          1 |
| p3             |          2 |
+----------------+------------+
4 rows in set (0.02 sec)


原先t2分布在p0,p1,现在也能分布在p2,p3啦。成功啦!嘎嘎!

 

注意:如果配置过程中出现问题,记得将防火墙给关闭。

 /*

以下是我在配置过程中遇到的问题:

ndb_mgm>  create nodegroup 6,7

*   110: Error

*        Time out talking to management server


mysql> ALTER ONLINE TABLE t2 REORGANIZE PARTITION;

ERROR 1297 (HY000): Got temporary error 711 'System busy with node restart, schema operations not allowed' from NDBCLUSTER


出错原因:192.168.6.70,192.168.6.71的防火墙处于开启状态

解决办法:关闭防火墙

*/

本篇文章参考:

http://blog.csdn.net/chengfei112233/article/details/7706275

 


 

你可能感兴趣的:(Mysql Cluster水平扩展-添加数据节点)