<?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; database</title>
	<atom:link href="http://linuxadminzone.com/tag/database/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>Setting up mutiple MySQL Database servers on a single linux machine</title>
		<link>http://linuxadminzone.com/setting-up-mutiple-mysql-database-servers-on-a-single-linux-machine/</link>
		<comments>http://linuxadminzone.com/setting-up-mutiple-mysql-database-servers-on-a-single-linux-machine/#comments</comments>
		<pubDate>Wed, 25 Nov 2009 09:35:53 +0000</pubDate>
		<dc:creator>jagbir</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://linuxadminzone.com/?p=149</guid>
		<description><![CDATA[One of my friend requested to setup two independent MySQL DB servers in his CentOS 5.4 server box. One MySQL (5.0.77) service was already running on the machine, So I had to install another one. Though, I dont recommend running multiple instances on a single server, instead due to cheap hardware you may better setup [...]]]></description>
			<content:encoded><![CDATA[<p>One of my friend requested to setup two independent MySQL DB servers in his CentOS 5.4 server box. One MySQL (5.0.77) service was already running on the machine, So I had to install another one. Though, I dont recommend running multiple instances on a single server, instead due to cheap hardware you may better <a href="http://linuxadminzone.com/setting-up-a-mysql-cluster-7-0-in-redhat-based-linux/">setup a MySQL cluster for best performance</a>. In this case, after initial investigation, I&#8217;ve found that there are few ways to implement this. The idea of using <a href="https://edge.launchpad.net/mysql-sandbox">MySQL Sandbox</a> interested me most. At the end of day, there was two server running simultaneously on the using different ports for connections. Here are the steps, I took to install and configure multiple MySQL servers: </p>
<p>1. Download, compile and install MySQL sandbox:</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>edge.launchpad.net<span style="color: #000000; font-weight: bold;">/</span>mysql-sandbox<span style="color: #000000; font-weight: bold;">/</span>mysql-sandbox-<span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>mysql-sandbox-<span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span>+download<span style="color: #000000; font-weight: bold;">/</span>MySQL-Sandbox-3.0.05.tar.gz
<span style="color: #c20cb9; font-weight: bold;">tar</span> xzf MySQL-Sandbox-3.0.05.tar.gz
<span style="color: #7a0874; font-weight: bold;">cd</span> MySQL-Sandbox-3.0.05
<span style="color: #c20cb9; font-weight: bold;">perl</span> Makefile.PL
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #7a0874; font-weight: bold;">test</span>
<span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

<p>2. Get the latest binary tarball for MySQL server:</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.41-linux-x86_64-icc-glibc23.tar.gz<span style="color: #000000; font-weight: bold;">/</span>from<span style="color: #000000; font-weight: bold;">/</span>http:<span style="color: #000000; font-weight: bold;">//</span>mirror.csclub.uwaterloo.ca<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Here, I&#8217;ve downloaded MySQL 5.1.41 server tarball. Please note that one MySQL was already there on server having different version (ver 5.0.77). For second installation, I&#8217;ve downloaded different version to test out things but for best compatibility, its recommended to download same version. </p>
<p>3. Create new sandbox for single MySQL server. Pls note that you should run following command from a non-root user. Though, in my case, I went ahead and wanted to run command by root user and for that, we must set an environment variable to > 0 value.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">SANDBOX_AS_ROOT</span>=<span style="color: #000000;">1</span>     <span style="color: #666666; font-style: italic;">## no need if your are executing below command from non-root user</span>
make_sandbox  <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.41-linux-x86_64-icc-glibc23.tar.gz</pre></div></div>

<p>4. Sandbox should be created without any glitch. you can go inside the config directory and check that out:</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>root<span style="color: #000000; font-weight: bold;">/</span>sandboxes<span style="color: #000000; font-weight: bold;">/</span>msb_5_1_41</pre></div></div>

<p>Pls replace root here with your normal username in case you created sandbox with non-root user. Also note down that sandbox created new directory using 5_1_41 naming based on your MySQL server version. This is the default behaviour and we can change it via configuration of sandbox. Also note down that the new MySQL server will listen on same port number ie. 5141. </p>
<p>5. Start and use the service of newly installed MySQL server:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>start   <span style="color: #666666; font-style: italic;">## make sure you are in /root/sandboxes/msb_5_1_41 directory</span></pre></div></div>

<p>server should be started. now try to login in MySQL:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>use</pre></div></div>

<p>You should be in MySQL prompt. You can update these scripts (use, start, stop etc.) as per your taste. The default configuration file for MySQL will be in this directory having name as my.sandbox.cnf. You can update this MySQL config file as per your requirements. </p>
<p>Also dont forget to update root password and if you ever encounter situation where you forgot the password, refer <a href="http://linuxadminzone.com/recover-or-reset-root-password-of-mysql-and-postgresql-servers/">these instructions to quickly reset MySQL root password</a>. </p>
<p>Try to connect this MySQl service using your script after making sure that you must specify port 5141 (or whatever you mentioned in configs) while connecting because this service is not listening to default MySQL port 3306. </p>
<p>If you want to use PhpMyAdmin to manage these multiple MySQL services, <a href="http://linuxadminzone.com/install-and-configure-phpmyadmin-to-manage-multiple-mysql-servers/">Here&#8217;s post</a> that will help you configuring PhpMyAdmin. </p>
<p>Other useful posts on MySQL in this blog: </p>
<p>* <a href="http://linuxadminzone.com/setting-up-a-mysql-cluster-7-0-in-redhat-based-linux/">Setup MySQL Cluster in Redhat based Linux</a>.<br />
* <a href="http://linuxadminzone.com/optimize-mysql-on-a-large-database-server/">Optimize a large installation of MySQL</a>.<br />
* <a href="http://linuxadminzone.com/quickly-repair-a-huge-corrupted-or-crashed-table-in-mysql/">Quickly repair a huge corrupted or crashed table</a>.<br />
* <a href="http://linuxadminzone.com/ignore-mysql-error-while-executing-bulk-statements/">How to ignore MySQL errors while executing bulk statements</a><br />
* <a href="http://linuxadminzone.com/optimize-and-fix-mysql-server-running-slow-without-any-load/">Fix MySQL running slow without any know reason</a>. </p>
]]></content:encoded>
			<wfw:commentRss>http://linuxadminzone.com/setting-up-mutiple-mysql-database-servers-on-a-single-linux-machine/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
	</channel>
</rss>

