Howto setup mysql-cluster (beginners tutorial)

August 12, 2010 39 comments


This HOWTO is designed for a classic setup of two servers behind a load-balancer. The aim is to have true redundancy – either server can be unplugged and yet the site will remain up.


You MUST have a third server as a management node but this can be shut down after the cluster starts. Also note that I do not recommend shutting down the management server (see the extra notes at the bottom of this document for more information). You can not run a MySQL Cluster with just two servers And have true redundancy.

Although it is possible to set the cluster up on two physical servers you WILL NOT GET the ability to “kill” one server and for the cluster to continue as normal. For this you need a third server running the management node.

we are going to talk about three servers:

Servers node01 and node02 will be the two that end up “clustered”. This would be perfect for two servers behind a loadbalancer or using round robin DNS and is a good replacement for replication. Server node03 needs to have only minor changes made to it and does NOT require a MySQL install. It can be a low-end machine and can be carrying out other tasks.

Get the software:

For Generally Available (GA), supported versions of the software, download from

Make sure that you select the correct platform – in this case, “Linux – Generic” and then the correct architecture (for LINUX this means x86 32 or 64 bit).

Note: Only use MySQL Server executables (mysqlds) that come with the MySQL Cluster installation.

STAGE1: Installation of Data and SQL nodes on node01 and node02

On each of the machines designated to host data or SQL nodes(in our case node01 and node02), perform the following steps as the system root user:

  1. create a new mysql user group, and then add a mysql user to this group:
    shell> groupadd mysql

    shell> useradd -g mysql mysql

  2. Change location to the directory containing the downloaded file, unpack the archive, and create a symlink to the mysql directory named mysql. Note that the actual file and directory names vary according to the MySQL Cluster version number.
    shell> cd /var/tmp

    shell> tar -C /usr/local -xzvf mysql-cluster-gpl-7.1.5-linux-x86_64-glibc23.tar.gz

    shell> ln -s /usr/local/mysql-cluster-gpl-7.1.5-linux-i686-glibc23 /usr/local/mysql

    shell> export PATH=$PATH:/usr/local/mysql/bin

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

  3. Change location to the mysql directory and run the supplied script for creating the system databases:
    shell> cd mysql

    shell> ./scripts/mysql_install_db –user=mysql

  4. Set the necessary permissions for the MySQL server and data directories:
    shell> chown -R root .

    shell> chown -R mysql data

    shell> chgrp -R mysql .

  5. Copy the MySQL startup script to the appropriate directory, make it executable, and set it to start when the operating system is booted up:
    shell> cp support-files/mysql.server /etc/init.d/mysql

    shell> chmod +x /etc/init.d/mysql

    shell> update-rc.d mysql defaults

STAGE2: Installation of Management node on node03

Installation of the management node does not require the mysqld binary. Only the MySQL Cluster management server (ndb_mgmd) is required; I assume that you have placed mysql-cluster-gpl-7.1.5-linux-i686-glibc23.tar.gz in /var/tmp.

As system root perform the following steps to install ndb_mgmd and ndb_mgm on the Cluster management node host (node02):

  1. Change location to the /var/tmp directory, and extract the ndb_mgm and ndb_mgmd from the archive into a suitable directory such as /usr/local/bin:
    shell> cd /var/tmp

    shell> tar -zxvf mysql-cluster-gpl-7.1.5-linux-i686-glibc23.tar.gz

    shell> cd /usr/local/mysql-cluster-gpl-7.1.5-linux-i686-glibc23

    shell> cp bin/ndb_mgm* /usr/local/bin

  2. Change location to the directory into which you copied the files, and then make both of them executable:
    shell> cd /usr/local/bin

    shell> chmod +x ndb_mgm*

STAGE3: Configuration of Management node

The first step in configuring the management node is to create the directory in which the configuration file can be found and then to create the file itself. For example (running as root):

shell> mkdir /var/lib/mysql-cluster

shell> cd /var/lib/mysql-cluster

shell> vi config.ini

For our setup, the config.ini file should read as follows:

[ndbd default]




[tcp default]


hostname= # Hostname or IP address of MGM node

datadir=/var/lib/mysql-cluster # Directory for MGM node log files


hostname= # Hostname or IP address

datadir=/usr/local/mysql/data # Directory for this data node’s data files


hostname= # Hostname or IP address

datadir=/usr/local/mysql/data # Directory for this data node’s data files


hostname= # Hostname or IP address


hostname= # Hostname or IP address

STAGE4: Configuration of Data and SQL nodes

The first step in configuring the management node is to create the directory in which the configuration file can be found and then to create the file itself. For example (running as root):

shell> vi /etc/my.cnf

Note :
We show vi being used here to create the file, but any text editor should work just as well.

For each data node and SQL node in our setup, my.cnf should look like this:


port = 3306

socket = /tmp/mysql.sock


port = 3306

socket = /tmp/mysql.sock


ndbcluster # run NDB storage engine

ndb-connectstring= # location of management server


ndb-connectstring= # location of management server

