Two Nodes mySQL Cluster on CentOS 6.5 (64-bit)

By -
Share:

This blog will describe the process of installing and configuring two nodes mySQL cluster on CentOS 6.5. It is expected that the reader has sufficient knowledge of installing and configuring software on Linux operating system and knowledge of Middleware Technologies.

 Operating System        CentOS    6.5        (64-bit, installed using “Basic Server” and without any database)

Cluster Planning

* Data Nodes                02
* Management Node    01

Note:- Diable iptables and set SELINUX=permissive 

IP Scheme

node1.mydomain.org        DataNode                          192.168.161.186
node2.mydomain.org        DataNode                          192.168.161.189
node3.mydomain.org        Management Node            192.168.161.190
 

Configuration for all nodes

Modify the /etc/hosts file and add entries as follows

vi /etc/hosts

192.168.161.186            node1.mydomain.org        node1
192.168.161.189            node2.mydomain.org        node2
192.168.161.190            node3.mydomain.org        node3          
 

Software for all nodes

Download mysql-cluster-gpl-7.3.8-linux-glibc2.5-x86_64.tar.gz for 64-bit OS from Oracle Website and copy in /tmp directory

cp mysql-cluster-gpl-7.3.8-linux-glibc2.5-x86_64.tar.gz /tmp 

Data Nodes Configuration

 Add mysql user and group

groupadd mysql
useradd -g mysql mysql

or you can simply type

useradd mysql 

Unpack the .tar.gz file and create Symbolic Link

cd /tmp
tar -C /usr/local -zxvf  mysql-cluster-gpl-7.3.8-linux-glibc2.5-x86_64.tar.gz
cd /usr/local
mv mysql-cluster-gpl-7.3.8-linux-glibc2.5-x86_64.tar.gz mysql-cluster

ln -s /usr/local/mysql-cluster /usr/local/mysql

export PATH=$PATH:/usr/local/mysql/bin
echo “export PATH=\$PATH:/usr/local/mysql/bin” >> /etc/bash.bashrc
 

Create System Databases

cd /usr/local/mysql/scripts
./mysql_install_db –user=mysql –basedir=/usr/local/mysql/ –datadir=/home/mysql
 

Copy the start-up scripts

cd /usr/local/mysql/support-files
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql
chkconfig mysql on
 

Modify /etc/my.cnf file

vi /etc/my.cnf

[client]port = 3306
socket = /var/lib/mysql/mysql.sock

[mysqld]port = 3306

#datadir=/var/lib/mysql
datadir=/home/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql

pid-file=/var/run/mysqld/mysqld.pid

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

ndbcluster                                      #Run NDB Storage Engine
ndb-connectstring=192.168.161.190               #Location of Management Server

[mysql_cluster]ndb-connectstring=192.168.161.190               #Location of Management Server

[mysqld_safe]log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

:wq 

Management Node Configuration

Unpack the .tar.gz file and create Symbolic Link

cd /tmp
tar -C /usr/local -zxvf  mysql-cluster-gpl-7.3.8-linux-glibc2.5-x86_64.tar.gz
cd /usr/local
mv mysql-cluster-gpl-7.3.8-linux-glibc2.5-x86_64.tar.gz mysql_cluster

ln -s /usr/local/mysql_cluster /usr/local/mysql 

Setup Node Management utilities

Copy ndb_mgm and ndb_mgmd from /usr/local/mysql/bin into /usr/local/bin

cd /usr/local/mysql/bin
cp ndb_mgm* /usr/local/bin
cd /usr/local/bin
chmod +x ndb_mgm*
 

Create Cluster configuration file

mkdir /var/lib/mysql_cluster
cd /var/lib/mysql_cluster

vi config.ini

[ndbd default]

NoOfReplicas=2
DataMemory=80M
IndexMemory=18M

[tcp default]

[ndb_mgmd]hostname=192.168.161.190        # Hostname or IP address of MGM node
datadir=/var/lib/mysql_cluster  # Directory for MGM node log files

[ndbd]hostname=192.168.161.186        # Hostname or IP address
datadir=/usr/local/mysql/data # Directory for this data node’s data files
#ServerPort=50501

[ndbd]hostname=192.168.161.189        # Hostname or IP address
datadir=/usr/local/mysql/data # Directory for this data node’s data files
#ServerPort=50502

[mysqld]hostname=192.168.161.186         # Hostname or IP address

[mysqld]hostname=192.168.161.189        # Hostname or IP address

:wq 

Starting Management node and Data nodes

On Management Server run following command

cd /usr/local/bin
ndb_mgmd -f /var/lib/mysql_cluster/config.ini –configdir=/var/lib/mysql_cluster/

Following message will appear

image

 Switch to node1.mydomain.org

1. Start the cluster client using following command

/usr/local/mysql/bin/ndbd

Following message will appear

image

2. Now Start the mySQL service

image

Switch to node2.mydomain.org and repeat Step 1 and Step 2

If no error appear, the cluster is up.

Verify Cluster

Switch to node3.mydomain.org and perform commands as shown in below image. The cluster should show both the data nodes

image

Testing the Cluster

Login to mySQL on node1.mydoamin.org and create a database as shown in below picture 

image

Now, login to mySQL on node2.mydoamin.org and type “show databases;” as shown in below picture.

image

If you see the database on node2 as well, then Congratulations.

The setup is complete.

 

In case of any queries please feel free to email info@royalcyber.com

Share: