<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Linux Admin Zone &#187; mysql cluster</title>
	<atom:link href="http://linuxadminzone.com/tag/mysql-cluster/feed/" rel="self" type="application/rss+xml" />
	<link>http://linuxadminzone.com</link>
	<description>Adding more reasons to celebrate Open Source.</description>
	<lastBuildDate>Wed, 09 May 2012 10:17:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Setting up a MySQL cluster 7.0 in Redhat based linux</title>
		<link>http://linuxadminzone.com/setting-up-a-mysql-cluster-7-0-in-redhat-based-linux/</link>
		<comments>http://linuxadminzone.com/setting-up-a-mysql-cluster-7-0-in-redhat-based-linux/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 10:40:05 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[mysql cluster]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=173</guid>
		<description><![CDATA[MySQL Cluster is used to provide high-availability, high-redundancy for the distributed computing environment. You might know that beginning with MySQL 5.1.24, support for the NDBCLUSTER storage engine was removed from the standard MySQL server binaries built by MySQL. Therefore, here I&#8217;m using MySQL Cluster edition instead of MySQL Community edition. I&#8217;m using 3 servers (1 [...]]]></description>
			<content:encoded><![CDATA[<p>MySQL Cluster is used to provide high-availability, high-redundancy for the distributed computing environment. You might know that beginning with MySQL 5.1.24, support for the NDBCLUSTER storage engine was removed from the standard MySQL server binaries built by MySQL. Therefore, here I&#8217;m using MySQL Cluster edition instead of MySQL Community edition. I&#8217;m using 3 servers (1 Management and 2 data) to setup cluster in CentOS 5.4 Linux box. The steps mentioned here can be used for quickly deploying a cluster and worked out for me but no guarantee that this will work for you, So its always advisable to go through official MySQL guide as well for production environment. In case you are also riding on cloud computing wave, I&#8217;ve already blogged way to setup <a href="http://linuxadminzone.com/how-to-setup-mysql-cluster-in-amazon-ec2/">MySQL cluster in Amazon EC2 environment</a>. </p>
<p>1 server will play role of Management server (Example IP: 10.17.250.130) having AMD Opetron 2Ghz with 2 GB of RAM. The load on this server will not be any significant, so a server with low configuration will do the job decently. You can install some monitoring software here to monitor you cluster. </p>
<p>2 data/sql servers (Example IPs: 10.12.248.66, 10.8.75.70) having Intel Xeon 5335 4&#215;2.00GHz with 16 GB of RAM each. These servers will store/replicate data.</p>
<p>I want to say here that we can also set both cluster management service and MySQL service in a single server, even management service with 2 mysql instance in a single box (for more info refer: <a href="http://linuxadminzone.com/setting-up-mutiple-mysql-database-servers-on-a-single-linux-machine/">how to run multiple instances of MySQL in single server</a>) but that&#8217;s definitely NOT recommended and apparently have no use here. Please note that I&#8217;m using only IP addresses while referencing the hosts, you can use the host name as well if you want. </p>
<p>Step 1. Configuration of Management Server</p>
<p>a) MySQL Cluster rpms are available on <a href="http://dev.mysql.com/downloads/cluster/">download site</a> for RedHat linux (on which CentOS is based), so download the rpms for our servers. I&#8217;ve downloaded all rpms except which provides debugging etc.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cd /usr/src</span>
<span style="color: #666666; font-style: italic;"># wget http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.0/MySQL-Cluster-gpl-client-7.0.9-0.rhel5.x86_64.rpm/from/ftp://mysql.mirror.rafal.ca/pub/mysql/</span></pre></div></div>

<p>.. download all others in same way in /usr/src directory. I&#8217;ve downloaded the following rpms:<br />
  MySQL-Cluster-gpl-management-7.0.9-0.rhel5.x86_64.rpm<br />
  MySQL-Cluster-gpl-storage-7.0.9-0.rhel5.x86_64.rpm<br />
  MySQL-Cluster-gpl-client-7.0.9-0.rhel5.x86_64.rpm<br />
  MySQL-Cluster-gpl-server-7.0.9-0.rhel5.x86_64.rpm<br />
  MySQL-Cluster-gpl-tools-7.0.9-0.rhel5.x86_64.rpm<br />
  MySQL-Cluster-gpl-extra-7.0.9-0.rhel5.x86_64.rpm<br />
  MySQL-Cluster-gpl-shared-7.0.9-0.rhel5.x86_64.rpm</p>
<p>Now before installing, make sure you should remove any prior installation of MySQL in the box, if any. Then install the rpms:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># rpm -ivh MySQL-Cluster-gpl-*</span></pre></div></div>

<p>Installation should go smooth. We need to create config.ini in directory /var/lib/mysql-cluster which will acts are configuration file for cluster. Add following configuration directives in the file. Make sure to write IP addresses etc as per your own environment:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cd /var/lib/mysql-cluster</span>
<span style="color: #666666; font-style: italic;"># vi config.ini</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>NDBD DEFAULT<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #007800;">NoOfReplicas</span>=<span style="color: #000000;">2</span>
<span style="color: #007800;">LockPagesInMainMemory</span>=<span style="color: #000000;">1</span>
&nbsp;
<span style="color: #007800;">DataMemory</span>=12288M
<span style="color: #007800;">IndexMemory</span>=1536M
&nbsp;
<span style="color: #007800;">ODirect</span>=<span style="color: #000000;">1</span>
&nbsp;
<span style="color: #007800;">NoOfFragmentLogFiles</span>=<span style="color: #000000;">300</span>
<span style="color: #007800;">MaxNoOfConcurrentOperations</span>=<span style="color: #000000;">100000</span>
<span style="color: #007800;">TimeBetweenGlobalCheckpoints</span>=<span style="color: #000000;">1000</span>
<span style="color: #007800;">TimeBetweenEpochs</span>=<span style="color: #000000;">200</span>
<span style="color: #007800;">DiskCheckpointSpeed</span>=10M
<span style="color: #007800;">DiskCheckpointSpeedInRestart</span>=100M
<span style="color: #007800;">RedoBuffer</span>=32M
<span style="color: #666666; font-style: italic;"># MaxNoOfLocalScans=64</span>
<span style="color: #007800;">MaxNoOfTables</span>=<span style="color: #000000;">1024</span>
<span style="color: #007800;">MaxNofOfOrderedIndexes</span>=<span style="color: #000000;">256</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>MYSQLD DEFAULT<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>NDB_MGMD DEFAULT<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>TCP DEFAULT<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #666666; font-style: italic;"># Managment Server</span>
<span style="color: #007800;">SendBufferMemory</span>=8M
<span style="color: #007800;">ReceiveBufferMemory</span>=8M
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>NDB_MGMD<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #666666; font-style: italic;"># the IP of THIS SERVER</span>
<span style="color: #007800;">HostName</span>=10.17.250.130
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>NDBD<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #666666; font-style: italic;"># the IP of the FIRST SERVER (Data Node)</span>
<span style="color: #007800;">HostName</span>=10.12.248.66
<span style="color: #007800;">DataDir</span>= <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql-cluster
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>NDBD<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #666666; font-style: italic;"># the IP of the SECOND SERVER (Data Node)</span>
<span style="color: #007800;">HostName</span>=10.8.75.70
<span style="color: #007800;">DataDir</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql-cluster
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>MYSQLD<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>MYSQLD<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Please note that values in DataMemory, IndexMemory variables are based in available physical memory in data nodes, in this case 16 GB. To understand the purpose and ideal value of various variable, please check <a href="http://dev.mysql.com/doc/refman/5.1/en/mysql-cluster-config-example.html">MySQL cluster documentation</a>. </p>
<p>b) Start the management service mentioning the config file we just created above:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ndb_mgmd -f /var/lib/mysql-cluster/config.ini </span>
<span style="color: #000000;">2010</span>-02-<span style="color: #000000;">27</span> 02:08:<span style="color: #000000;">49</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>MgmtSrvr<span style="color: #7a0874; font-weight: bold;">&#93;</span> INFO     <span style="color: #660033;">--</span> NDB Cluster Management Server. mysql-5.1.39 ndb-7.0.9b
<span style="color: #000000;">2010</span>-02-<span style="color: #000000;">27</span> 02:08:<span style="color: #000000;">49</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>MgmtSrvr<span style="color: #7a0874; font-weight: bold;">&#93;</span> INFO     <span style="color: #660033;">--</span> The default config directory <span style="color: #ff0000;">'//mysql-cluster'</span> does not exist. Trying to create it...
<span style="color: #000000;">2010</span>-02-<span style="color: #000000;">27</span> 02:08:<span style="color: #000000;">49</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>MgmtSrvr<span style="color: #7a0874; font-weight: bold;">&#93;</span> INFO     <span style="color: #660033;">--</span> Sucessfully created config directory
<span style="color: #000000;">2010</span>-02-<span style="color: #000000;">27</span> 02:08:<span style="color: #000000;">49</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>MgmtSrvr<span style="color: #7a0874; font-weight: bold;">&#93;</span> INFO     <span style="color: #660033;">--</span> Reading cluster configuration from <span style="color: #ff0000;">'/var/lib/mysql-cluster/config.ini'</span></pre></div></div>

<p>Management server configuration is done. We will revisit here after setting up data nodes. </p>
<p>Step 2. Configure data/storage nodes of cluster. You should implement below steps in both of data nodes while taking care of IP address etc.</p>
<p>a) Check that there should be no prior installation of mysql in the server, if there&#8217;s any, remove it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># rpm -qa | grep mysql </span>
mysql-5.0.77-<span style="color: #000000;">4</span>.el5_4.1
&nbsp;
<span style="color: #666666; font-style: italic;"># yum remove mysql</span></pre></div></div>

<p>b) Install cluster (copy rpms you downloaded in management node to here). Again, I&#8217;ve installed everything just for the sake of ease.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># cd /usr/src</span>
<span style="color: #666666; font-style: italic;"># rpm -ivh MySQL-Cluster-gpl-client-7.0.9-0.rhel5.x86_64.rpm MySQL-Cluster-gpl-client-7.0.9-0.rhel5.x86_64.rpm MySQL-Cluster-gpl-extra-7.0.9-0.rhel5.x86_64.rpm MySQL-Cluster-gpl-shared-7.0.9-0.rhel5.x86_64.rpm MySQL-Cluster-gpl-server-7.0.9-0.rhel5.x86_64.rpm MySQL-Cluster-gpl-storage-7.0.9-0.rhel5.x86_64.rpm MySQL-Cluster-gpl-tools-7.0.9-0.rhel5.x86_64.rpm</span></pre></div></div>