Important :
Once you have started a mysqld process with the NDBCLUSTER and ndb-connectstring parameters in the [mysqld] in the my.cnf file as shown previously, you cannot execute any CREATE TABLE or ALTER TABLE statements without having actually started the cluster. Otherwise, these statements will fail with an error.

STAGE4: Starting the MySQL Cluster

Starting the cluster is not very difficult after it has been configured. Each cluster node process must be started separately, and on the host where it resides. The management node should be started first, followed by the data nodes, and then finally by any SQL nodes:

  1. On the management host(node03), issue the following command from the system shell to start the management node process:
    shell> ndb_mgmd -f /var/lib/mysql-cluster/config.ini –configdir=/var/lib/mysql-clusetr
  2. On each of the Data/SQL node hosts, run these commands to start the ndbd and mysql server process:
    shell> /usr/local/mysql/bin/ndbd

    shell> /etc/init.d/mysql start

If all has gone well, and the cluster has been set up correctly, the cluster should now be operational. You can test this by invoking the ndb_mgm management node client. The output should look like that shown here:

node03:~# 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 @ (mysql-5.1.44 ndb-7.1.5, Nodegroup: 0, Master)

id=3 @ (mysql-5.1.44 ndb-7.1.5, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)

id=1 @ (mysql-5.1.44 ndb-7.1.5)

[mysqld(API)] 2 node(s)

id=4 @ (mysql-5.1.44 ndb-7.1.5)

id=5 @ (mysql-5.1.44 ndb-7.1.5)

STAGE5: Testing the Setup

If you are OK to here it is time to test mysql. On either server node01 or node02 enter the following commands: Note that we have no root password yet:

shell> mysql

create database testdb;

use test;


INSERT INTO cluster_test (i) VALUES (1);

SELECT * FROM cluster_test;

You should see 1 row returned (with the value 1).

If this works, now go to the other server and run the same SELECT and see what you get. Insert from that host and go back to previous host and see if it works. If it works then congratulations!

Save 90% on international calls and sms with Vopium

March 15, 2010 3 comments

If you are living abroad or frequently call your family and friends abroad you can save upto 90% on international calls and sms with Vopium, a Copenhagen – Denmark based company. VopiumVopium provides it’s users variety of simple ways to make international calls and sms via it’s web portal and mobile application, Vopium is a mobile phone application supported on variety of platforms (symbian, iphone, android, java).

Apart from international calls and sms plans, Vopium enables it’s users to talk and chat using Skype, Google Talk, Msn and Yahoo.

Currently Vopium is available in 18 countries including Australia, Belgium, Denmark, France, Finland, Germany, Netherlands, Italy, Norway, Spain, Switzerland, Sweden, UK & USA.

To find out more and get started with Vopium, visit

retrieve skype contact photos using python

September 5, 2009 2 comments

tonight i was looking for a way to retrieve display pictures of my skype contacts from .dbb files and ended up with this small piece of code. i don’t find it much useful though but someone might be interesting so here it is.

#!/usr/bin/env python
# Author Ghulam Mustafa
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License version
## 2 as published by the Free Software Foundation.

## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## General Public License version 2 for more details.

## You should have received a copy of the GNU General Public License
## version 2 along with this program; if not, write to the Free
## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
## MA 02110-1301, USA.

profile = ‘/home/mustafa/.Skype/cyrenity/’

skypefiles = [“user256”, “user1024”, “user4096”, “user16384”, “user32768”, “user65536”,
“profile256”, “profile1024”, “profile4096”, “profile16384”, “profile32768”]

##retrieve contents of skype binary files and store them in a single variable
skbin = []
n = 0
for f in skypefiles:
fil = “%s%s.dbb” % (profile, f)
try: skbin.append(file(fil, “rb”).read())
except: pass
n = n + 1

binary = “”.join(skbin)

## get_icon(username, binary)
## returns
## True if successfull
## None if failed
## -1 if user not found
def get_icon(buddy, binary):
startmark = “\xff\xd8”
endmark = “\xff\xd9”

startfix = 0
endfix = 2

nick_start = “\x03\x10%s” % buddy
nick_end = “0”

nickstart = binary.find(nick_start)
if nickstart == -1: return -1
nickend = binary.find(nick_end, nickstart)
handle = binary[nickstart+2:nickend]
blockstart = binary.rfind(“l33l”, 0, nickend)
imgstart = binary.find(startmark, blockstart, nickend)
imgend = binary.find(endmark, imgstart)

imgstart += startfix
imgend += endfix
if (imgstart < 1): return None ##print "JPG %s from %d to %d" % (handle, imgstart, imgend) jpg = binary[imgstart:imgend] jpgfile = file("%s.jpg" % (handle), "wb") jpgfile.write(jpg) jpgfile.close() return True users = ['cyrenity', 'gmustafa9'] for user in users: status = get_icon(user, binary) if status and status != -1: print "success [%s]" % user else: print "failed[%s] [%s]" % (status, user) [/sourcecode] p.s. you are encouraged to send me update if you found a bug or fix something.🙂

howto install Karaka: xmpp gateway to skype!

July 16, 2009 2 comments

