How to Setup MySQL NDB Cluster on Ubuntu 16.04

Prerequisites

Step 1: Defining MySQL NDB Cluster Management Node (ndb_mgmd)

Download NDB Management Server

$ cd /tmp
$ wget https://dev.mysql.com/get/Downloads/MySQL-Cluster-7.6/mysql-cluster-community-management-server_7.6.7-1ubuntu16.04_amd64.deb

Installing the NDB Management Server

$ sudo dpkg -i mysql-cluster-community-management-server_7.6.7-1ubuntu16.04_amd64.deb

Configuring the MySQL NDB Management Node

$ sudo mkdir /var/lib/mysql-cluster/
$ sudo nano  /var/lib/mysql-cluster/config.ini
# Default settings
[ndbd default]
NoOfReplicas=2
# Management node
[ndb_mgmd]
hostname=172.16.0.1
datadir=/var/lib/mysql-cluster
# 1st data node
[ndbd]
hostname=172.16.0.2
NodeId=2
datadir=/usr/local/mysql/data
# 2nd data node
[ndbd]
hostname=172.16.0.3
NodeId=3
datadir=/usr/local/mysql/data
# SQL node
[mysqld]
hostname=172.16.0.4
$ sudo ndb_mgmd -f /var/lib/mysql-cluster/config.ini
MySQL Cluster Management Server mysql-5.7.23 ndb-7.6.7
2018-08-31 06:11:22 [MgmtSrvr] INFO -- The default config directory '/usr/mysql-cluster' does not exist. Trying to create it...
2018-08-31 06:11:22 [MgmtSrvr] INFO -- Sucessfully created config directory
$ sudo pkill -f ndb_mgmd
$ sudo nano /etc/systemd/system/ndb_mgmd.service
[Unit]
Description=MySQL NDB Cluster Management Server
After=network.target auditd.service
[Service]
Type=forking
ExecStart=/usr/sbin/ndb_mgmd -f /var/lib/mysql-cluster/config.ini
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
$ sudo systemctl daemon-reload
$ sudo systemctl enable ndb_mgmd
$ sudo systemctl start ndb_mgmd
$ sudo systemctl status ndb_mgmd

Step 2: Configuring MySQL Cluster Data Nodes on Alibaba Cloud

$ cd /tmp
$ wget https://dev.mysql.com/get/Downloads/MySQL-Cluster-7.6/mysql-cluster-community-data-node_7.6.7-1ubuntu16.04_amd64.deb
$ sudo apt-get update
$ sudo apt-get install libclass-methodmaker-perl
$ sudo dpkg -i mysql-cluster-community-data-node_7.6.7-1ubuntu16.04_amd64.deb
$ sudo nano /etc/my.cnf
[mysql_cluster]
ndb-connectstring=172.16.0.1
$ sudo mkdir -p /usr/local/mysql/data
$ ndbd
2018-08-31 18:39:48 [ndbd] INFO     -- Angel connected to '172.16.0.1:1186'
2018-08-31 18:39:48 [ndbd] INFO -- Angel allocated nodeid: 2
$ sudo pkill -f ndbd
$ sudo nano /etc/systemd/system/ndbd.service
[Unit]
Description=MySQL NDB Data Node Daemon
After=network.target auditd.service
[Service]
Type=forking
ExecStart=/usr/sbin/ndbd
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
[Install]
WantedBy=multi-user.target
$ sudo systemctl daemon-reload
$ sudo systemctl enable ndbd
$ sudo systemctl start ndbd
$ sudo systemctl status ndbd

Step 3: Configuring SQL Cluster Node on Alibaba Cloud

$ sudo apt-get update
$ sudo apt install libaio1 libmecab2
$ cd /tmp
$ wget https://dev.mysql.com/get/Downloads/MySQL-Cluster-7.6/mysql-cluster_7.6.7-1ubuntu16.04_amd64.deb-bundle.tar
$ sudo mkdir installation
$ sudo tar -xvf mysql-cluster_7.6.7-1ubuntu16.04_amd64.deb-bundle.tar -C installation/
$ cd installation
$ sudo dpkg -i mysql-common_7.6.7-1ubuntu16.04_amd64.deb
$ sudo dpkg -i mysql-cluster-community-client_7.6.7-1ubuntu16.04_amd64.deb
$ sudo dpkg -i mysql-client_7.6.7-1ubuntu16.04_amd64.deb
$ sudo dpkg -i mysql-cluster-community-server_7.6.7-1ubuntu16.04_amd64.deb
$ sudo dpkg -i mysql-server_7.6.7-1ubuntu16.04_amd64.deb
$ sudo nano /etc/mysql/my.cnf
[mysqld]
ndbcluster
[mysql_cluster]
ndb-connectstring=172.16.0.1 # private ip address of the cluster manager
$ sudo systemctl restart mysql

Step 4: Testing MySQL NDB Cluster on Alibaba Cloud

$ mysql -u root -p
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.23-ndb-7.6.7 MySQL Cluster Community Server (GPL)
mysql > create database test_database;
mysql > use test_database;
mysql> create table students(student_Id BIGINT NOT NULL, student_name  VARCHAR(40) NOT NULL) ENGINE=ndbcluster;
mysql> Insert into students(student_Id, student_name) values('1', 'JOHN DOE');
mysql> Insert into students(student_Id, student_name) values('2', 'MARY DOE');
mysql> select * from students;
+------------+--------------+
| student_Id | student_name |
+------------+--------------+
| 1 | JOHN DOE |
| 2 | MARY DOE |
+------------+--------------+
2 rows in set (0.00 sec)
$ ndb_mgm
-- NDB Cluster -- Management Client --
ndb_mgm>
ndb_mgm> show;
Connected to Management Server at: 172.16.0.1:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @172.16.0.2 (mysql-5.7.23 ndb-7.6.7, Nodegroup: 0, *)
id=3 @172.16.0.3 (mysql-5.7.23 ndb-7.6.7, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @172.16.0.1 (mysql-5.7.23 ndb-7.6.7)

[mysqld(API)] 1 node(s)
id=4 @172.16.0.4 (mysql-5.7.23 ndb-7.6.7)

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store