<p>c) Time to create my.cnf for MySQL service, this is very basic config file having required entries for Cluster. We have to <a href="http://linuxadminzone.com/optimize-mysql-on-a-large-database-server/">optimize this</a> as we go forward.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># vi /etc/my.cnf</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>client<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #007800;">port</span>=<span style="color: #000000;">3306</span>
<span style="color: #007800;">socket</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>mysql.sock
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>mysqld<span style="color: #7a0874; font-weight: bold;">&#93;</span>
&nbsp;
ndbcluster
<span style="color: #666666; font-style: italic;"># IP address of the cluster management node</span>
ndb-connectstring=10.17.250.130
default-storage-engine=NDBCLUSTER
&nbsp;
<span style="color: #666666; font-style: italic;">#max_connections=341</span>
<span style="color: #666666; font-style: italic;">#query_cache_size=16M</span>
<span style="color: #666666; font-style: italic;">#thread_concurrency = 4</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>mysql_cluster<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #666666; font-style: italic;"># IP address of the cluster management node</span>
ndb-connectstring=10.17.250.130</pre></div></div>

<p>d) Start ndbd service with initial setup. The initial parameters needed only first time while you are starting the service to create cluster file system and other things, subsequently we just need to enter &#8216;ndbd&#8217; to start this.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ndbd --initial </span>
<span style="color: #000000;">2010</span>-02-<span style="color: #000000;">27</span> 02:<span style="color: #000000;">40</span>:<span style="color: #000000;">51</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>ndbd<span style="color: #7a0874; font-weight: bold;">&#93;</span> INFO     <span style="color: #660033;">--</span> Configuration fetched from <span style="color: #ff0000;">'10.17.250.130:1186'</span>, generation: <span style="color: #000000;">1</span></pre></div></div>

