How to install and configure MySQL NDB cluster on CentOS 6.7

How to install and configure MySQL NDB cluster on CentOS 6.7

MySQL NDB Cluster is a high-availability, high-redundancy version of MySQL adapted for the distributed computing environment. The MySQL Cluster technology is implemented through the NDB (Network DataBase) and NDBCLUSTER storage engines. They are Management node, Data Node and Sql node and descriptions of the nodes as shown below. This tutorial covers the installation and configuration process of MySQL NDB cluster on CentOS 6.7.

Management Node

The role of this type of node is to manage the other nodes within the NDB Cluster, performing such functions as providing configuration data, starting and stopping nodes, and running backups. Because this node type manages the configuration of the other nodes, a node of this type should be started first, before any other node. An MGM node is started with the command ndb_mgmd.

Data Node

This type of node stores cluster data. There are as many data nodes as there are replicas, times the number of fragments. For example, with two replicas, each having two fragments, you need four data nodes. One replica is sufficient for data storage, but provides no redundancy therefore, it is recommended to have 2 (or more) replicas to provide redundancy, and thus high availability. A data node is started with the command ndbd.

SQL Node

This node can accesses the cluster data. In the case of NDB Cluster, an SQL node is a traditional MySQL server that uses the NDBCLUSTER storage engine. An SQL node is a mysqld process started with the --ndbcluster and --ndb-connectstring options.

NDB_MGMD : 192.168.7.195 [Management node]

Ndbd node1 : 192.168.7.196 [Data node1]

Ndbd node2 : 192.168.7.197 [Data node2]

Mysqld node1 : 192.168.7.198 [SQL node1]

Mysqld node2 : 192.168.7.199 [SQL node2]

Prerequisite

  • Disable firewall services.
  • Set SELinux into disabled mode.

Installation procedure

1. To begin with the installation procedure, download the Mysql NDB cluster 7.4.10 using wget command.

[root@domain1 ~]# wget http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.4/MySQL-Cluster-gpl-7.4.10-1.el6.x86_64.rpm-bundle.tar

2. The MySQL cluster is downloaded in the target system. Download the perl-data-dumper package using the wget command.

[root@domain2 ~]# wget ftp://195.220.108.108/linux/dag/redhat/el6/en/x86_64/dag/RPMS/perl-Data-Dumper-2.125-1.el6.rf.x86_64.rpm

3. The perl-data-dumper is also downloaded in the system. Remove the MySQL library files by running the following command.

[root@domain1 ~]# yum remove mysql-libs &ndash y

4. The MySQL library file are removed successfully. Next, install the perl data dumper package by executing the following command.

[root@domain1 ~]# yum install perl-Data-Dumper-2.125-1.el6.rf.x86_64.rpm

5. Now, extract the MySQL NDB cluster package by running the tar command.

[root@domain1 ~]# tar -xvf MySQL-Cluster-gpl-7.4.10-1.el6.x86_64.rpm-bundle.tar

6. The MySQL NDB cluster package is installed in the target system. Install the following MySQL NDB packages as follows.

[root@domain4 ~]# yum install MySQL-Cluster-shared-gpl-7.4.10-1.el6.x86_64.rpm MySQL-Cluster-server-gpl-7.4.10-1.el6.x86_64.rpm MySQL-Cluster-client-gpl-7.4.10-1.el6.x86_64.rpm &ndash y

Repeat step 1-6 in all the nodes.

7. Now create a directory in below location by executing the following commands.

[root@domain4 ~]# mkdir /var/lib/mysql-cluster
[root@domain4 ~]# cd /var/lib/mysql-cluster

8. Next create a file in the newly created directory and add the cluster configuration details to the file. Save and exit from the file.

[root@domain1 mysql-cluster]# vim config.ini
[ndb_mgmd]
#Management Node db1
HostName=192.168.7.195

[ndbd default]
NoOfReplicas=2      # Number of replicas
DataMemory=100M     # Memory allocate for data storage
IndexMemory=100M    # Memory allocate for index storage
#Directory for Data Node
DataDir=/var/lib/mysql-cluster

[ndbd]
#Data Node db2
HostName=192.168.7.196

[ndbd]
#Data Node db3
HostName=192.168.7.197

[mysqld]
HostName=192.168.7.198 #SQL Node1

[mysqld]
HostName=192.168.7.199  #SQL Node2

9. Start the NDB management node by running the following command.

[root@domain1 ~]# ndb_mgmd --config-file=/var/lib/mysql-cluster/config.ini
MySQL Cluster Management Server mysql-5.6.28 ndb-7.4.10
2017-06-09 01:34:57 [MgmtSrvr] INFO     -- The default config directory ' /usr/mysql-cluster'  does not exist. Trying to create it...
2017-06-09 01:34:57 [MgmtSrvr] INFO     -- Sucessfully created config directory

10. Check the other node status from NDB management node.

- NDB Cluster -- Management Client --
ndb_mgm>  show 
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]      2 node(s)
id=2 (not connected, accepting connect from 192.168.7.196)
id=3 (not connected, accepting connect from 192.168.7.197)

[ndb_mgmd(MGM)]      1 node(s)
id=1       @192.168.7.195  (mysql-5.6.28 ndb-7.4.10)

