To implement a MySQL Cluster, we have to install three types of nodes. Each node type will be installed on it’s own server. The components are:
1. Management Node – NDB_MGMD/MGM
The Cluster management server is used to manage the other node of the cluster. We can create and configure new nodes, restart, delete, or backup nodes on the cluster from the management node.
2. Data Nodes – NDBD/NDB
This is the layer where the process of synchronizing and data replication between nodes happens.
3. SQL Nodes – MySQLD/API
The interface servers that are used by the applications to connect to the database cluster.
Step 1 – Setup Management Node
The first step is to create the “Management Node” with CentOS 7 db1 and IP 192.168.1.120. Make sure you are logged into the db1 server as root user.
A. Download the MySQL Cluster software
I’ll download it from the MySQL site with wget. I’m using the “Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit), RPM Bundle ” here which is compatible with CentOS 7. Then extract the tar file.
cd ~
wget http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.4/MySQL-Cluster-gpl-7.4.10-1.el7.x86_64.rpm-bundle.tar
tar -xvf MySQL-Cluster-gpl-7.4.10-1.el7.x86_64.rpm-bundle.tar
B. Install and Remove Packages
Before you install the rpm package for MySQL Cluster, you need to install perl-Data-Dumper that is required by the MySQL-Cluster server. And you need to remove mariadb-libs before we can install MySQL Cluster.
yum -y install perl-Data-Dumper
yum -y remove mariadb-libs
C. Install MySQL Cluster
Install MySQL Cluster package with these rpm commands:
cd ~
rpm -Uvh MySQL-Cluster-client-gpl-7.4.10-1.el7.x86_64.rpm
rpm -Uvh MySQL-Cluster-server-gpl-7.4.10-1.el7.x86_64.rpm
rpm -Uvh MySQL-Cluster-shared-gpl-7.4.10-1.el7.x86_64.rpm
Make sure there is no error.
D. Configure MySQL Cluster
Create a new directory for the configuration files. I will use the “/var/lib/mysql-cluster” directory.
mkdir -p /var/lib/mysql-cluster
Then create new configuration file for the cluster management named “config.ini” in the mysql-cluster directory.
cd /var/lib/mysql-cluster
vi config.ini
Paste the configuration below:
[ndb_mgmd default] # Directory for MGM node log files DataDir=/var/lib/mysql-cluster [ndb_mgmd] #Management Node db1 HostName=192.168.1.120 [ndbd default] NoOfReplicas=2 # Number of replicas DataMemory=256M # Memory allocate for data storage IndexMemory=128M # Memory allocate for index storage #Directory for Data Node DataDir=/var/lib/mysql-cluster [ndbd] #Data Node db2 HostName=192.168.1.121 [ndbd] #Data Node db3 HostName=192.168.1.122 [mysqld] #SQL Node db4 HostName=192.168.1.123 [mysqld] #SQL Node db5 HostName=192.168.1.124
Save the file and exit.
E. Start the Management Node
Next start the management node with the command below:
ndb_mgmd –config-file=/var/lib/mysql-cluster/config.ini
The result should be similar to this:
MySQL Cluster Management Server mysql-5.6.28 ndb-7.4.10
2016-03-22 19:26:08 [MgmtSrvr] INFO — The default config directory ‘/usr/mysql-cluster’ does not exist. Trying to create it…
2016-03-22 19:26:08 [MgmtSrvr] INFO — Successfully created config directory
The management node is started, now you can use command “ndb_mgm” to monitor the node:
ndb_mgm
show
You can see the management node has been started with: mysql-6.6 and ndb-7.4.
Step 2 – Setup the MySQL Cluster Data Nodes
We will use 2 CentOS servers for the Data Nodes.
- db2 = 192.168.1.121
- db3 = 192.168.1.122
A. Login as root user and download the MySQL Cluster software
Login to the db2 server with ssh:
ssh root@192.168.1.121
Then download the MySQL Cluster package and extract it:
cd ~
wget http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.4/MySQL-Cluster-gpl-7.4.10-1.el7.x86_64.rpm-bundle.tar
tar -xvf MySQL-Cluster-gpl-7.4.10-1.el7.x86_64.rpm-bundle.tar
B. Install and Remove Packages
Install perl-Data-Dumper and remove the mariadb-libs:
yum -y install perl-Data-Dumper
yum -y remove mariadb-libs
C. Install MySQL Cluster
Now we can install the MySQL Cluster packages for the Data Nodes with these rpm commands:
cd ~
rpm -Uvh MySQL-Cluster-client-gpl-7.4.10-1.el7.x86_64.rpm
rpm -Uvh MySQL-Cluster-server-gpl-7.4.10-1.el7.x86_64.rpm
rpm -Uvh MySQL-Cluster-shared-gpl-7.4.10-1.el7.x86_64.rpm
Make sure there is no error.
D. Configure Data Node
Create a new configuration file in the /etc directory with the vi editor:
vi /etc/my.cnf
Paste configuration below:
[mysqld] ndbcluster ndb-connectstring=192.168.1.120 # IP address of Management Node [mysql_cluster] ndb-connectstring=192.168.1.120 # IP address of Management Node
Save the file and exit.
Then create the new directory for the database data that we defined in the management node config file “config.ini”.
mkdir -p /var/lib/mysql-cluster
Now start the data node/ndbd:
ndbd
results:
2016-03-22 19:35:56 [ndbd] INFO — Angel connected to ‘192.168.1.120:1186’
2016-03-22 19:35:56 [ndbd] INFO — Angel allocated nodeid: 2
Data Node db2 connected to the management node ip 192.168.1.120.
E. Redo step 2.A – 2.D on db3 server.
As we have 2 data nodes, please redo the steps 2.A – 2.D on our second data node.
Step 3 – Setup SQL Node
This is step contains the setup for the SQL Node that provides the application access to the database. We use 2 CentOS servers for the SQL Nodes:
- db4 = 192.168.1.123
- db5 = 192.168.1.124
A. Log in and Download MySQL Cluster
Login to the db4 server as root user:
ssh root@192.168.1.123
And download MySQL Cluster package:
cd ~
wget http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.4/MySQL-Cluster-gpl-7.4.10-1.el7.x86_64.rpm-bundle.tar
tar -xvf MySQL-Cluster-gpl-7.4.10-1.el7.x86_64.rpm-bundle.tar
Install perl-Data-Dumper and remove the mariadb-libs that conflict with MySQL Cluster.
yum -y install perl-Data-Dumper
yum -y remove mariadb-libs
C. Install MySQL Cluster
Install the MySQL Cluster server, client and shared package with the rpm commands below:
cd ~
rpm -Uvh MySQL-Cluster-client-gpl-7.4.10-1.el7.x86_64.rpm
rpm -Uvh MySQL-Cluster-server-gpl-7.4.10-1.el7.x86_64.rpm
rpm -Uvh MySQL-Cluster-shared-gpl-7.4.10-1.el7.x86_64.rpm
D. Configure the SQL Node
Create a new my.cnf file in the /etc directory:
vi /etc/my.cnf
And paste configuration below:
[mysqld] ndbcluster ndb-connectstring=192.168.1.120 # IP address for server management node default_storage_engine=ndbcluster # Define default Storage Engine used by MySQL [mysql_cluster] ndb-connectstring=192.168.1.120 # IP address for server management node
Save the file and exit the editor.
Start the SQL Node by starting the MySQL server:
service mysql start
E. Redo step 3.A – 3.D on db5 server.
Please redo the steps 3.A – 3.D on the second SQL server (db5).