<p>e) Start MySQL server now:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># start mysql server</span>
<span style="color: #666666; font-style: italic;"># /etc/init.d/mysql start</span></pre></div></div>

<p>f) Dont forget to set password for root user.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># mysqladmin -u root password 'yourpassword'</span></pre></div></div>

<p>If there&#8217;s any unfortunate event when you forget root password of MySQL, here&#8217;s a <a href="http://linuxadminzone.com/recover-or-reset-root-password-of-mysql-and-postgresql-servers/">quick way to reset that</a>.  </p>
<p>Repeat Step 2 in second data node as well. After completion of this we have done setup of basic MySQL cluster and now its time to check this out. </p>
<p>Step 3. Testing the cluster and other important things to remember </p>
<p>a) Login to management node again and issue ndb_mgm command to open command prompt where we can issue management commands and check status of cluster by issuing &#8216;show&#8217; command:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ndb_mgm</span>
<span style="color: #660033;">--</span> NDB Cluster <span style="color: #660033;">--</span> Management Client <span style="color: #660033;">--</span>
&nbsp;
ndb_mgm<span style="color: #000000; font-weight: bold;">&gt;</span> show
Connected to Management Server at: localhost:<span style="color: #000000;">1186</span>
Cluster Configuration
<span style="color: #660033;">---------------------</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>ndbd<span style="color: #7a0874; font-weight: bold;">&#40;</span>NDB<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>	<span style="color: #000000;">2</span> node<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">id</span>=<span style="color: #000000;">2</span>	<span style="color: #000000; font-weight: bold;">@</span>10.12.248.66  <span style="color: #7a0874; font-weight: bold;">&#40;</span>mysql-5.1.39 ndb-7.0.9, Nodegroup: <span style="color: #000000;">0</span>, Master<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">id</span>=<span style="color: #000000;">3</span>	<span style="color: #000000; font-weight: bold;">@</span>10.8.75.70  <span style="color: #7a0874; font-weight: bold;">&#40;</span>mysql-5.1.39 ndb-7.0.9, Nodegroup: <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>ndb_mgmd<span style="color: #7a0874; font-weight: bold;">&#40;</span>MGM<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>	<span style="color: #000000;">1</span> node<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">id</span>=<span style="color: #000000;">1</span>	<span style="color: #000000; font-weight: bold;">@</span>10.17.250.130  <span style="color: #7a0874; font-weight: bold;">&#40;</span>mysql-5.1.39 ndb-7.0.9<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>mysqld<span style="color: #7a0874; font-weight: bold;">&#40;</span>API<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>	<span style="color: #000000;">2</span> node<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">id</span>=<span style="color: #000000;">4</span>	<span style="color: #000000; font-weight: bold;">@</span>10.12.248.66  <span style="color: #7a0874; font-weight: bold;">&#40;</span>mysql-5.1.39 ndb-7.0.9<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">id</span>=<span style="color: #000000;">5</span>	<span style="color: #000000; font-weight: bold;">@</span>10.8.75.70  <span style="color: #7a0874; font-weight: bold;">&#40;</span>mysql-5.1.39 ndb-7.0.9<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
ndb_mgm<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>You can see that both ndb nodes are connected, 1 management node is there and then 2 mysqld/api nodes there. You can notice that both of data nodes are referred as ndb and mysqld/api nodes because we are running ndb service there as well as mysql service. This will facilitate that our data node also runs mysql service and we can connect to any of these nodes to manage our data. If you refer MySQL cluster documentation, you can see that they are stressing to have 1 mysqld/api node and then 2 data nodes, I dont see any advantage in that. Due to availability of faster hardware and lots of storage, I prefer to keep both data/api in same machine. This will also help in setting up load balancer later to distribute load among available data/mysqld nodes. </p>
<p>Coming back to ndb management prompt, there are several command we can issue here to check/view most stats. like &#8220;ALL REPORT MEMORY&#8221; shows memory usage from all machines.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ndb_mgm<span style="color: #000000; font-weight: bold;">&gt;</span> all report memory
&nbsp;
ndb_mgm<span style="color: #000000; font-weight: bold;">&gt;</span> Node <span style="color: #000000;">2</span>: Data usage is <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">22</span> 32K pages of total <span style="color: #000000;">2560</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Node <span style="color: #000000;">2</span>: Index usage is <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">16</span> 8K pages of total <span style="color: #000000;">2336</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Node <span style="color: #000000;">3</span>: Data usage is <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">22</span> 32K pages of total <span style="color: #000000;">2560</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Node <span style="color: #000000;">3</span>: Index usage is <span style="color: #000000;">0</span><span style="color: #000000; font-weight: bold;">%</span><span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">16</span> 8K pages of total <span style="color: #000000;">2336</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
ndb_mgm<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>there are many commands supported here, which can be found on MySQL cluster official documentation.</p>
<p>b) Testing data nodes and create/importing data</p>
<p>As you already know, cluster uses its own stroage engine, therefore you MUST create tables or alter them if you import from backup etc. to NDBCLUSTER storage engine otherwise tables will not replicate in cluster. (here&#8217;s solution of one issue where we want to <a href=" http://linuxadminzone.com/ignore-mysql-error-while-executing-bulk-statements/">ignore errors coming while backup restore</a>.<br />
) </p>
<p>Login to data node 1 and connect to mysql there:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># mysql -u root -p</span>
&nbsp;
mysql<span style="color: #000000; font-weight: bold;">&gt;</span> create database testdb; 
Query OK, <span style="color: #000000;">1</span> row affected <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.21</span> sec<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
mysql<span style="color: #000000; font-weight: bold;">&gt;</span> use testdb; 
Database changed
&nbsp;
mysql<span style="color: #000000; font-weight: bold;">&gt;</span> create table t <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">seq</span> int, name varchar<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">10</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> engine = ndbcluster; 
Query OK, <span style="color: #000000;">0</span> rows affected <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.28</span> sec<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
mysql<span style="color: #000000; font-weight: bold;">&gt;</span> insert into t values <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">1</span>,<span style="color: #ff0000;">'Mohan'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>; 
Query OK, <span style="color: #000000;">1</span> row affected <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.00</span> sec<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Now login to node 2, access mysql and check data:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># mysql -u root -p</span>
&nbsp;
mysql<span style="color: #000000; font-weight: bold;">&gt;</span> show databases; 
+--------------------+
<span style="color: #000000; font-weight: bold;">|</span> Database           <span style="color: #000000; font-weight: bold;">|</span>
+--------------------+
<span style="color: #000000; font-weight: bold;">|</span> information_schema <span style="color: #000000; font-weight: bold;">|</span>
<span style="color: #000000; font-weight: bold;">|</span> mysql              <span style="color: #000000; font-weight: bold;">|</span>
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #7a0874; font-weight: bold;">test</span>               <span style="color: #000000; font-weight: bold;">|</span>
<span style="color: #000000; font-weight: bold;">|</span> testdb             <span style="color: #000000; font-weight: bold;">|</span>
+--------------------+
<span style="color: #000000;">4</span> rows <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.00</span> sec<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
mysql<span style="color: #000000; font-weight: bold;">&gt;</span> use testdb
Reading table information <span style="color: #000000; font-weight: bold;">for</span> completion of table and column names
You can turn off this feature to get a quicker startup with <span style="color: #660033;">-A</span>
&nbsp;
Database changed
mysql<span style="color: #000000; font-weight: bold;">&gt;</span> show tables; 
+------------------+
<span style="color: #000000; font-weight: bold;">|</span> Tables_in_testdb <span style="color: #000000; font-weight: bold;">|</span>
+------------------+
<span style="color: #000000; font-weight: bold;">|</span> t                <span style="color: #000000; font-weight: bold;">|</span>
+------------------+
<span style="color: #000000;">1</span> row <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.03</span> sec<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
mysql<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">select</span> <span style="color: #000000; font-weight: bold;">*</span> from t; 
+------+-------+
<span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">seq</span>  <span style="color: #000000; font-weight: bold;">|</span> name  <span style="color: #000000; font-weight: bold;">|</span>
+------+-------+
<span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">|</span> Mohan <span style="color: #000000; font-weight: bold;">|</span>
+------+-------+
<span style="color: #000000;">1</span> row <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">set</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">0.00</span> sec<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
mysql<span style="color: #000000; font-weight: bold;">&gt;</span></pre></div></div>

