Build mysql NDB cluster

Posted by al3x8730 on Wed, 11 Mar 2020 10:41:43 +0100

NDB cluster installation


NDBCLUSTER (also known as NDB )Is a memory storage engine that provides high availability and data persistence.

Of NDBCLUSTER The storage engine can be configured with a range of failover and load balancing options, but the simplest is to start the storage engine at the cluster level. NDB Cluster's NDB The storage engine contains a complete set of data, which only depends on other data within the cluster itself.

The configuration of the cluster part of the NDB cluster is independent of the MySQL server. In an NDB cluster, each part of the cluster is treated as a node.

There are three types of cluster nodes, and in the smallest NDB cluster configuration, there will be at least three nodes, one of these types:

  • Management node: this type of node is used to manage other nodes in the NDB cluster, perform functions such as providing configuration data, starting and stopping nodes, and running backups. Because this node type manages the configuration of other nodes, you should start this type of node before starting any other nodes. Use command ndb_mgmd Start an MGM node.

  • Data node: this type of node stores cluster data.

    NDB cluster tables are usually completely stored in memory, not on disk (that's why we call NDB clusters memory databases). However, some NDB cluster data can be stored on disk.

  • SQL node: This is the node that accesses the cluster data. For NDB clusters, SQL nodes use the NDBCLUSTER Traditional MySQL server for storing engine.

    The SQL node is actually just a special type of API node that specifies any application accessing NDB cluster data. Another example of an API node is for restoring cluster backups ndb_restore Utility. You can write such an application using the NDB API.

1. Resource Planning


IP address

hardware resource




Management node (mgmd)

1 CPU, 1G memory




Management node (mgmd)

1 CPU, 1G memory




Data node "A" (ndbd)

SQL node (mysqld)

1 CPU, 3G memory

(data nodes eat memory)




Data node "B" (ndbd)

SQL node (mysqld)

1 CPU, 3G memory





2. Download the installation files (,

Official website address:



3.2 SQL node

Change the location to the directory containing the downloaded files, extract the archive files, and create a symbolic link named mysql to the mysql directory.

useradd mysql

tar -xf mysql-cluster-gpl-8.0.20-linux-glibc2.12-x86_64.tar.gz

mv mysql-cluster-gpl-8.0.20-linux-glibc2.12-x86_64 /usr/local/mysql


3.3 change the location to mysql directory, and use mysqld to set the system database -- initialize, as shown below:

#rm -rf /data/apps/mysql-8.0/

mkdir  -p  /data/apps/mysql-8.0/logs  && chown -R mysql.mysql  /data/apps/mysql-8.0

chown -R mysql.mysql /usr/local/mysql

cat > /usr/local/mysql/my.cnf <<EOE



























mv /etc/my.cnf /etc/my.cnf_`date +%F-%s`

ln -s  /usr/local/mysql/my.cnf  /etc/my.cnf



3.4 initialize database

/usr/local/mysql/bin/mysqld --defaults-file=/usr/local/mysql/my.cnf --basedir=/usr/local/mysql --datadir=/data/apps/mysql-8.0/data  --initialize --user=mysql 




Remember the code. Use it later



3.4 copy the MySQL startup script to the appropriate directory, make it executable, and set it to start when the operating system starts:

cp support-files/mysql.server  /etc/rc.d/init.d/

chmod +x /etc/rc.d/init.d/mysql.server

chkconfig --add mysql.server


4.1 for data nodes, copy the startup files of data nodes, for example, data nodes and sql nodes are on the same platform. This step is ignored

scp{ndbd,ndbmtd}  /usr/local/bin/.

cd /usr/local/bin

chmod +x ndb*

mkdir -p /data/apps/mysql-8.0

Repeat the above steps on each data node host.


5.1 management node.  137.128,137.129

scp*  /usr/local/bin/.
cd /usr/local/bin
chmod +x ndb_mgm*
mkdir -p /usr/local/mysql/mysql-cluster


5.2 configuration management node.

#Profile details



cat >  /usr/local/mysql/config.ini <<EOE
[ndbd default]
# Options affecting ndbd processes on all data nodes:
NoOfReplicas=2    # Number of replicas
DataMemory=98M    # How much memory to allocate for data storage

# Management process options:
HostName=          # Hostname or IP address of MGM node
DataDir=/usr/local/mysql/mysql-cluster  # Directory for MGM node log files

# Management process options:
HostName=          # Hostname or IP address of MGM node
DataDir=/usr/local/mysql/mysql-cluster  # Directory for MGM node log files

# Options for data node "A":
                               # (one [ndbd] section per data node)
HostName=         # Hostname or IP address
NodeId=3                        # Node ID for this data node
DataDir=/data/apps/mysql-8.0   # Directory for this data node's data files

# Options for data node "B":
HostName=          # Hostname or IP address
NodeId=4                        # Node ID for this data node
DataDir=/data/apps/mysql-8.0   # Directory for this data node's data files

# SQL node options:
HostName=      # Hostname or IP address
                                # (additional mysqld connections can be
                                # specified for this node for various
[mysqld] # SQL node options: NodeId
=6 HostName= # purposes such as running ndb_restore) EOE


6. Initial startup of NDB cluster

6.1 management host

/usr/local/mysql/bin/ndb_mgmd  -f /usr/local/mysql/config.ini  --initial (Add only after initialization)




6.2 on each data node host, run the following command to start ndbd Process:

ndbd --initial

If an error is reported, execute the following command


ln -s /usr/local/lib64/ /usr/lib64/

ln -s /usr/local/lib64/ /usr/lib64/

Restart successful:


6.3 Sql node start database:

/usr/local/mysql/bin/mysqld &


If all goes well and the cluster is set up correctly, the cluster should now be operational. You can call ndb_mgm Manage node clients to test this. The output should look like what is shown here, although you may see some slight differences in the output, depending on the MySQL version used:

Management node





The SQL node is called [mysqld(API)] here, which reflects mysqld The fact that a process acts as an NDB cluster API node.

7. Safely shut down and restart the NDB cluster

7.1 to shut down the cluster, enter the following command in the shell on the computer that hosts the management node:

NDB? MGM - e shutdown - e the options here are used to pass commands from the shell to the NDB? MGM client.

7.2 restart, management node executes

ndb_mgmd   -f /usr/local/mysql/config.ini  

7.3 execution at each data node


7.4 use the NDB? MGM client to verify that both data nodes have started successfully.

7.5 on the SQL host:

/usr/local/mysql/bin/mysqld &

If one of the data nodes is hung up, one of the nodes must be fully recovered before the cluster can continue to use it


8. Other notes

You must set the primary key and add ENGINE=NDBCLUSTER when creating the table

create table s_position


id int not null auto_increment,

name varchar(20) not null default 'manager', #Set default

description varchar(100),

primary key PK_positon (id) #Set primary key


Topics: MySQL SQL Linux Database