April 10, 2017

MySQL Cluster on Ubuntu 17.04

MySQL provide software database cluster on MySQL Cluster to keep high availability for database node. MySQL Cluster contain 3 important function. NDB, NDB_MGM, SQL Node.
Management Node (ndb_mgmd) : MySQL Cluster to maintain two or mode node server. ndb_mgmd function to monitoring and configuring all nodes.
Data Node (ndbd) : MySQL Cluster Data Node used to store the data and pro automatic sharding and handled by replication.
SQL Node (mysqld) : MySQL Server connected to the ndb_mgmd to create query to all nodes in the cluster.

In this tutorial, I will show you how to install a 'MySQL Cluster' on Ubuntu 17.04.
Server Configuration :
4 nodes with Ubuntu server 17.04
172.17.20.140    management-node
172.17.20.141    node1
172.17.20.142    node2
172.17.20.143    sql
Root privileges on the nodes (sudo -s).

Configuration to all Node

Download MySQL Cluster Installer
wget http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.4/mysql-cluster-gpl-7.4.12-linux-glibc2.5-x86_64.tar.gz
unpack MySQL Cluster Installer
tar -xzvf mysql-cluster-gpl-7.4.12-linux-glibc2.5-x86_64.tar.gz
Rename mysql cluster installer 
mv mysql-cluster-gpl-7.4.12-linux-glibc2.5-x86_64/ mysql/
go to mysql
cd ~/mysql/
copy all files inside bin/ directory to /usr/local/bin
cp bin/ndb_mgm* /usr/local/bin/
Give the executable permission with +x
chmod +x /usr/local/bin/ndb_mgm*
Remove bin/* files existing, and create a new symlink
rm -rf bin/

ln -s /usr/local/bin /usr/local/mysql/
Change the directory ownership
chown -R root:mysql .

chown -R mysql data
Install MySQL Cluster package denpendecy 
apt-get install libaio1
Create New User and Group mysql
groupadd mysql

useradd -g mysql mysql
Configuration by Function
1. MySQL Cluster Management Node
Create new directory /var/lib/mysql-cluster/
mkdir -p /var/lib/mysql-cluster/
Create configuration file for MySQL Management Node (config.ini)
vim /var/lib/mysql-cluster/config.ini
[ndbd default]

NoOfReplicas=2
DataMemory=80M
IndexMemory=18M
[mysqld default]
[ndb_mgmd default]
[tcp default]
# Cluster Control / Management node
[ndb_mgmd]
hostname=172.17.20.140
# Data Node 1
[ndbd]
hostname=172.17.20.141
DataDir= /var/lib/mysql-cluster
# Data Node 1
[ndbd]
HostName=172.17.20.142
DataDir=/var/lib/mysql-cluster
# SQL Node
[mysqld]
hostname=172.17.20.143
Start MySQL Cluster Management Node :
ndb_mgmd -f /var/lib/mysql-cluster/config.ini --configdir=/var/lib/mysql-cluster/
Check Management node Serivce Status
Management Service Status


2. MySQL Cluster Data Node
Create new file configuration my.cnf inside /etc/ :
nano /etc/my.cnf
Node Configuration :
# MySQL Config

[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
user=mysql
# Run ndb storage engine
ndbcluster
# IP address management node
ndb-connectstring=172.17.20.140
[mysql_cluster]
# IP address management node
ndb-connectstring=172.17.20.140
# MySQL Pid and Log
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
save and exit.

Crate MySQL Cluster Data Node Directory :
mkdir -p /var/lib/mysql-cluster/

chown -R mysql /var/lib/mysql-cluster
Start MySQL Cluster Data Node :
ndbd --initial
or

systemctl start mysql
ndbd initial

Configure MySQL Cluster User and Password :
mysql_secure_installation
Repeat to second node with same step configuration.
related Artickle : MySQL Replication
3. MySQL Cluster SQL Node Configuration.
Create new File my.cnf
nano /etc/my.cnf
# MySQL Config

[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
user=mysql
# Run ndb storage engine
ndbcluster
# IP address management node
ndb-connectstring=172.17.20.140
[mysql_cluster]
# IP address management node
ndb-connectstring=172.17.20.140
# MySQL Pid and Log
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Start MySQL Cluster SQL Node
systemctl start mysql
Setting MySQL Cluster User and Password
mysql_secure_installation
Testing :
Logon to MySQL Cluster SQL Node 
login so mysql server 
mysql -u root -p

Password
SQL Node

Test to create new Database 
create database db_michaelsean;
ndb_mgm status

note : nodegroup: 0, * is primary Node MySQL Cluster, trying to shutdwon the primary node, the database will be automatically move to secondary node.


Thank you.
Previous Post
Next Post

post written by:

0 comments: