centos7 quick guide for building MySQL NDB Cluster 7.5/7.6 cluster

NDB Cluster is a technology that enables in memory database clustering in a shareless system. Shareless architecture enables the system to use very cheap hardware with minimal specific requirements for hardware or software.

NDB Cluster is designed without any single point of failure. In a non shared system, each component should have its own memory and disk. It is not recommended or supported to use shared storage mechanisms such as network sharing, network file system and SAN. NDB Cluster consists of a group of computers called hosts, each running one or more processes. These processes, called nodes, may include MySQL servers (for accessing NDB data), data nodes (for storing data), one or more management servers, and possibly other dedicated data access programs. The relationship between these components in NDB Cluster is as follows:

MySQL NDB Cluster consists of three nodes: SQL node, data node and management node.

Next, this paper uses the following methods to build clusters.

3 servers:

Management node,:
SQL node a, data node A:

SQL node b, data node b:

Perform the following operations on the management node, SQL node, data node:

1. Add MySQL Yum repository for MySQL NDB Cluster, and execute on all node servers:

$> mkdir -p /data/mysql
$> cd /data/mysql/
$> yum -y install wget
$> wget https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm
$> rpm -Uvh mysql80-community-release-el7-6.noarch.rpm

2. Select MySQL NDB cluster sub Library:

$> yum -y install yum-utils
$> sudo yum-config-manager --disable mysql80-community
$> sudo yum-config-manager --enable mysql-cluster-7.6-community

$> yum repolist enabled | grep mysql
mysql-cluster-7.6-community/x86_64      MySQL Cluster 7.6 Community          359
mysql-connectors-community/x86_64       MySQL Connectors Community           192
mysql-tools-community/x86_64            MySQL Tools Community                 90

3. Install MySQL NDB cluster:

$> rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

3.1 perform the following operations in the management node:

$> yum -y install mysql-cluster-community-management-server

3.2 perform the following operations on the SQL node:

Manually install the dependency Perl class methodmaker (this dependency does not exist in CentOS and cannot be found automatically. EPEL EL7 x86#u 64 is used):

$> wget https://mirrors.aliyun.com/epel/7/x86_64/Packages/p/perl-Class-MethodMaker-2.20-1.el7.x86_64.rpm
$> yum -y install perl-Class-MethodMaker-2.20-1.el7.x86_64.rpm

Install components of SQL node:
Close the firewall and selinux

$> systemctl stop firewalld.service #Stop firewall
$> systemctl disable firewalld.service #Disable firewall startup
$> setenforce 0

query state
$> getenforce
$> vi  /etc/sysconfig/selinux

Install sql node

$> yum -y install mysql-cluster-community-server

Stop the mysql node service. If it cannot be stopped, you need to kill ps -ef|grep mysql | kill -9

$> systemctl stop mysqld

Move data files to / data/mysql/data directory

$> cp -rf /var/lib/mysql /data/mysql/data/

Setting data permissions is very important, otherwise it cannot be started

$> chown -R mysql:mysql /var/lib/mysql
$> chown -R mysql:mysql /data/mysql/data/

3.3 installing data nodes:

$> sudo yum -y install mysql-cluster-community-data-node

3.4 configure my on each sql node and data node conf

$> vi /etc/my.cnf

#Add the following:
# Options for mysqld process:
ndbcluster                      # run NDB storage engine

#Amend the following
#Change to

# Options for NDB Cluster processes:
ndb-connectstring=  # location of management server

3.5 configuration management node

$> mkdir /var/lib/mysql-cluster
$> mkdir /data/mysql/mysql-cluster

$> cd /var/lib/mysql-cluster
$> vi config.ini

[ndbd default]
# Options affecting ndbd processes on all data nodes:
NoOfReplicas=2    # Number of fragment replicas
DataMemory=80M    # How much memory to allocate for data storage
#IndexMemory=18M   # How much memory to allocate for index storage
                  # For DataMemory and IndexMemory, we have used the
                  # default values. Since the "world" database takes up
                  # only about 500KB, this should be more than enough for
                  # this example NDB Cluster setup.
                  # NOTE: IndexMemory is deprecated in NDB 7.6 and later; in
                  # these versions, resources for all data and indexes are
                  # allocated by DataMemory and any that are set for IndexMemory
                  # are added to the DataMemory resource pool
ServerPort=2202   # This the default value; however, you can use any
                  # port that is free for all the hosts in the cluster
                  # Note1: It is recommended that you do not specify the port
                  # number at all and simply allow the default value to be used
                  # instead
                  # Note2: The port was formerly specified using the PortNumber
                  # TCP parameter; this parameter is no longer available in NDB
                  # Cluster 7.5.

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

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

# Options for data node "B":
HostName=          # Hostname or IP address
NodeId=3                        # Node ID for this data node
DataDir=/data/mysql/data   # 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
                                # purposes such as running ndb_restore)

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


3.6 configuration on management node

Perform operations on the management node:
Open port 1186:

$> firewall-cmd --zone=public --add-port=1186/tcp --permanent
$> firewall-cmd --zone=public --add-port=2202/tcp --permanent
$> systemctl restart firewalld.service
$> firewall-cmd --list-ports

If you want to reinitialize after modifying the configuration file for the first time, add the -- initial parameter after the following command

$> ndb_mgmd -f /var/lib/mysql-cluster/config.ini

Start on the data node in the correct order

$> ndbd

3.5 start the service on the sql node

$> systemctl start mysqld.service

Observe the cluster: execute on any sql node or management node

# ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm> show
Connected to Management Server at:
Cluster Configuration
[ndbd(NDB)]    2 node(s)
id=2    @  (mysql-5.7.38 ndb-7.6.22, Nodegroup: 0, *)
id=3    @  (mysql-5.7.38 ndb-7.6.22, Nodegroup: 0)

[ndb_mgmd(MGM)]    1 node(s)
id=1    @  (mysql-5.7.38 ndb-7.6.22)

[mysqld(API)]    2 node(s)
id=4    @  (mysql-5.7.38 ndb-7.6.22)
id=5    @  (mysql-5.7.38 ndb-7.6.22)


Seeing the above display indicates that the cluster is running normally

Other common commands

Shut down the cluster
$> ndb_mgm -e shutdown

View the mysql default password in the sql node
$> grep 'temporary password' /var/log/mysqld.log

reference material:

MySQL :: MySQL 5.7 Reference Manual :: 21.2 NDB Cluster Overview

Tags: Database MySQL MariaDB

Posted by DrTom on Sun, 22 May 2022 08:32:09 +0300