Home > Database > Mysql Tutorial > body text

Mysql集群添加节点水平扩展

WBOY
Release: 2016-06-07 15:33:56
Original
1404 people have browsed it

参考:http://dev.mysql.com/doc/refman/5.6/en/mysql-cluster-online-add-node-example.html 本机为管理节点ip为10.135.10.225,在单机管理节点,ndb 数据节点和 mysql 节点启动且运行成功的基础上,在数据库中添加一个引擎为 ndbcluster 类型的表 b_contac

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

        本机为管理节点ip为10.135.10.225,在单机管理节点,ndb数据节点和mysql节点启动且运行成功的基础上,在数据库中添加一个引擎为ndbcluster类型的表b_contact,并向表中插入10条测试数据。下面为在此基础上水平扩展一个节点,已知该节点ip10.135.10.51

1.       修改本机管理节点的config.ini配置文件 ,添加如下一段:

[ndbd default]

NoOfReplicas=1

 

[ndb_mgmd]

NodeId=1

HostName=10.135.10.225

DataDir=c:\cluster\data

 

[mysqld]

NodeId=11

HostName=10.135.10.51

 

[mysqld]

NodeId=12

HostName=10.135.10.225

 

[ndbd]

NodeId=21

HostName=10.135.10.51

DataDir=c:\cluster\ndbdata

 

[ndbd]

NodeId=22

HostName=10.135.10.225

DataDir=c:\cluster\ndbdata

2.       重启管理节点:

ndb_mgm> <strong>1 STOP</strong>
Copy after login

Node 1 has shut down.

Disconnecting to allow Management Server to shutdown

 

shell> ndb_mgmd.exe--config-file=c:\cluster\config.ini --configdir=c:\cluster –reload

3.       查看管理节点是否重启成功:

ndb_mgm> <code><strong>SHOW</strong></code>
Copy after login
Copy after login
Copy after login
Connected to Management Server at: 10.135.10.225:1186
Copy after login
Copy after login
Copy after login
Cluster Configuration
Copy after login
Copy after login
Copy after login
---------------------
Copy after login
Copy after login
Copy after login
[ndbd(NDB)]     2 node(s)
Copy after login
Copy after login
Copy after login
id=22    @10.135.10.225  (5.6.20-ndb-7.3.7, Nodegroup: 0, *)
Copy after login
Copy after login
Copy after login
id=21 (not connected, accepting connect from 10.135.10.51)
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
[ndb_mgmd(MGM)] 1 node(s)
Copy after login
Copy after login
Copy after login
id=1    @10.135.10.225  (5.6.20-ndb-7.3.7)
Copy after login
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
[mysqld(API)]   2 node(s)
Copy after login
Copy after login
Copy after login
id=12   @10.135.10.225  (5.6.20-ndb-7.3.7)
Copy after login
Copy after login
Copy after login

如果下面有显示各节点状态表明重启成功。

4.       重启数据节点和mysql节点:

ndb_mgm> <code><strong>22 RESTART -f</strong></code>
Copy after login
Node 22: Node shutdown initiated
Copy after login
Node 22: Node shutdown completed, restarting, no start.
Copy after login
Node 22 is being restarted
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
ndb_mgm> Node 22: Start initiated (version 7.3.7)
Copy after login
Node 22: Started (version 7.1.33)
Copy after login

 

shell>net stop mysql;

 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login

shell>net start mysql;

5.       启动新增的数据节点和mysql节点:

以下操作是在新增节点10.135.10.51上进行的。

shell> <code><strong>ndbd -c </strong></code>10.135.10.225<code></code><code>–</code><code>–</code><span>initial</span>
Copy after login
<code><strong> </strong></code>
Copy after login
shell> net start mysql;
Copy after login

 

6.       查看新增节点是否启动成功:

