Skip to main content

MySQL Cluster Set Up


1) Management node

192.168.0.1 -Management (MGM) node
MySQL-ndb-tools-5.1.11-0.glibc23.rpm
MySQL-ndb-management-5.1.11-0.glibc23.rpm
192.168.0.2 - MySQL server (SQL) node 
MySQL-server-5.1.11-0.glibc23.rpm
MySQL-shared-5.1.11-0.glibc23.rpm
MySQL-client-5.1.11-0.glibc23.rpm
192.168.0.3 - Data (NDBD) node "A" 
MySQL-ndb-tools-5.1.11-0.glibc23.rpm
MySQL-client-5.1.11-0.glibc23.rpm
MySQL-ndb-storage-5.1.11-0.glibc23.rpm
MySQL-server-5.1.11-0.glibc23.rpm ( Optional )
192.168.0.4 - Data (NDBD) node "B" 
MySQL-ndb-tools-5.1.11-0.glibc23.rpm
MySQL-client-5.1.11-0.glibc23.rpm
MySQL-ndb-storage-5.1.11-0.glibc23.rpm
MySQL-server-5.1.11-0.glibc23.rpm( Optional )
Step by Step configuration:

Each data node or SQL node requires a my.cnf file that provides two pieces of information:
- A connect string to find the MGM node
- A line which says the MySQL server on this host to run in NDB mode.

The 
my.cnf file for data node (ndb)

For each data node and SQL node in our example setup(i.e. Data (NDBD) node "A" 192.168.0.3 & Data (NDBD) node"B" 192.168.0.4) my.cnf should look like this:
# Options for mysqld process:
[MYSQLD]
ndbcluster # run NDB engine
ndb-connectstring=192.168.0.1 # location of MGM node

# Options for ndbd process:
[MYSQL_CLUSTER]
ndb-connectstring=192.168.0.1 # location of MGM node
Now, you need to start the actual cluster:The Management Node configuration:

You need to create a directory in 
MGM node to in which the configuration file can be found and then to create file it self.
# mkdir /var/lib/mysql-cluster
# cd /var/lib/mysql-cluster
# vi config.ini
# Options affecting ndbd processes on all data nodes:
[NDBD DEFAULT]
NoOfReplicas=2 # Number of replicas


# TCP/IP options:
[TCP DEFAULT]

# Management process options:
[NDB_MGMD]
hostname=192.168.0.1 # Hostname or IP address of MGM node
datadir=/var/lib/mysql-cluster # Directory for MGM node logfiles

# Options for data node "A":
[NDBD]
# (one [NDBD] section per data node)
hostname=192.168.0.3 # Hostname or IP address
DataDir=/var/lib/mysql-cluster # Directory for this data node's datafiles
BackupDataDir=/var/lib/mysql-cluster/backup
#DataMemory=256M # Set this as per your server h/w


# Options for data node "B":
[NDBD]
hostname=192.168.0.4 # Hostname or IP address
DataDir= /var/lib/mysql-cluster # Directory for this data node's datafiles
BackupDataDir=/var/lib/mysql-cluster/backup
#DataMemory = 256M # Set this as per your server h/w

# SQL node options:
[MYSQLD]
hostname=192.168.0.2 # Hostname or IP address
# (additional mysqld connections can be
# specified for this node for various
# purpos 
The following options will be passed to all MySQL clients
[client]
socket=/tmp/mysql.sock
es such as running ndb_restore)
[MYSQLD] # for API
[MYSQLD]
[MYSQLD]
Then, you need to start a cluster which as been configured; each cluster node process must be started separately.

It is recommended that the 
management node be started first, followed by the storage nodes, and then finally by any SQL nodes:

In MGM node (192.168.0.1) pass the following command:
# ndb_mgmd -f /var/lib/mysql-cluster/config.ini
-OR-
# cd /var/lib/mysql-cluster
# ndb_mgmd

You must need to tell mgmd to find the configuration file.

Now, start the 
ndbd process in each data node A and B (192.168.0.3 & 192.168.0.4)
# ndbd --initial