[mysqld(API)]    2 node(s)
id=4 (not connected, accepting connect from 192.168.7.198)
id=5 (not connected, accepting connect from 192.168.7.199)
ndb_mgm>  exit

11. Switch to Data node1 and do the following steps. Create the new directory for the database data that is defined in the management node by config file " config.ini" .

[root@domain2 ~]# mkdir -p /var/lib/mysql-cluster

12. Next, configure the NDB data node.

[root@domain2 ~]# vim /etc/my.cnf
[mysqld]
ndbcluster
ndb-connectstring=192.168.7.195
[mysql_cluster]
ndb-connectstring=192.168.7.195

13. Now start the data node by following command.

[root@domain2 ~]# ndbd
2017-06-09 03:48:45 [ndbd] INFO     -- Angel connected to ' 192.168.7.195:1186' 
2017-06-09 03:48:45 [ndbd] INFO     -- Angel allocated nodeid: 2

Repeat step 9-11 on data node2.

14. Switch to SQL node and do the following configuration.

[root@domain4 ~]# vim .my.cnf
[mysqld]
ndbcluster
ndb-connectstring=192.168.7.195       # IP address for server management node
default_storage_engine=ndbcluster     # Define default Storage Engine used by MySQL

[mysql_cluster]
ndb-connectstring=192.168.7.195       # IP address for server management node

15. Set the MySQL credentials by executing the following commands.

[root@domain5 ~]# mysql_secure_installation

16. Restart the MySQL service.

[root@domain5 ~]# service mysql restart

Repeat steps 14-16 to SQL second node.

17. Switch to management node and check the cluster connection status.

[root@domain1 ~]# ndb_mgm
-- NDB Cluster -- Management Client --

ndb_mgm>  show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)]     2 node(s)
id=2    @192.168.7.196  (mysql-5.6.28 ndb-7.4.10, Nodegroup: 0, *)
id=3    @192.168.7.197  (mysql-5.6.28 ndb-7.4.10, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.7.195  (mysql-5.6.28 ndb-7.4.10)

[mysqld(API)]   2 node(s)
id=4    @192.168.7.198  (mysql-5.6.28 ndb-7.4.10)
id=5    @192.168.7.199  (mysql-5.6.28 ndb-7.4.10)
ndb_mgm> exit

18. Now it’ s time to check replication status. On SQL node1 create a database by running the following command.

mysql>  create database cluster1_db 
Query OK, 1 row affected (0.19 sec)

mysql>  show databases 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cluster1_db        |
| mysql              |
| ndbinfo            |
| performance_schema |
+--------------------+
5 rows in set (0.12 sec)

19. Switch to SQL node2 and check the status of the databases.

mysql>  show databases 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cluster1_db        |
| mysql              |
| ndbinfo            |
| performance_schema |
+--------------------+
5 rows in set (0.09 sec)

20. Now create database in SQL node2 to check replication process.

mysql>  create database cluster2_db 
Query OK, 1 row affected (0.07 sec)

mysql>  show databases 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cluster1_db        |
| cluster2_db        |
| mysql              |
| ndbinfo            |
| performance_schema |
+--------------------+
6 rows in set (0.00 sec)

21. Switch to SQL node1 and check the replication process.

mysql>  show databases 
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cluster1_db        |
| cluster2_db        |
| mysql              |
| ndbinfo            |
| performance_schema |
+--------------------+
6 rows in set (0.00 sec)

That was an easy installation and configuration process, Wasn' t it? The MySQL NDB cluster also supports User authentication and authorization.

Comment
alonzo
Mar 23 2020
hi. i'm stuck on the sql node. there is no .mysql_secret file on my end. please help
manesh12
Jun 29 2019
ERROR -- Could not determine which nodeid to use for this node. Specify it with --ndb-nodeid= on command line

how to solve this error????/
Add a comment
FAQ
Q
What is MySQL NDB cluster?
A
MySQL NDB Cluster is a high-availability, high-redundancy version of MySQL adapted for the distributed computing environment. The MySQL Cluster technology is implemented through the NDB (Network DataBase) and NDBCLUSTER storage engines. They are the Management node, Data Node, and SQL node and descriptions of the nodes
Q
Is MySQL Cluster supported on Virtual Machine environments?
A
Yes. MySQL Cluster is tested and certified on Oracle VM.
Q
What is MySQL Cluster Carrier Grade Edition?
A
MySQL Cluster Carrier Grade Edition (CGE) includes tools for the management, monitoring security and auditing of the MySQL Cluster database, coupled with access to Oracle Premier Support. MySQL Cluster CGE is available under a choice of subscription or commercial license and support.
Q
What do “NDB” and “NDBCLUSTER” mean?
A
“NDB” stands for “Network Database”. NDB and NDBCLUSTER are both names for the storage engine that enables clustering support with MySQL. NDB is preferred, but either name is correct.
Q
How do I find out what an error or warning message means when using NDB Cluster?
A
From within the mysql client, use SHOW ERRORS or SHOW WARNINGS immediately upon being notified of the error or warning condition.

From a system shell prompt, use perror --ndb error_code.