Source

Portfolio / hacktuts / mariadb / ndb_cluster_snap.txt

Full commit
NDB Cluster in a Snap
=====================

NOTE:
NDB is a clustered engine and tables need to be created with ENGINE=NDB.

1) Notes on the Setup

Will use NDB 7.1 with one management node, two SQL nodes and two data nodes. We will use the
MySQL and NDB binaries as supplied by Oracle and not the native packages.

2) Download Cluster Package

You should be able to get it here.

3) Configure Management Node

*cp the download archive to /opt and expand
*mkdir -p /usr/local/mysql/mysql-cluster
*mkdir /var/lib/mysql-cluster (data directory)
*create config.ini

# GLOBAL OPTIONS
[ndbd default]
NoOfReplicas=2
LockPagesInMainmemory=1
DataMemory=80M
IndexMemory=18M


[tcp default]
SendBufferMemory=2M
ReceiveBufferMemory=2M


# MGMT DEFAULT OPTIONS
[ndb_mgmd default]
datadir=/var/lib/mysql-cluster


# MGMT OPTIONS
[ndb_mgmd]
hostname=sqlcmgr1-int # {/etc/hosts record with internal IP}


[ndbd]
Id=2
hostname=data1-int # {/etc/hosts record with internal IP}
datadir=/usr/local/mysql/data


[ndbd]
Id=3
hostname=data2-int # {/etc/hosts record with internal IP}
datadir=/usr/local/mysql/data


# We can house mysql on the data nodes so define 4
[mysqld]
hostname=sql1-int # {/etc/hosts record with internal IP}
[mysqld]
hostname=sql2-int # {/etc/hosts record with internal IP}
[mysqld]
hostname=data1-int # {/etc/hosts record with internal IP}
[mysqld]
hostname=data2-int # {/etc/hosts record with internal IP}

3) Start Management Node

ndb_mgmd –initial -f /usr/local/mysql/mysql-cluster/config.ini

4) Sync Hosts File

Make sure each node has an /etc/hosts file that matches all other nodes	with the entries you specified in the management node config.ini file.

5) Setup MySQL and Data Nodes

*copy mysql-cluster tarball to each mysql node
*expand tarball in /opt
*groupadd mysql && useradd -g mysql mysql
*rename expanded tarball directory to mysql
*move the mysql directory to /usr/local
*cd /usr/local/mysql
*chown -R mysql:mysql .
*install the database with

scripts/mysql_install_db –user=mysql && chown -R root:mysql . &&
chown -R mysql data && cp support-files/mysql.server /etc/init.d/mysql &&
chmod +x /etc/init.d/mysql && cd /etc/init.d && update-rc.d mysql defaults &&
cd -

*update global profile /etc/profile with MySQL path...

## MySQL Path Update
##
export PATH=$PATH:/usr/local/mysql/bin

*setup /etc/my.cnf

[mysqld]
bind-address=sql1-int
ndbcluster
ndb-connectstring='host=sqlcmgr1-int' ## MGMT-int address
[mysql_cluster]
ndb-connectstring='host=sqlcmgr1-int' ## MGMT-int address

* make the data directory with mkdir /var/lib/mysql
*logout and back in
*start the MySQL database server
*secure the database with mysql_secure_installation and answer all questions with a Y
*register the node with the cluster manager

ndbd --initial

6) Verify Connectivity

On the management node run ndb_mgm to get to the manager shell. Then do


ndb_mgm> SHOW

which should show something similar to


Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 4 node(s)
id=2 @xxx.xxx.xxx.xxx (mysql-5.1.44 ndb-7.1.4, Nodegroup: 0, Master)
id=3 @xxx.xxx.xxx.xxx (mysql-5.1.44 ndb-7.1.4, Nodegroup: 0)
id=4 @xxx.xxx.xxx.xxx (mysql-5.1.44 ndb-7.1.4, Nodegroup: 1)
id=5 @xxx.xxx.xxx.xxx (mysql-5.1.44 ndb-7.1.4, Nodegroup: 1)


[ndb_mgmd(MGM)] 1 node(s)
id=1 @xxx.xxx.xxx.xxx (mysql-5.1.44 ndb-7.1.4)


[mysqld(API)] 4 node(s)
id=6 @xxx.xxx.xxx.xxx (mysql-5.1.44 ndb-7.1.4)
id=7 @xxx.xxx.xxx.xxx (mysql-5.1.44 ndb-7.1.4)
id=8 @xxx.xxx.xxx.xxx (mysql-5.1.44 ndb-7.1.4)
id=9 @xxx.xxx.xxx.xxx (mysql-5.1.44 ndb-7.1.4)

If you have nodes being ejected then you are most likely not giving them enough RAM. NDB is an in
memory database so it needs a lot of RAM. Ideally as much as the size of your database (or in the case of
many, the largest).