You came here searching for howto install karaka. Vipdia Limited doesn’t tell much on how to setup karaka step by step, yesterday someone asked this question on karaka-discuss mailing list, this post is helpful for you if you are thinking about giving karaka a try.

more here:

update and retrieve twitter timeline from linux shell

January 24, 2009 8 comments

you can update your twitter status and follow feeds using linux shell, this is a quick tip for linux lover’s, this is the reason i prefer linux over other operating systems is it’s total usefullnes,

to post your status on twitter type:

curl -s -u username:password -d status="your_status_message goes here" > /dev/null

replace username, password and message to post with the your own.

to follow feeds from twitter.

curl -s -u username:password | grep title | sed -e 's/]*>//g'

replace username and password with your own. above command will retrieve recent rss entries from your twitter timeline.

one more cool thing you can do with this long command is to enclose it put it in a text file, let’s say “/usr/local/bin/get-twits” and make it exectuable by issuing

chmod a+x /usr/local/bin/get-twits

now open a new terminal windows and type:  watch --interval=60 get-twits

this command will keep your terminal windows updated with recent twitter updates.


cloning harddrives over network

December 30, 2008 6 comments

To clone identical drives in a linux system you can use dd command, dd command makes it really easy.

dd if=/dev/hda of=/dev/hdb

above command will clone hda to hdb (partitions, boot record etc), but what if you have to clone a drive that is not attached to same system?

I found a really interesting way to transfer files over the network simple by using netcat and dd.

  • Boot the machine (where second drive is attached) with a live cd distro like Ubuntu or Knoppix. Setup networking or let the DHCP server assign an ip automatically. My DHCP assigned this machine ip
  • run following command on this machine
    nc -l -p 7777 | dd of=/dev/hdb
    (where /dev/hdb is the target drive)
  • Now come to the machine where you have attached the drive to be cloned and issue following command.
    dd if=/dev/hda | nc 7777
    (/dev/hda is the drive to be cloned)

It will take time (usually several hours) depending on size of the drive. If you are worried about bandwidth you can pipe through gzip to compress and uncompress the streamed data on source and destination machine respectively, to do this you would run following commands.

On target machine:

nc -l -p 7777 | gzip –dfc | dd of=/dev/hdb

And on source machine.

dd if=/dev/hda | gzip –cf | nc 7777

have fun with dd and nc🙂

Categories: linux, ubuntu Tags: , , ,

asterisk 1.2 with realtime ldap driver

December 28, 2008 13 comments

I have created an auto install script based on to install Asterisk 1.2 with ldap realtime driver support (modified original script to enable realtime ldap support).

This script should work almost with any(Redhat, Centos, Mandrake, Debian, Slackware) Linux distro

Before running this script you must install following packages.

For Centos, Redhat:

yum install openldap-devel gcc kernel-devel bison openssl-devel libtermcap-devel ncurses-devel

For Debian, Ubuntu:

apt-get install libldap2-dev build-essential linux-headers-`uname -r` libncurses5-dev libssl-dev

You can download the script from here, simply run the script to start installation process.

download Asterisk schema for OpenLdap here

Installer and installation process is not tested, if you find any problem please let me know.

#Asterisk Download page
#Asterisk Package
#Asterisk Folder
if [ -f /etc/redhat-release ] ; then
elif [ -f /etc/debian_version ] ; then
elif [ -f /etc/SUSE-release ] ; then
elif [ -f /etc/mandrake-release ] ; then
elif [ -f /etc/slackware-release ] ; then
elif [ -f /etc/gentoo-release ] ; then

echo "Downloading and extracting zaptel and asterisk source"
cd /usr/local/src/
if [ ! -e $ZAPPACKAGE ]; then
  wget $ZAPTEL
if [ ! -e $ASTPACKAGE ]; then
  wget $ASTERISK
if [ ! -e $ASTADDONSPACKAGE ]; then
tar -zvxf $ZAPPACKAGE
tar -zvxf $ASTPACKAGE

echo "Installing zaptel"
make clean
make install
cd ..

echo "Installing asterisk"
echo "Downloading patches"
patch -p0<resmkfile.patch
patch -p0<config.c.patch
echo "Downloading Realtime Ldap driver"
cd res
wget $RTLDAP
patch -p0<res_config_ldap.c.patch
cd ../configs
cd ..
make clean
make install
make samples
cp contrib/init.d/rc.$DISTRO.asterisk /etc/init.d/asterisk
cd ..

echo "Installing asterisk-addons"
make clean
make install

echo "Loading ztdummy driver"
modprobe zaptel
modprobe ztdummy

echo "adding rules to /etc/rc.local"

echo "modprobe zaptel
modprobe ztdummy
" >> /etc/rc.local

echo "Downloading open source g729 codec"
cd /usr/lib/asterisk/modules/

echo "Running Asterisk"
/etc/init.d/asterisk start

echo "***********************************************************************"
echo "*             INSTALLATION SUCCESSFUL                                 *"
echo "***********************************************************************"
echo "* You can test if Asterisk installed successfully using               *"
echo "* asterisk -ncrvvv and start configuring your dial plan               *"
echo "***********************************************************************"