Then, start mysql server process on the SQL node (192.168.0.2)
# service mysql start
Verify that SQL node is started with support of ndb cluster:
# mysql –u root –p
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8 to server version: 5.1.11-beta

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> SHOW ENGINES\G*************************** 10. row ***************************
Engine: ndbcluster
Support: YES
Comment: Clustered, fault-tolerant tables
Transactions: YES
XA: NO
Savepoints: NO
************************************************
If all has been setup correctly, the cluster should be operational.

Type the below mentioned command from Management Node:
# ndb_mgm-- NDB Cluster -- Management Client --ndb_mgm> showConnected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.0.4 (Version: 5.1.11, Node group: 0)
id=3 @192.168.0.3 (Version: 5.1.11, Node group: 0, Master)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.0.1 (Version: 5.1.11)

[mysqld(API)] 3 node(s)
id=4 @192.168.0.2 (Version: 5.1.11)
ndb_mgm>
mysql> SHOW PROCESSLIST \G;*************************** 1. row ***************************
Id: 1
User: system user
Host:
db:
Command: Daemon
Time: 1
State: Waiting for event from ndbcluster
Info: NULL
*************************************************
How to shutdown and restart the cluster:

In MGM node use the below mentioned command:
# ndb_mgm -e shutdown

The above command causes the ndb_mgm, ndb_mgmd, and any ndbd processes to terminate gracefully.

To restart the cluster:
From MGM node (192.168.0.1)
# ndb_mgmd -f /var/lib/mysql-cluster/config.ini

From Data Node (192.168.0.3 & 192.168.0.4)
# ndbd (do not use –initial as it is used only first time)

From SQL node:
# service mysql start

Comments

Popular posts from this blog

About MySQL - Database history Support and Versioning

About MySQL: MySQL was created by a Swedish company. David Axmark (left) and Michael "Monty" Widenius,  MySQL AB, founded by David Axmark, Allan Larsson and Michael "Monty" Widenius. Original development of MySQL by Widenius and Axmark began in 1994. The first version of MySQL appeared on 23 May 1995. It was initially created for personal usage from mSQL based on the low-level language ISAM, which the creators considered too slow and inflexible. They created a new SQL interface, while keeping the same API as mSQL. By keeping the API consistent with the mSQL system, many developers were able to use MySQL instead of the (proprietarily licensed) mSQL antecedent. Support: The MySQL server software itself and the client libraries use dual-licensing distribution. They are offered under GPL version 2, or a proprietary license. MySQL AB owns the copyright to the MySQL source code. This means that MySQL AB can distribute MySQL under several different l...

MySQL thread error code of 1032- Translate binlog completely to avoid error

Could not execute Update_rows event on table db.table; Can't find record in 'table', Error_code: 1032; handler error HA_ERR_KEY_NOT_FOUND; the event's   master log mysql-bin.262297, end_log_pos 1983208 As of my knowledge the causing stop of slave SQL thread error code of 1032, due to lack of sync between Master - Slave. In our case, slave got an Update event form master, but that particular record was not available in the slave. (Of course, that was deleted on Master n Slave separately) You would get this error only if the binlog_format is set to ROW_BASED or MIXED mode. So, now check that particular binlog at that position where replication stopped with this error. When you convert the binlog with mysqlbinlog command, you may see some junk characters   where you were expecting some DMLs which caused the error(In our case its an Update statement). So you can use below command to translate binlog completely: mysqlbinlog --base64-output=DECO...

MySQL Architecture -Client Server Architecture

Client/Server Overview The MySQL database system operates using a client/server architecture. The server is a central program that manages database contents, and client programs connect to the server to retrieve or modify the data. MySQL also includes non-client utility programs and scripts. MySQL Server:   This is the mysqld program that manages database and tables. Most users choose binary MySQL distribution that includes a server ready to run with the capabilities they need, but it's also possible to compile MySQL from source. Client Programs:  These are programs that communicate with the server by sending requests to it over a network connection. The server acts on each request and returns a response to the client. For example you can use the mysql client to send queries to the server, and the server returns the query results. A client program can connect locally to a server running on the same machine or remotely to a server running on a different mac...