The aim of this document is to provide knowledge on how to configure a mysql cluster and deploy it for a particular scenario. We use one management node, two data nodes and two sql nodes in this particular deployment. One sql node will have WSO2 ESB running in the same instance and the other sql node will have WSO2 BAM running in the same instance. I use 5 vmware instances for the deployment of my test cluster setup.
I created 5 vmware instances in my desktop machine in order to setup the cluster test environment.

The setup includes one management node and two data nodes and two sql nodes. In one sql node I have WSO2 ESB running and in the other sql node I have WSO2 BAM running.
First let's briefly get clarified with the following terminology
mysql-cluster-gpl-7.1.3-linux-x86_64-glibc23.tar.gz downloadable from mysql site. Although our separate nodes of the cluster need specific software to run the corresponding daemons which are avaiable from mysql site as separate software packages, the tar.gz pack mentioned here contains them all. So we install this pack in all of our cluster nodes in spite of the fact that we may use only part of the software within that cluster. However from my experience with installing the cluster on Redhat linux I'll recommend to install from rpm's instead of tar.gz. Note that rpm's come in separate bundles for management node, sql nodes etc.
group add mysql
useradd -g mysql mysql
tar -zxf mysql-cluster-gpl-7.1.3-linux-x86_64-glibc23.tar.gz
ln -s <your cluster unpack folder>mysql-cluster-gpl-7.1.3-linux-x86_64-glibc23 /usr/local/mysql
cd /usr/local/mysql
scripts/mysql_install_db --user=mysqlNote: Sometimes you may need to provide basedir as well
scripts/mysql_install_db --basedir=/usr/local/mysql-cluster --user=mysql
chown -R root .
chown -R mysql data
chgrp -R mysql .
cp support-files/mysql.server /etc/init.d/
chmod +x /etc/init.d/mysql.server
update-rc.d mysql.server defaultsNote: In red hat linux you need to execute following instead.
cp support-files/mysql.server /etc/rc.d/init.d/
chmod +x /etc/rc.d/init.d/mysql.server
chkconfig --add mysql.server
In the management node we run ndb_mgmd daemon. We also install the cluster management client (ndb_mgm) in this node. ndb_mgm is a command line client tool to execute commands on management node.
tar -zxf mysql-cluster-gpl-7.1.3-linux-x86_64-glibc23.tar.gz
ln -s <your cluster unpack folder>mysql-cluster-gpl-7.1.3-linux-x86_64-glibc23 /usr/local/mysql
cp /usr/local/mysql/bin/ndb_mgm* /usr/local/bin
cd /usr/local/bin
chmod +x ndb_mgm*
Now we have installed the cluster nodes in the machine instances. Lets now move into the configuration part.
We need to configure 5 configuration file for each of our five node instances.
vi /etc/my.cnf
[mysqld] # Options for mysqld process: ndbcluster # run NDB storage engine ndb-connectstring=192.168.0.10 # location of management server [mysql_cluster] # Options for ndbd process: ndb-connectstring=192.168.0.10 # location of management server
We will store the configuration file for management node in /var/lib/mysql-cluster
mkdir /var/lib/mysql-cluster
Create a sample configuration file called config.ini here
[ndbd default]
# Options affecting ndbd processes on all data nodes:
NoOfReplicas=2 # Number of replicas
DataMemory=80M # Number of replicas
IndexMemory=18M # How much memory to allocate for index storage
# For DataMemory and IndexMemory, we have used the
# default values. This is because we don't expand these
testing databases. Check with the memory needed for registry and user_mgmt databases
in real environments.
[tcp default]
# TCP/IP options:
portnumber=2202 # This the default; however, you can use any
# port that is free for all the hosts in the cluster
# Note: It is recommended that you do not specify the port
# number at all and simply allow the default value to be used
# instead
[ndb_mgmd]
# Management process options:
hostname=192.168.0.10 # Hostname or IP address of MGM node
datadir=/var/lib/mysql-cluster # Directory for MGM node log files
[ndbd]
# Options for data node "A": # (one [ndbd] section per data node)
hostname=192.168.0.30 # Hostname or IP address
datadir=/usr/local/mysql/data # Directory for this data node's data files
[ndbd]
# Options for data node "B":
hostname=192.168.0.40 # Hostname or IP address
datadir=/usr/local/mysql/data # Directory for this data node's data files
[mysqld]
# SQL node options:
hostname=192.168.0.20 # Hostname or IP address
# (additional mysqld connections can be
# specified for this node for various
# purposes such as running ndb_restore)
[mysqld]
# SQL node options:
hostname=192.168.0.50
We need to start our cluster in following order
ndb_mgmd -f /var/lib/mysql-cluster/config.ini --configdir=/var/lib/mysql-cluster
According to mysql official cluster documentation you need to run
ndb_mgmd -f /var/lib/mysql-cluster/config.iniBut if your configuration directory is not /usr/local/mysql/mysql-cluster you have to run the command suggested before.
/usr/local/mysql/bin/ndbd
/etc/init.d/mysql.server start
Now you should have an mysql cluster running on your test setup. When running the ndb_mgm management client you should see an output something like this
ndb_mgm -- NDB Cluster -- Management Client -- ndb_mgm> SHOW Connected to Management Server at: localhost:1186 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=2 @192.168.0.30 (Version: 5.1.47-ndb-6.3.39, Nodegroup: 0, Master) id=3 @192.168.0.40 (Version: 5.1.47-ndb-6.3.39, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s) id=1 @192.168.0.10 (Version: 5.1.47-ndb-6.3.39) [mysqld(API)] 2 node(s) id=4 @192.168.0.20 (Version: 5.1.47-ndb-6.3.39) id=5 @192.168.0.50 (Version: 5.1.47-ndb-6.3.39)
Now you can test shutdown and restart of the cluster using following commands.
To shutdown
ndb_mgm -e shutdown
Note that you are running ndb_mgm commands in the management server node, because we installed our ndb_mgm program there.
Now we test restarting the cluster
ndb_mgmd -f /var/lib/mysql-cluster/config.ini --configdir=/var/lib/mysql-cluster
Then on each of data nodes
ndbd
Now after verifying that both data nodes have started, on the sql nodes run
mysqld_safe &
Later if you change configuration files make sure to run the ndb_mgmd node with --reload option.
For more information on MySQL cluster configuration see MySQL cluster documentation [1].
We will configure WSO2 ESB and WSO2 BAM to run with our mysql cluster.
First we need to import the two databases into the mysql cluster. I am not going to elaborate this process here to keep brevity in this document. It is enough to say that I used mysqldump to take a dump of the sufficiently small existing databases of registry and userstore and imported them into the cluster using normal mysql import procedures. Before doing the imports I did the following changes to the database scripts.
Now let's install WSO2 applications into the sql nodes. In one sql node let's install WSO2 ESB and in the other sql node let's install WSO2 BAM server.
To proceed download WSO2 BAM server product from [2] and WSO2 ESB server from [3]. Unarchive them into appropriate directories and configure them to point to the same registry and userstore database by editing the registry.xml and user-mgt.xml files respectively .
Edit repository/conf/registry.xml in both products as following
<dbConfig name="wso2registry">
<url>jdbc:mysql://192.168.0.20:3306/registry?autoReconnect=true</url>
<userName>registry</userName>
<password>password123</password>
<driverName>com.mysql.jdbc.Driver</driverName>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<minIdle>5</minIdle>
<validationQuery>SELECT 1</validationQuery>
</dbConfig>
And configure usr-mgt.xml in both products as following
jdbc:mysql://192.168.0.20:3306/userstore?autoReconnect=true userstore password123 com.mysql.jdbc.Driver 50 60000 5 org.wso2.carbon.user.core.config.multitenancy.SimpleRealmConfigBuilder SELECT 1
Note that ip should change according as where the corresponding sql node installed.
Now start the servers from the corresponding bin directories by executing.
./wso2server.sh
Now you can log into admin console of the bam server and monitor your esb seamlessly.
Following are some facts that should be kept in mind when designing a mysql cluster to be used with WSO2 products
[1]http://dev.mysql.com/doc/mysql-cluster-excerpt/5.1/en/mysql-cluster-multi-computer.html
[2]http://wso2.com/products/business-activity-monitor
[3]http://wso2.com/products/enterprise-service-bus
[4]http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-disk-data-objects.html
[5]http://dev.mysql.com/doc/refman/5.0/en/mysql-cluster-programs-ndb-size-pl.html
Author: Damitha Kumarage
Technical Lead, WSO2 Inc.
| Attachment | Size |
|---|---|
| cluster.png | 12.05 KB |