search
HomeDatabaseMysql TutorialMysql集群添加节点水平扩展

Mysql集群添加节点水平扩展

Jun 07, 2016 pm 03:33 PM
dhttpmysqlExpandlevelAdd tonodecluster

参考: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>

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>
Connected to Management Server at: 10.135.10.225:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=22    @10.135.10.225  (5.6.20-ndb-7.3.7, Nodegroup: 0, *)
id=21 (not connected, accepting connect from 10.135.10.51)
 
[ndb_mgmd(MGM)] 1 node(s)
id=1    @10.135.10.225  (5.6.20-ndb-7.3.7)
 
[mysqld(API)]   2 node(s)
id=12   @10.135.10.225  (5.6.20-ndb-7.3.7)

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

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

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

 

shell>net stop mysql;

 

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>
<code><strong> </strong></code>
shell> net start mysql;

 

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

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

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

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

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

 

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为引擎的表的数据会全部丢失,重新插入数据进行测试。





Statement
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
What are stored procedures in MySQL?What are stored procedures in MySQL?May 01, 2025 am 12:27 AM

Stored procedures are precompiled SQL statements in MySQL for improving performance and simplifying complex operations. 1. Improve performance: After the first compilation, subsequent calls do not need to be recompiled. 2. Improve security: Restrict data table access through permission control. 3. Simplify complex operations: combine multiple SQL statements to simplify application layer logic.

How does query caching work in MySQL?How does query caching work in MySQL?May 01, 2025 am 12:26 AM

The working principle of MySQL query cache is to store the results of SELECT query, and when the same query is executed again, the cached results are directly returned. 1) Query cache improves database reading performance and finds cached results through hash values. 2) Simple configuration, set query_cache_type and query_cache_size in MySQL configuration file. 3) Use the SQL_NO_CACHE keyword to disable the cache of specific queries. 4) In high-frequency update environments, query cache may cause performance bottlenecks and needs to be optimized for use through monitoring and adjustment of parameters.

What are the advantages of using MySQL over other relational databases?What are the advantages of using MySQL over other relational databases?May 01, 2025 am 12:18 AM

The reasons why MySQL is widely used in various projects include: 1. High performance and scalability, supporting multiple storage engines; 2. Easy to use and maintain, simple configuration and rich tools; 3. Rich ecosystem, attracting a large number of community and third-party tool support; 4. Cross-platform support, suitable for multiple operating systems.

How do you handle database upgrades in MySQL?How do you handle database upgrades in MySQL?Apr 30, 2025 am 12:28 AM

The steps for upgrading MySQL database include: 1. Backup the database, 2. Stop the current MySQL service, 3. Install the new version of MySQL, 4. Start the new version of MySQL service, 5. Recover the database. Compatibility issues are required during the upgrade process, and advanced tools such as PerconaToolkit can be used for testing and optimization.

What are the different backup strategies you can use for MySQL?What are the different backup strategies you can use for MySQL?Apr 30, 2025 am 12:28 AM

MySQL backup policies include logical backup, physical backup, incremental backup, replication-based backup, and cloud backup. 1. Logical backup uses mysqldump to export database structure and data, which is suitable for small databases and version migrations. 2. Physical backups are fast and comprehensive by copying data files, but require database consistency. 3. Incremental backup uses binary logging to record changes, which is suitable for large databases. 4. Replication-based backup reduces the impact on the production system by backing up from the server. 5. Cloud backups such as AmazonRDS provide automation solutions, but costs and control need to be considered. When selecting a policy, database size, downtime tolerance, recovery time, and recovery point goals should be considered.

What is MySQL clustering?What is MySQL clustering?Apr 30, 2025 am 12:28 AM

MySQLclusteringenhancesdatabaserobustnessandscalabilitybydistributingdataacrossmultiplenodes.ItusestheNDBenginefordatareplicationandfaulttolerance,ensuringhighavailability.Setupinvolvesconfiguringmanagement,data,andSQLnodes,withcarefulmonitoringandpe

How do you optimize database schema design for performance in MySQL?How do you optimize database schema design for performance in MySQL?Apr 30, 2025 am 12:27 AM

Optimizing database schema design in MySQL can improve performance through the following steps: 1. Index optimization: Create indexes on common query columns, balancing the overhead of query and inserting updates. 2. Table structure optimization: Reduce data redundancy through normalization or anti-normalization and improve access efficiency. 3. Data type selection: Use appropriate data types, such as INT instead of VARCHAR, to reduce storage space. 4. Partitioning and sub-table: For large data volumes, use partitioning and sub-table to disperse data to improve query and maintenance efficiency.

How can you optimize MySQL performance?How can you optimize MySQL performance?Apr 30, 2025 am 12:26 AM

TooptimizeMySQLperformance,followthesesteps:1)Implementproperindexingtospeedupqueries,2)UseEXPLAINtoanalyzeandoptimizequeryperformance,3)Adjustserverconfigurationsettingslikeinnodb_buffer_pool_sizeandmax_connections,4)Usepartitioningforlargetablestoi

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!