<p>Cluster is working as expected. You can start making use of it. </p>
<p>One thing to note down that if you want to change/add new configs in management server, be sure to stop/start the ndb_mgm daemon and also restart ndbd and mysql services in all data nodes.  </p>
<p>This setup is very basic and needs lots of optimization before deploying in production. One issue here is that the cluster doesn&#8217;t provide any fault tolerance as your application needs to be aware that two mysql nodes are available so in case of one node fails, you must connect to other node in meantime the first node get repaired. </p>
<p>To overcome such issues, and eliminate single point of failure, I&#8217;ve to setup 2 load balancer servers with single virtual IP among them to present single point of contact for application. Currently I&#8217;m testing that thing and will blog the stuff here very soon, till then stay tuned. Please let me know your valuable suggestions/queries regarding this article. </p>
]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/setting-up-a-mysql-cluster-7-0-in-redhat-based-linux/feed/</wfw:commentRss>
		<slash:comments>53</slash:comments>
		</item>
		<item>
		<title>How to setup Mysql Cluster in Amazon EC2</title>
		<link>http://linuxadminzone.com/how-to-setup-mysql-cluster-in-amazon-ec2/</link>
		<comments>http://linuxadminzone.com/how-to-setup-mysql-cluster-in-amazon-ec2/#comments</comments>
		<pubDate>Thu, 31 Jul 2008 07:41:15 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[mysql cluster]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=22</guid>
		<description><![CDATA[This is a quick Howto for setting up MySQL cluster using Amazon EC2 instances. I have used 3 small instances (1 mgmt + 2 data nodes) from RightScale&#8217;s CentOS 5 public image to test things. I&#8217;ve a working cluster using these steps but there&#8217;s no guarantee that these steps works for you as well. Management [...]]]></description>
			<content:encoded><![CDATA[<p>This is a quick Howto for setting up MySQL cluster using Amazon EC2 instances. I have used 3 small instances (1 mgmt + 2 data nodes) from RightScale&#8217;s CentOS 5 public image to test things. I&#8217;ve a working cluster using these steps but there&#8217;s no guarantee that these steps works for you as well.</p>
<p><strong>Management server for cluster:</strong><br />
Although we can set up management server for cluster in one of the data node but we should have a third node as if one of the two MySQL cluster nodes fails, and the management server is not running, then the data on the two cluster nodes will become inconsistent and if the same node fails which have management server, then we will not be able to create another node or configure cluster.</p>
<p>Beginning with MySQL 5.1.6, it is possible to store the non-indexed columns of NDB tables on disk, rather than in RAM as with previous versions of MySQL Cluster. Here I&#8217;m using MySQL 5.1.26-rc as its the latest version while writing this article. </p>
<p>Let&#8217;s dive in practical:<br />
1. Fire up 3 instances and note down their public and private IPs, dedicate roles(mgmt, node) for them and login in management node. Install ncurses library for MySQL compilation requirement:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ yum <span style="color: #c20cb9; font-weight: bold;">install</span> ncurses ncurses-devel</pre></div></div>

<p>2. Download mysql source from its <a href="http://dev.mysql.com/downloads/mysql/5.1.html#source">source download page</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src
$ groupadd mysql
$ useradd <span style="color: #660033;">-g</span> mysql mysql
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>dev.mysql.com<span style="color: #000000; font-weight: bold;">/</span>get<span style="color: #000000; font-weight: bold;">/</span>Downloads<span style="color: #000000; font-weight: bold;">/</span>MySQL-<span style="color: #000000;">5.1</span><span style="color: #000000; font-weight: bold;">/</span>mysql-5.1.26-rc.tar.gz<span style="color: #000000; font-weight: bold;">/</span>from<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ftp</span>:<span style="color: #000000; font-weight: bold;">//</span>mirror.services.wisc.edu<span style="color: #000000; font-weight: bold;">/</span>mirrors<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> xzf mysql-5.1.26-rc.tar.gz
$ <span style="color: #7a0874; font-weight: bold;">cd</span> mysql-5.1.26-rc
<span style="color: #000000; font-weight: bold;">&lt;</span>pre<span style="color: #000000; font-weight: bold;">&gt;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;</span>strong<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000;">3</span>. Compile and <span style="color: #c20cb9; font-weight: bold;">install</span>: <span style="color: #000000; font-weight: bold;">&lt;/</span>strong<span style="color: #000000; font-weight: bold;">&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;</span>pre <span style="color: #007800;">lang</span>=<span style="color: #ff0000;">&quot;bash&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span>
$ .<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--enable-community-features</span> <span style="color: #660033;">--with-mysqld-user</span>=mysql <span style="color: #660033;">--with-mysqlmanager</span> <span style="color: #660033;">--with-plugins</span>=ndbcluster 
$ <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p><strong> 4. Create required directories: </strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>mysql-cluster<span style="color: #000000; font-weight: bold;">/</span>backup
$ <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> mysql:mysql <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql
$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>mysql-cluster
$ <span style="color: #c20cb9; font-weight: bold;">vim</span> config.ini
<span style="color: #7a0874; font-weight: bold;">&#91;</span>NDBD DEFAULT<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #007800;">NoOfReplicas</span>=<span style="color: #000000;">2</span>
<span style="color: #007800;">DataMemory</span>=80M    <span style="color: #666666; font-style: italic;"># How much memory to allocate for data storage</span>
<span style="color: #007800;">IndexMemory</span>=18M   <span style="color: #666666; font-style: italic;"># How much memory to allocate for index storage</span>
<span style="color: #666666; font-style: italic;"># For DataMemory and IndexMemory, we have used the</span>
<span style="color: #666666; font-style: italic;"># default values. Since the &quot;world&quot; database takes up</span>
<span style="color: #666666; font-style: italic;"># only about 500KB, this should be more than enough for</span>
<span style="color: #666666; font-style: italic;"># this example Cluster setup.</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>MYSQLD DEFAULT<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>NDB_MGMD DEFAULT<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>TCP DEFAULT<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #666666; font-style: italic;"># Section for the cluster management node</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>NDB_MGMD<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #666666; font-style: italic;"># IP address of the management node (this system)</span>
<span style="color: #007800;">HostName</span>=10.252.169.x
<span style="color: #666666; font-style: italic;"># Section for the storage nodes</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>NDBD<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #666666; font-style: italic;"># IP address of the first storage node</span>
<span style="color: #007800;">HostName</span>=10.254.237.x
<span style="color: #007800;">DataDir</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>mysql-cluster
<span style="color: #007800;">BackupDataDir</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>mysql-cluster<span style="color: #000000; font-weight: bold;">/</span>backup
<span style="color: #007800;">DataMemory</span>=2048M
<span style="color: #7a0874; font-weight: bold;">&#91;</span>NDBD<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #666666; font-style: italic;"># IP address of the second storage node</span>
<span style="color: #007800;">HostName</span>=10.251.74.x
<span style="color: #007800;">DataDir</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>mysql-cluster
<span style="color: #007800;">BackupDataDir</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>mysql-cluster<span style="color: #000000; font-weight: bold;">/</span>backup
<span style="color: #007800;">DataMemory</span>=2048M
&nbsp;
<span style="color: #666666; font-style: italic;"># one [MYSQLD] per storage node</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>MYSQLD<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>MYSQLD<span style="color: #7a0874; font-weight: bold;">&#93;</span></pre></div></div>

<p>Save and close the file. </p>
<p>5. Start management server. You can also copy ndb_mgmd in system path for easy access.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>mysql-5.1.26-rc<span style="color: #000000; font-weight: bold;">/</span>storage<span style="color: #000000; font-weight: bold;">/</span>ndb<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>mgmsrv<span style="color: #000000; font-weight: bold;">/</span>ndb_mgmd <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>mysql-cluster<span style="color: #000000; font-weight: bold;">/</span>config.ini</pre></div></div>

<p>***</p>
<p><strong>Setup of Node1 and Node2:</strong></p>
<p>1. These settings are identical for Node 1 and Node 2. Let&#8217;s start by adding mysql user and group:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ groupadd mysql 
$ useradd <span style="color: #660033;">-g</span> mysql mysql</pre></div></div>

<p>2. Install required ncurses library for MySQL compilation:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ yum <span style="color: #c20cb9; font-weight: bold;">install</span> ncurses ncurses-devel</pre></div></div>

<p>3. Download, compile and install MySQL:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src
$ <span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>dev.mysql.com<span style="color: #000000; font-weight: bold;">/</span>get<span style="color: #000000; font-weight: bold;">/</span>Downloads<span style="color: #000000; font-weight: bold;">/</span>MySQL-<span style="color: #000000;">5.1</span><span style="color: #000000; font-weight: bold;">/</span>mysql-5.1.26-rc.tar.gz<span style="color: #000000; font-weight: bold;">/</span>from<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">ftp</span>:<span style="color: #000000; font-weight: bold;">//</span>mirror.services.wisc.edu<span style="color: #000000; font-weight: bold;">/</span>mirrors<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>
$ <span style="color: #c20cb9; font-weight: bold;">tar</span> xzf mysql-5.1.26-rc.tar.gz
$ <span style="color: #7a0874; font-weight: bold;">cd</span> mysql-5.1.26-rc
$ .<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--enable-community-features</span> <span style="color: #660033;">--with-mysqld-user</span>=mysql <span style="color: #660033;">--with-mysqlmanager</span> <span style="color: #660033;">--with-plugins</span>=ndbcluster 
$ <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>4. Install initial mysql db:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>mysql-5.1.26-rc<span style="color: #000000; font-weight: bold;">/</span>scripts<span style="color: #000000; font-weight: bold;">/</span>mysql_install_db <span style="color: #660033;">--user</span>=mysql</pre></div></div>

<p>5. Create directories:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>mysql-cluster<span style="color: #000000; font-weight: bold;">/</span>backup
$ <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> mysql:mysql <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql</pre></div></div>

<p>6. Copy init script from mysql source to preferred location:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>mysql-5.1.26-rc<span style="color: #000000; font-weight: bold;">/</span>support-files<span style="color: #000000; font-weight: bold;">/</span>mysql.server <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>
$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">755</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>mysql.server</pre></div></div>

<p>7. Create config file for MySQL:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>my.cnf
<span style="color: #7a0874; font-weight: bold;">&#91;</span>mysqld<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #007800;">datadir</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql
<span style="color: #007800;">socket</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>mysql.sock
<span style="color: #666666; font-style: italic;"># Default to using old password format for compatibility with mysql 3.x</span>
<span style="color: #666666; font-style: italic;"># clients (those using the mysqlclient10 compatibility package).</span>
<span style="color: #007800;">old_passwords</span>=<span style="color: #000000;">1</span>
ndbcluster
<span style="color: #666666; font-style: italic;"># IP address of the cluster management node</span>
ndb-connectstring=10.253.191.210
default-storage-engine=NDBCLUSTER
<span style="color: #666666; font-style: italic;">#Those are for future tuning</span>
<span style="color: #666666; font-style: italic;">#max_connections=341</span>
<span style="color: #666666; font-style: italic;">#query_cache_size=16M</span>
<span style="color: #666666; font-style: italic;">#thread_concurrency = 4</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>client<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #007800;">port</span>=<span style="color: #000000;">3306</span>
<span style="color: #007800;">socket</span>=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>lib<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>mysql.sock
<span style="color: #7a0874; font-weight: bold;">&#91;</span>mysql.server<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #007800;">user</span>=mysql
<span style="color: #007800;">basedir</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>mysql_cluster<span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #666666; font-style: italic;"># IP address of the cluster management node</span>
ndb-connectstring=10.253.191.x
<span style="color: #7a0874; font-weight: bold;">&#91;</span>mysqld_safe<span style="color: #7a0874; font-weight: bold;">&#93;</span>
log-error=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>log<span style="color: #000000; font-weight: bold;">/</span>mysqld.log
pid-file=<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>run<span style="color: #000000; font-weight: bold;">/</span>mysqld<span style="color: #000000; font-weight: bold;">/</span>mysqld.pid</pre></div></div>

<p>Save and close the file.</p>
<p>8. You can also include MySQL directories in your path (Optional).</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #007800;">PATH</span>=<span style="color: #007800;">$PATH</span>:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>libexec
$ <span style="color: #7a0874; font-weight: bold;">export</span> PATH</pre></div></div>

<p>9. Start MySQL Server now:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>mysql.server start</pre></div></div>

<p>10. Repeat these steps in node 2 and start MySQL on both nodes. MySQL should start without any complain. You should also update the password for root user. </p>
<p><strong>Test the cluster:</strong></p>
<p>1. Focus again on Management node to have a look of Cluster connectivity. Open the ndb cluster management console. You should add this directory in PATH or can copy files to your system bin. (I&#8217;m a bit lazy <img src='http://linuxadminzone.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>mysql-5.1.26-rc<span style="color: #000000; font-weight: bold;">/</span>storage<span style="color: #000000; font-weight: bold;">/</span>ndb<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>mgmclient<span style="color: #000000; font-weight: bold;">/</span>ndb_mgm
<span style="color: #660033;">--</span> NDB Cluster <span style="color: #660033;">--</span> Management Client <span style="color: #660033;">--</span></pre></div></div>

<p>2. Issue command to view status of cluster:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">ndb_mgm<span style="color: #000000; font-weight: bold;">&gt;</span> show;
Connected to Management Server at: localhost:<span style="color: #000000;">1186</span>
Cluster Configuration
<span style="color: #660033;">---------------------</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>ndbd<span style="color: #7a0874; font-weight: bold;">&#40;</span>NDB<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>     <span style="color: #000000;">2</span> node<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">id</span>=<span style="color: #000000;">2</span>    <span style="color: #000000; font-weight: bold;">@</span>10.254.237.x  <span style="color: #7a0874; font-weight: bold;">&#40;</span>Version: 5.1.26, Nodegroup: <span style="color: #000000;">0</span>, Master<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">id</span>=<span style="color: #000000;">3</span>    <span style="color: #000000; font-weight: bold;">@</span>10.251.74.x  <span style="color: #7a0874; font-weight: bold;">&#40;</span>Version: 5.1.26, Nodegroup: <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>ndb_mgmd<span style="color: #7a0874; font-weight: bold;">&#40;</span>MGM<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000;">1</span> node<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">id</span>=<span style="color: #000000;">1</span>    <span style="color: #000000; font-weight: bold;">@</span>10.252.169.x  <span style="color: #7a0874; font-weight: bold;">&#40;</span>Version: 5.1.26<span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">&#91;</span>mysqld<span style="color: #7a0874; font-weight: bold;">&#40;</span>API<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>   <span style="color: #000000;">2</span> node<span style="color: #7a0874; font-weight: bold;">&#40;</span>s<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">id</span>=<span style="color: #000000;">4</span>    <span style="color: #000000; font-weight: bold;">@</span>10.254.237.x  <span style="color: #7a0874; font-weight: bold;">&#40;</span>Version: 5.1.26<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">id</span>=<span style="color: #000000;">5</span>    <span style="color: #000000; font-weight: bold;">@</span>10.251.74.x  <span style="color: #7a0874; font-weight: bold;">&#40;</span>Version: 5.1.26<span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #000000; font-weight: bold;">&lt;/</span>code<span style="color: #000000; font-weight: bold;">&gt;</span>
ndb_mgm<span style="color: #000000; font-weight: bold;">&gt;</span> quit</pre></div></div>

<p>Everything should run fine.</p>
<p>3. Jump on the node 1 (or 2, doesnt matter in a cluster <img src='http://linuxadminzone.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  and try to create db, table and issue commands. BE SURE to use <strong>ENGINE=NDBCLUSTER</strong> while table creation else cluster will not work, means data will not be replicated throughtout cluster. Insert some records and check that on other node.<br />
<strong><br />
Conclusion: </strong><br />
It&#8217;s a basic test cluster and I would not recommend it for any production use. In fact, as per one of MySQL expert, &#8220;I would advise you to consider if MySQL Cluster is really a right choice for your project, it&#8217;s often not, probably in 99.9% of the cases I encountered, and does not give expected results&#8221; and when asking the alternate, &#8220;usually some MySQL/InnoDB in Master/Master, Master/Slave setup can work well enough to handle very high rate of transactions.&#8221;</p>
<p>Of course, ther are several considerations you have to take care, like network connectivity between instanes, backup to S3 and automatic promotion of second master in case first one failed. I&#8217;m looking on these and as well as on to setup Master/Master replication with S3 backup. I&#8217;ll post that here, once done.</p>
<p>You may also like to read:<br />
* <a href="http://linuxadminzone.com/install-and-configure-ftp-server-in-amazon-ec2-instance/"> Install and configure FTP server in Amazon Instance </a><br />
* <a href="http://linuxadminzone.com/quick-web-based-php-script-to-check-replication-status-of-mysql/"> Quick and simple php based script to check replication status of multiple MySQL Servers </a><br />
* <a href="http://linuxadminzone.com/setting-up-mutiple-mysql-database-servers-on-a-single-linux-machine/"> Setup multiple MySQL database servers in a single Linux host </a><br />
* <a href="http://linuxadminzone.com/optimize-mysql-on-a-large-database-server/"> Optimize MySQL on a large Database Server </a><br />
* <a href="http://linuxadminzone.com/recover-or-reset-root-password-of-mysql-and-postgresql-servers/"> Recover or reset root password of MySQL and PostgreSQL Servers </a><br />
* <a href="http://linuxadminzone.com/setting-up-a-mysql-cluster-7-0-in-redhat-based-linux/"> How to setup MySQL Cluster 7.0 in Redhat based Linux </a><br />
* <a href="http://linuxadminzone.com/optimize-and-fix-mysql-server-running-slow-without-any-load/"> Optimize and fix MySQL Server running slow without any load </a><br />
* <a href="http://linuxadminzone.com/find-out-the-clients-of-your-mysql-server/"> How to find out the clients connecting to your MySQL server </a><br />
* <a href="http://linuxadminzone.com/quickly-repair-a-huge-corrupted-or-crashed-table-in-mysql/"> Quickly repair huge corrupted or crashed table in MySQL </a><br />
* <a href="http://linuxadminzone.com/install-and-configure-phpmyadmin-to-manage-multiple-mysql-servers/"> Install and configure PhpMyAdmin to manage multiple MySQL Servers </a> </p>
]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/how-to-setup-mysql-cluster-in-amazon-ec2/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
	</channel>
</rss>