ndb_mgm> <code><strong>SHOW</strong></code>
Copy after login
Copy after login
Copy after login
Connected to Management Server at: 10.135.10.225:1186
Copy after login
Copy after login
Copy after login
Cluster Configuration
Copy after login
Copy after login
Copy after login
---------------------
Copy after login
Copy after login
Copy after login
[ndbd(NDB)]     2 node(s)
Copy after login
Copy after login
Copy after login
id=22    @10.135.10.225  (5.6.20-ndb-7.3.7, Nodegroup: 0, *)
Copy after login
Copy after login
Copy after login
id=21    @10.135.10.51  (5.6.20-ndb-7.3.7, <strong><em><span>no nodegroup</span></em></strong>)
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
[ndb_mgmd(MGM)] 1 node(s)
Copy after login
Copy after login
Copy after login
id=1    @10.135.10.225  (5.6.20-ndb-7.3.7)
Copy after login
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
[mysqld(API)]   2 node(s)
Copy after login
Copy after login
Copy after login
id=12   @10.135.10.225  (5.6.20-ndb-7.3.7)
Copy after login
Copy after login
Copy after login
id=11   @10.135.10.51  (5.6.20-ndb-7.3.7)
Copy after login
Copy after login

         如上id=21行显示即为添加成功。

7.       将新增节点添加到新分组并查看是否添加成功:

ndb_mgm> <code><strong>CREATE NODEGROUP 21</strong></code>
Copy after login
Nodegroup 1 created
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
ndb_mgm> <code><strong>SHOW</strong></code>
Copy after login
Copy after login
Copy after login
Connected to Management Server at: 10.135.10.225:1186
Copy after login
Copy after login
Copy after login
Cluster Configuration
Copy after login
Copy after login
Copy after login
---------------------
Copy after login
Copy after login
Copy after login
[ndbd(NDB)]     2 node(s)
Copy after login
Copy after login
Copy after login
id=22    @10.135.10.225  (5.6.20-ndb-7.3.7, Nodegroup: 0, *)
Copy after login
Copy after login
Copy after login
id=21    @10.135.10.51  (5.6.20-ndb-7.3.7, Nodegroup: 1 )
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
[ndb_mgmd(MGM)] 1 node(s)
Copy after login
Copy after login
Copy after login
id=1    @10.135.10.225  (5.6.20-ndb-7.3.7)
Copy after login
Copy after login
Copy after login
 
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
Copy after login
[mysqld(API)]   2 node(s)
Copy after login
Copy after login
Copy after login
id=12   @10.135.10.225  (5.6.20-ndb-7.3.7)
Copy after login
Copy after login
Copy after login
id=11   @10.135.10.51  (5.6.20-ndb-7.3.7)
Copy after login
Copy after login

 

8.       查看和重分配数据:

         Mysql集群添加节点水平扩展

可见新增节点尚未为分配数据。在数据库中输入如下命令并运行:

        Mysql集群添加节点水平扩展

运行后的结果如下图:

Mysql集群添加节点水平扩展

         如图可知数据迁移之后空间还没有释放出来,需要通过optimize命令优化表,释放迁移走的空间(当optimize一个ndb大表的时候很慢,很容易出问题)。

         在数据库中输入优化命令,优化后结果如下图:

        Mysql集群添加节点水平扩展

         可知部分数据已经迁移到新增的21节点上了。


9.  集群使用中遇到的问题以及解决的方法

1.       在未给要查询字段设置索引的情况下,使用mysql集群进行查改删的操作时,即使是100w数据的情况下,进行并发操作都会报如下错误:“ERROR 1205 (HY000): Lock wait timeout exceeded; try restartingtransaction” ——“锁等待超时”,且数据量越大,并发数越多报错的线程数也越多。但是单次执行以上操作时不会出现这种错误。在尝试将集群配置”TransactionDeadLockDetectionTimeOut” ——事务锁监测超时时间,修改增大到10秒后,报错情况有所改善但不明显。最后,在要查询字段name上建立了索引,才最终解决了这个问题。


2.       在添加第四个节点组进行到最后一步——向节点组四上迁移数据的时候,报了一个错误——“[Err] 1297 - Got temporary error 410 'REDO log files overloaded (decreaseTimeBetweenLocalCheckpoints or increase NoOfFragmentLogFiles)”,导致数据迁移失败并中断。此后,尝试修改配置减小TimeBetweenLocalCheckpoints或增大NoOfFragmentLogFiles,等方法后,重启节点都无法成功。最后,只能初始化数据节点——原来的以NDBCluster为引擎的表的数据会全部丢失,重新插入数据进行测试。





Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!