Mysql集群添加节点水平扩展
参考: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条测试数据。下面为在此基础上水平扩展一个节点,已知该节点ip为10.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. 查看和重分配数据:
可见新增节点尚未为分配数据。在数据库中输入如下命令并运行:
运行后的结果如下图:
如图可知数据迁移之后空间还没有释放出来,需要通过optimize命令优化表,释放迁移走的空间(当optimize一个ndb大表的时候很慢,很容易出问题)。
在数据库中输入优化命令,优化后结果如下图:
可知部分数据已经迁移到新增的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为引擎的表的数据会全部丢失,重新插入数据进行测试。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting

Installing MySQL on CentOS involves the following steps: Adding the appropriate MySQL yum source. Execute the yum install mysql-server command to install the MySQL server. Use the mysql_secure_installation command to make security settings, such as setting the root user password. Customize the MySQL configuration file as needed. Tune MySQL parameters and optimize databases for performance.
