<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>uzyn.com</title>
	
	<link>http://uzyn.com</link>
	<description>web development, cloud computing, security</description>
	<lastBuildDate>Tue, 07 Feb 2012 11:59:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/uzyn" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="uzyn" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Web-based global live traffic visualization</title>
		<link>http://uzyn.com/web-based-global-live-traffic-visualization/</link>
		<comments>http://uzyn.com/web-based-global-live-traffic-visualization/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 11:59:59 +0000</pubDate>
		<dc:creator>uzyn</dc:creator>
				<category><![CDATA[Showcase]]></category>
		<category><![CDATA[cakephp]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[google earth]]></category>
		<category><![CDATA[google earth api]]></category>
		<category><![CDATA[idm]]></category>
		<category><![CDATA[ijam]]></category>
		<category><![CDATA[live traffic]]></category>
		<category><![CDATA[mda]]></category>
		<category><![CDATA[singapore]]></category>
		<category><![CDATA[site traffic]]></category>
		<category><![CDATA[traffic]]></category>
		<category><![CDATA[visualization]]></category>

		<guid isPermaLink="false">http://uzyn.com/?p=246</guid>
		<description><![CDATA[It has been awhile, but I have just noticed this video of a project I&#8217;ve done back in late 2008 for Media Development Authority of Singapore (MDA). The visualization shows live traffic[1] aggregated from various projects that are funded by MDA under their Interactive Digital Media funding program. The visualization is web-based. Its front-end is [...]]]></description>
			<content:encoded><![CDATA[<p>It has been awhile, but I have just noticed this video of a project I&#8217;ve done back in late 2008 for <a href="http://www.mda.gov.sg/">Media Development Authority of Singapore</a> (MDA).</p>
<p><iframe width="640" height="480" src="http://www.youtube.com/embed/KEtvq8-IDwM" frameborder="0" allowfullscreen></iframe></p>
<p>The visualization shows live traffic<sup>[1]</sup> aggregated from various projects that are funded by MDA under their <a href="http://www.idm.sg/">Interactive Digital Media</a> funding program.</p>
<p>The visualization is web-based. Its front-end is built with a lot of JavaScript goodness and <a href="https://developers.google.com/earth/">Google Earth API</a>; backend is powered by <a href="http://cakephp.org">CakePHP</a> with the data stream aggregated from various sites&#8217; access logs and <a href="http://www.google.com/analytics/">Google Analytics</a>.</p>
<p>I had some thought, at that time, to open-source it I did not do it in the end. </p>
<div class="ref-notes">
<sup>[1]</sup> There are some amount of simulation involved, but data shown is indicative of actual data.
</div>
<img src="http://feeds.feedburner.com/~r/uzyn/~4/7pcZ3Dg5ki0" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://uzyn.com/web-based-global-live-traffic-visualization/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>My top albums of 2011</title>
		<link>http://uzyn.com/my-top-albums-of-2011/</link>
		<comments>http://uzyn.com/my-top-albums-of-2011/#comments</comments>
		<pubDate>Fri, 06 Jan 2012 15:30:50 +0000</pubDate>
		<dc:creator>uzyn</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[music]]></category>
		<category><![CDATA[progressive rock]]></category>

		<guid isPermaLink="false">http://uzyn.com/?p=226</guid>
		<description><![CDATA[My top albums (mainly progressive rock) of 2011: The Devin Townsend Project &#8212; Ghost Opeth &#8212; Heritage Anathema &#8212; Falling Deeper Björk &#8212; Biophilia Aaron Lewis &#8212; Town Line Steven Wilson &#8212; Grace For Drowning Blackfield &#8212; Welcome to My DNA Pain of Salvation &#8212; Road Salt Two Dream Theater &#8212; A Dramatic Turn of [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://uzyn.com/wp-content/uploads/2012/01/SymphonyX_Iconoclast_cover-300x272.jpg" alt="" title="Symphont X - Iconoclast" width="300" height="272" class="alignright size-medium wp-image-243" /><br />
My top albums (mainly progressive rock) of 2011:</p>
<ol>
<li value="10">The Devin Townsend Project &mdash; Ghost</li>
<li value="9">Opeth &mdash; Heritage</li>
<li value="8">Anathema &mdash; Falling Deeper</li>
<li value="7">Björk &mdash; Biophilia</li>
<li value="6">Aaron Lewis &mdash; Town Line</li>
<li value="5">Steven Wilson &mdash; Grace For Drowning</li>
<li value="4">Blackfield &mdash; Welcome to My DNA</li>
<li value="3">Pain of Salvation &mdash; Road Salt Two</li>
<li value="2">Dream Theater &mdash; A Dramatic Turn of Events</li>
<li value="1">Symphony X &mdash; Iconoclast</li>
</ol>
<p>And it&#8217;s the year I finally discovered <a href="http://www.blazemonger.com/GG/">Gentle Giant</a>, probably the most creative progressive rock band ever!</p>
<img src="http://feeds.feedburner.com/~r/uzyn/~4/2SA-TDy81DI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://uzyn.com/my-top-albums-of-2011/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hash as filename</title>
		<link>http://uzyn.com/hash-as-filename/</link>
		<comments>http://uzyn.com/hash-as-filename/#comments</comments>
		<pubDate>Tue, 13 Sep 2011 09:16:36 +0000</pubDate>
		<dc:creator>uzyn</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[base-16]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[hex]]></category>
		<category><![CDATA[hexadecimal]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[storage]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://uzyn.com/?p=196</guid>
		<description><![CDATA[md5, sha1, etc are very handy tools for programmers to generate hashed strings from random or fixed keys. A lot of the times, we simply store these hashes directly into databases, setting the field data type as string, or use the hashes as filenames (handy for creating cache files) or as part of URL. While [...]]]></description>
			<content:encoded><![CDATA[<p><code>md5</code>, <code>sha1</code>, etc are very handy tools for programmers to generate hashed strings from random or fixed keys.</p>
<p>A lot of the times, we simply store these hashes directly into databases, setting the field data type as string, or use the hashes as filenames (handy for creating cache files) or as part of URL.</p>
<p>While there is nothing wrong in that, sometimes it bothers me that hashes, which are hexadecimal (base-16) are stored in memory/storage spaces that are of larger base, eg. string-typed field in ASCII encoding can store 2<sup>8</sup> different character types (essentially making it base-256), in UTF-8: base-(2<sup>32</sup>), used as filenames in case-insensitive Non-POSIX Win32 NTFS: whatever base that is consisted of possible UTF-16 characters.</p>
<p>To improve on that, translate the hash, usually of hexadecimal, into numbers/strings with larger character sets. One of the easiest and handiest way to achieve this in PHP is through the use of <code><a href="http://php.net/base_convert">base_convert</a></code> function.</p>
<pre class="brush: php; title: ; notranslate">
$nicerHash = base_convert($hash, 16, 36);

// gets us '9ou4tb14lz40cokgw4ocoscs8'
// from 'a3aca2964e72000eea4c56cb341002a4'
</pre>
<p>Unfortunately, as the largest-supported base of <code>base_convert</code> is only 36, this still does not give you the full range of supported character sets for most cases. It does, however, help in improving character-set utilization, shortening the resulting hash&#8217;s string length and at the same time, making the hash appears more human-friendly (at least to me with the fact my filenames are not all consists of only 0-f).</p>
<p>For better conversion of bases in PHP, you&#8217;ll have to write your own translation function. Do take note, however, that not all UTF-8 characters are printable and may result in corruption when transported through certain mediums, say as part of URL; for alpha characters, the letter case may also get lost in transition.</p>
<img src="http://feeds.feedburner.com/~r/uzyn/~4/boDczfljJsw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://uzyn.com/hash-as-filename/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Connect to IBM DB2 on PHP via ODBC</title>
		<link>http://uzyn.com/how-to-connect-to-db2-on-php-via-odbc/</link>
		<comments>http://uzyn.com/how-to-connect-to-db2-on-php-via-odbc/#comments</comments>
		<pubDate>Mon, 23 May 2011 11:15:58 +0000</pubDate>
		<dc:creator>uzyn</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[db2]]></category>
		<category><![CDATA[ibm]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[odbc]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[php4]]></category>
		<category><![CDATA[php5]]></category>
		<category><![CDATA[unixodbc]]></category>

		<guid isPermaLink="false">http://uzyn.com/?p=172</guid>
		<description><![CDATA[This was done and tested on a Linux (CentOS) system running PHP 4. Configure PHP with ODBC support. You should check that it is successfully installed by doing phpinfo(). Obtain the latest DB2 ODBC driver from IBM. You can download it from here. Lookout for Driver for ODBC and CLI. Untar it at a dir. [...]]]></description>
			<content:encoded><![CDATA[<p>This was done and tested on a Linux (<strong>CentOS</strong>) system running <strong>PHP 4</strong>. </p>
<ol>
<li>Configure PHP with ODBC support.
<pre class="brush: bash; title: ; notranslate">yum install php4-odbc unixODBC</pre>
<p> You should check that it is successfully installed by doing <a href="http://php.net/phpinfo">phpinfo()</a>.</li>
<li>Obtain the latest DB2 ODBC driver from IBM. You can <a href="https://www-304.ibm.com/support/docview.wss?rs=4020&#038;uid=swg27016878">download it from here</a>. Lookout for <strong>Driver for ODBC and CLI</strong>.</li>
<li>Untar it at a dir. I chose <code>/opt/db2cli</code>.</li>
<li>Edit <code>odbcinst.ini</code> to define a new ODBC connection. The file should be located at <code>/etc/odbcinst.ini</code>. Add the following:
<pre class="brush: plain; title: ; notranslate">[DB2]
Description     = DB2 Driver
Driver      	= /opt/db2cli/lib/libdb2.so
FileUsage       = 1
DontDLClose     = 1</pre>
</li>
<li>You can now connect to IBM DB2 on PHP via ODBC. You can use the following PHP script to test the connection:
<pre class="brush: php; title: ; notranslate">$database = 'DBNAME';
$hostname = 'HOST';
$port = 'PORT';
$user = 'USERNAME';
$password = 'PASSWORD';
$driver = 'DB2';
$conn_string = &quot;DRIVER=\{$driver};DATABASE=$database;HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;&quot;;

if (!$db = odbc_connect ($conn_string, $user, $password)) echo 'Error!';
else echo 'Success!';

odbc_close($db);</pre>
</li>
</ol>
<p>You can read about more information on PHP ODBC functions via <a href="http://php.net/manual/en/ref.uodbc.php">PHP&#8217;s Manual</a>. </p>
<p>Though this guide is based on PHP4, this should also work for PHP5 with some minor modifications. Otherwise, you can also check out <a href="http://php.net/manual/en/book.ibm-db2.php">DB2 extension of PHP</a>.</p>
<p class="post-footer">
U-Zyn tweets about PHP, database, cloud computing and how to procrastinate productively at <a href="http://twitter.com/uzyn">@uzyn</a>.</p>
<img src="http://feeds.feedburner.com/~r/uzyn/~4/VmdEg24SJfw" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://uzyn.com/how-to-connect-to-db2-on-php-via-odbc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lack of keyboard shortcuts in Apple applications</title>
		<link>http://uzyn.com/lack-of-keyboard-shortcuts-in-apple-applications/</link>
		<comments>http://uzyn.com/lack-of-keyboard-shortcuts-in-apple-applications/#comments</comments>
		<pubDate>Fri, 11 Mar 2011 15:52:53 +0000</pubDate>
		<dc:creator>uzyn</dc:creator>
				<category><![CDATA[UX]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[ui]]></category>
		<category><![CDATA[ux]]></category>

		<guid isPermaLink="false">http://uzyn.com/?p=167</guid>
		<description><![CDATA[One thing I&#8217;ve always really hate about Apple softwares are the lack of keyboard shortcuts on a lot of things. Today, I&#8217;m looking for a shortcut for editing of a cell in Numbers (a spreadsheet application in iWork suite) and this is what it says: &#8220;Edit content in cell: Select cell and click once, twice, [...]]]></description>
			<content:encoded><![CDATA[<p>One thing I&#8217;ve always really hate about Apple softwares are the lack of keyboard shortcuts on a lot of things. </p>
<p>Today, I&#8217;m looking for a shortcut for editing of a cell in Numbers (a spreadsheet application in iWork suite) and this is what it says: </p>
<blockquote><p>&#8220;Edit content in cell:<br />
Select cell and click once, twice, or three times&#8221;</p></blockquote>
<p>Source: <a href="http://www.apple.com/support/numbers/shortcuts/">http://www.apple.com/support/numbers/shortcuts/</a></p>
<p><em>Clicking</em> (with a mouse) is not a <em>keyboard</em> shortcut, Apple!</p>
<img src="http://feeds.feedburner.com/~r/uzyn/~4/p3MsRC2quNg" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://uzyn.com/lack-of-keyboard-shortcuts-in-apple-applications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to convert a char column to numeric in PostgreSQL</title>
		<link>http://uzyn.com/how-to-convert-a-char-column-to-numeric-in-postgresql/</link>
		<comments>http://uzyn.com/how-to-convert-a-char-column-to-numeric-in-postgresql/#comments</comments>
		<pubDate>Thu, 27 Jan 2011 10:30:30 +0000</pubDate>
		<dc:creator>uzyn</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://uzyn.com/?p=155</guid>
		<description><![CDATA[Attempting to ALTER a char column directly to numeric will result in the following error: ERROR: column &#8220;COL_NAME&#8221; cannot be cast to type numeric Here&#8217;s how to get around that: Verify data is ok &#038; delete away the old column. I blog about PostgreSQL and other Linux sys admin stuffs on my Twitter (@uzyn) and [...]]]></description>
			<content:encoded><![CDATA[<p>Attempting to ALTER a char column directly to numeric will result in the following error:<br />
ERROR:  column &#8220;COL_NAME&#8221; cannot be cast to type numeric</p>
<p>Here&#8217;s how to get around that:</p>
<pre class="brush: sql; title: ; notranslate">
alter table TABLE_NAME add column COL_NAME_TEMP numeric(8,0);
update TABLE_NAME set COL_NAME_TEMP = CAST(COL_NAME as numeric);
alter table TABLE_NAME rename COL_NAME to COL_NAME_OLD;
alter table TABLE_NAME rename COL_NAME_TEMP to COL_NAME;
</pre>
<p>Verify data is ok &#038; delete away the old column.</p>
<pre class="brush: sql; title: ; notranslate">
alter table TABLE_NAME drop COL_NAME_OLD;
</pre>
<div class="post-footer">
I blog about PostgreSQL and other Linux sys admin stuffs on my Twitter (<a href="http://twitter.com/uzyn">@uzyn</a>) and this blog (<a href="http://uzyn.com/feed">subscribe</a>).
</div>
<img src="http://feeds.feedburner.com/~r/uzyn/~4/c5e4lH7V1YU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://uzyn.com/how-to-convert-a-char-column-to-numeric-in-postgresql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Running MySQL on EC2 ephemeral storage while maintaining consistency</title>
		<link>http://uzyn.com/running-mysql-on-ec2-ephemeral-storage-while-maintaining-consistency/</link>
		<comments>http://uzyn.com/running-mysql-on-ec2-ephemeral-storage-while-maintaining-consistency/#comments</comments>
		<pubDate>Mon, 13 Dec 2010 17:11:36 +0000</pubDate>
		<dc:creator>uzyn</dc:creator>
				<category><![CDATA[Cloud computing]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[cloud computing]]></category>
		<category><![CDATA[ebs]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[storage]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://uzyn.com/?p=64</guid>
		<description><![CDATA[&#160;&#160;&#160;&#160; Note: This article is written based on Ubuntu Linux 9.10 Server (Karmic Koala), having previously set up MySQL to run on EBS based on]]></description>
			<content:encoded><![CDATA[<p class="center"><img src="http://uzyn.com/wp-content/uploads/2010/12/logo_aws.gif" alt="" title="Amzon Web Services" width="164" height="60" class="size-full wp-image-136" /> &nbsp;&nbsp;&nbsp;&nbsp; <img src="http://uzyn.com/wp-content/uploads/2010/12/mysql.jpg" alt="" title="MySQL" width="116" height="60" class="size-full wp-image-142" /></p>
<p><strong>Note</strong>: This article is written based on Ubuntu Linux 9.10 Server (Karmic Koala), having previously set up MySQL to run on EBS based on <a href="<a href="http://aws.amazon.com/articles/1663?_encoding=UTF8&#038;jiveRedirect=1">Eric Hammond&#8217;s guide</a>.<br />
Same idea should still applies on other Linux distributions, especially newer versions of Ubuntu Linux.</p>
<h3>Overview</h3>
<p>Since the introduction of <a href="http://aws.amazon.com/ebs/">Elastic Block Storage</a> (EBS) on <a href="http://aws.amazon.com/ec2">Elastic Compute Cloud</a> (EC2), it is recommended to run MySQL on EC2 with EBS for both consistency and easy backup. </p>
<p>If you are looking for tutorial on how to run MySQL on EBS, Eric Hammond has <a href="http://aws.amazon.com/articles/1663?_encoding=UTF8&#038;jiveRedirect=1">a guide on how to get that set up</a>.</p>
<p>As I/O requests on EC2 is chargeable (at a rate of $0.10 per 1 million requests), it can get costly pretty quickly having MySQL running on EBS with the growth of database size. It got quite out of hand that at some point in time, for one of my instances, the I/O for EBS alone was costing 3x more than the compute time charges for the particular EC2 instance!</p>
<p>That was when I knew I cannot keep MySQL running on EBS for too long before it got me broke.</p>
<h3>General Idea</h3>
<p>The general idea is to have MySQL run on ephemeral storage of EC2, which comes in rather large volume and most importantly, I/O is not chargeable. Ephemeral storage, however, is known as such because it is not consistent. If an instance is terminated or crashes, data on ephemeral storage will be irrecoverable.</p>
<p>To overcome that and achieve consistency, we will have to rely on EBS. As I/O intensive operations for MySQL are mainly during sorting, especially during SELECT queries, the point will then be to have I/O heavy operations done on ephemeral storage while using EBS solely for maintaining consistency.</p>
<p>Here&#8217;s one way on how we can achieve that:</p>
<ol>
<li>Set up 2 MySQL servers with one being master and the other being slave, replicating the master.</li>
<li>Master server runs on ephemeral storage. Applications will be connecting directly to the master. </li>
<li>Replication slave runs on EBS.</li>
</ol>
<p>You can either launch 2 EC2 instances, having master and slave on different instances, or for the this tutorial, we will be setting them up on a single EC2 instance for cost-saving purposes.</p>
<p class="ref-notes">
Guide is inspired from <a href="http://ubuntuforums.org/showthread.php?t=1154296">http://ubuntuforums.org/showthread.php?t=1154296</a> with improvements and adaptations for EC2.
</p>
<h3>Converting from single MySQL server to dual MySQL servers on a single EC2 instance</h3>
<p>Assuming we already have a MySQL server with setup similar to Eric Hammond&#8217;s tutorial.<br />
Data directory (lib): <code>/vol/lib/</code></p>
<p>In order to allow mysqld_multi script to shutdown the MySQL server, we should run this SQL on the current MySQL installation before stopping it.</p>
<pre class="brush: sql; title: ; notranslate">GRANT SHUTDOWN ON *.* TO 'multi_admin'@'localhost' IDENTIFIED BY 'SOME_SECURE_PASSWORD';</pre>
<p>Stop MySQL</p>
<pre class="brush: bash; title: ; notranslate">sudo /etc/init.d/mysql stop</pre>
<p>Backup the current mysql init.d script and replacing with mysqld_multi.server</p>
<pre class="brush: bash; title: ; notranslate">sudo mv /etc/init.d/mysql /etc/init.d/mysql_mono.server

sudo cp /usr/share/mysql/mysqld_multi.server /etc/init.d/mysql</pre>
<p>Edit <code>/etc/init.d/mysql</code>, with any text editor like <code>nano</code>:</p>
<p>Find and replace</p>
<pre class="brush: plain; title: ; notranslate">basedir=/usr/local/mysql
bindir=/usr/local/mysql/bin</pre>
<p>with</p>
<pre class="brush: plain; title: ; notranslate">basedir=/usr
bindir=/usr/bin</pre>
<p>Copy data from EBS-backed stroage at <code>/vol/lib/mysql</code> to ephemeral storage at <code>/mnt/mysql/lib</code>, leaving the data on EBS-backed storage to be used by the replication slave.</p>
<pre class="brush: bash; title: ; notranslate">sudo mkdir /mnt/mysql
sudo cp -pr /vol/lib/mysql /mnt/mysql/lib
sudo mv /vol/lib /vol/lib-repli </pre>
<p>Edit <code>/etc/fstab</code> to change the mount configuration of <code>/var/lib/mysql</code> from <code>/vol/lib/mysql</code> to <code>/mnt/mysql/lib</code>:</p>
<pre class="brush: bash; title: ; notranslate">sudo umount /var/lib/mysql

# Edit /etc/fstab with your favorite text editor and make the replacement as described above

# Save and remount
sudo mount /var/lib/mysql
</pre>
<p>Next, configuring <code>my.cnf</code>. Backing up existing one and editing <code>/etc/mysql/my.cnf</code> with text editor.</p>
<pre class="brush: bash; title: ; notranslate">sudo cp -p /etc/mysql/my.cnf /etc/mysql/my.cnf.mono</pre>
<p>When editing <code>/etc/mysql/my.cnf</code>, here are some things to change and take note of:</p>
<ul>
<li>Rename <code>[mysql]</code> to <code>[mysqld1]</code></li>
<li>Copy the whole block of configs in <code>[mysqld1]</code> section, change the section name into <code>[mysqld2]</code> and paste it right below <code>[mysqld1]</code> section</li>
<li>For <code>[mysqld1]</code>, search and edit (uncomment if they are commented) the following:<br />
(very few changes as we are keeping it as close as possible to the earlier mono configuration)</p>
<pre class="brush: plain; highlight: [1]; title: ; notranslate">[mysqld1]
server-id = 1
log_bin = /var/log/mysql/mysql1-bin.log</pre>
</li>
<li>For <code>[mysqld2]</code>, search and edit (uncomment if they are commented) the following:
<pre class="brush: plain; highlight: [1]; title: ; notranslate">[mysqld2]
pid-file = /var/run/mysqld2.pid
socket = /var/run/mysqld2.sock
port = 3307
server-id = 2
datadir = /vol/lib-repli/mysql
log = /var/log/mysql/mysql2.log
</pre>
</li>
</ul>
<p>Before we can start mysql, we will also need to update AppArmor to grant permissions to mysqld to update the files for mysqld2.<br />
Backup, edit and add insert the following lines to <code>/etc/apparmor.d/usr.sbin.mysqld</code> before the last line with the closing curly bracket ( <code>}</code> ):</p>
<pre class="brush: plain; title: ; notranslate">/vol/lib-repli/ r,
/vol/lib-repli/** rwk,
/var/run/mysqld/mysqld2.pid w,
/var/run/mysqld/mysqld2.sock w,</pre>
<p>Restart AppArmor</p>
<pre class="brush: bash; title: ; notranslate">sudo /etc/init.d/apparmor restart</pre>
<p>And now start MySQL</p>
<pre class="brush: bash; title: ; notranslate">sudo /etc/init.d/myql start</pre>
<p>If everything is set up correctly, MySQL instances will silently run. You can verify that by invoking:</p>
<pre class="brush: bash; title: ; notranslate">ps aux | grep mysql | grep -v grep</pre>
<p>You should see 2 instances of MySQL running:<br />
<strong>Master</strong>, with server ID 1, running on ephemeral storage, and on the default MySQL port 3306.<br />
<strong>Slave</strong>, with server ID 2, running on EBS, and on port 3307.</p>
<p>Before starting up application that modifies/writes to MySQL, we should set up replication.</p>
<h3>Setting up MySQL master-slave replication</h3>
<p>Edit <code>/etc/mysql/my.cnf</code> once again to configure replication. </p>
<p>At <code>[mysqld1]</code>, enter the list of databases you would like to replicate under <code>binlog-do-db</code>. If there are multiple databases, you can list them under multiple <code>binlog-do-db</code>. For the purpose of this tutorial, let&#8217;s assume we would like to set up replication for exampledb1 and exampledb2.</p>
<pre class="brush: plain; highlight: [1]; title: ; notranslate">[mysqld1]
binlog-do-db=exampledb1
binlog-do-db=exampledb2
</pre>
<p>At <code>[mysqld2]</code>, enter the same list of databases as above under <code>replicate-do-db</code></p>
<pre class="brush: plain; highlight: [1]; title: ; notranslate">[mysqld2]
replicate-do-db=exampledb1
replicate-do-db=exampledb2
</pre>
<p>Restart MySQL:</p>
<pre class="brush: bash; title: ; notranslate">sudo /etc/init.d/mysql restart</pre>
<p>Run these SQL queries on master (port 3306):</p>
<pre class="brush: sql; title: ; notranslate">
# Just to be sure that we are on master server. We should be getting 1.
SELECT @@server_id; 

GRANT REPLICATION SLAVE ON *.* TO 'replslave'@'localhost' IDENTIFIED BY 'YOUR_OWN_CHOSEN_SLAVE_PASSWORD';

FLUSH PRIVILEGES;
SHOW MASTER STATUS;
# Note down the results of this, we will need them as we set up replication slave
</pre>
<p>Run these SQL queries on slave (port 3307):</p>
<pre class="brush: sql; title: ; notranslate">
# Just to be sure that we are on slave server. We should be getting 2.
SELECT @@server_id; 

# Take note of MASTER_LOG_FILE and MASTER_LOG_POS
# You should be entering the values that we take down earlier from master server.
CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_USER='replslave', MASTER_PORT=3306, MASTER_PASSWORD='YOUR_OWN_CHOSEN_SLAVE_PASSWORD', MASTER_LOG_FILE='mysql1-bin.000001', MASTER_LOG_POS=106;

START SLAVE;
SHOW SLAVE STATUS \G
</pre>
<p>If replication is set up properly, we should see these two lines indicating that it is running well:</p>
<pre class="brush: plain; title: ; notranslate">Slave_IO_Running: Yes
Slave_SQL_Running: Yes</pre>
<h3>Complete!</h3>
<p>Congratulations on successfully setting up MySQL master-slave replication on the same EC2 instance. </p>
<p>You can now run your MySQL-based applications. There should not be any changes needed for your applications to run as the master MySQL server is running default port and default socket.</p>
<p>Now you do not have to worry about I/O heavy operations on MySQL raising your cloud computing bills and at the same time having the peace of mind that your MySQL data is safely being replicated on a consistent EBS-backed storage.</p>
<p>For further safeguard, you can even take EBS snapshots from time to time.</p>
<h3>Feedback</h3>
<p>As this tutorial is written by attempting to retrace the steps I have taken for my setup, I may have missed some pointers.<br />
Let me know in the comments below or email me (<a href="mailto:chua@uzyn.com">chua@uzyn.com</a>) if you have any questions or suggestions, or just to let me know that you have successfully set it up by following this tutorial.</p>
<p>If you are into cloud computing, do consider <a href="http://uzyn.com/feed">subscribing to the blog</a>. Thanks.</p>
<img src="http://feeds.feedburner.com/~r/uzyn/~4/GfXZIQnQKi8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://uzyn.com/running-mysql-on-ec2-ephemeral-storage-while-maintaining-consistency/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Accessibility fail</title>
		<link>http://uzyn.com/accessibility-fail/</link>
		<comments>http://uzyn.com/accessibility-fail/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 15:05:12 +0000</pubDate>
		<dc:creator>uzyn</dc:creator>
				<category><![CDATA[UI]]></category>
		<category><![CDATA[accessibility]]></category>
		<category><![CDATA[user interface]]></category>

		<guid isPermaLink="false">http://uzyn.com/?p=35</guid>
		<description><![CDATA[From website of Malaysia&#8217;s Ministry of Foreign Affairs.]]></description>
			<content:encoded><![CDATA[<p><img src="http://uzyn.com/wp-content/uploads/2010/11/Accessibility-fail.png" alt="Accessibility fail - Website of Malaysia's Ministry of Foreign Affairs" title="Accessibility fail" width="558" height="625" class="alignnone size-full wp-image-36" /></p>
<p>From website of <a href="http://www.kln.gov.my/web/guest/fm">Malaysia&#8217;s Ministry of Foreign Affairs</a>.</p>
<img src="http://feeds.feedburner.com/~r/uzyn/~4/-uW8SGBGThI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://uzyn.com/accessibility-fail/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Email from myself — 5 years ago</title>
		<link>http://uzyn.com/email-from-myself-5-years-ago/</link>
		<comments>http://uzyn.com/email-from-myself-5-years-ago/#comments</comments>
		<pubDate>Sun, 07 Nov 2010 06:38:35 +0000</pubDate>
		<dc:creator>uzyn</dc:creator>
				<category><![CDATA[Personal]]></category>
		<category><![CDATA[capsule]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[personal]]></category>

		<guid isPermaLink="false">http://uzyn.com/?p=11</guid>
		<description><![CDATA[Received this surprise in the mail today: From: capsule@forbes.net To: chua@uzyn.com Date: Sun, Nov 7, 2010 at 4:15 AM Subject: Hi from me 5 years back Greetings from your past. In the fall of 2005, you agreed to receive this message, which has been preserved in the Forbes.com E-Mail Time Capsule. For more details, visit [...]]]></description>
			<content:encoded><![CDATA[<p>Received this surprise in the mail today:</p>
<blockquote><p>From: capsule@forbes.net<br />
To: chua@uzyn.com<br />
Date: Sun, Nov 7, 2010 at 4:15 AM<br />
Subject: Hi from me 5 years back</p>
<p>Greetings from your past. In the fall of 2005, you agreed to receive this<br />
message, which has been preserved in the Forbes.com E-Mail Time Capsule.<br />
For more details, visit the links below.</p>
<p>Here is the text of your message:</p>
<p>Hello. This is me 5 years back. Sitting in PGP<sup>[1]</sup>, NUS<sup>[2]</sup>. 2 weeks before exams, caught up between work<sup>[3]</sup> and studies.</p>
<p>I&#8217;m madly in love with Sek Ling.</p>
<p>__________________________________________________________________________<br />The Forbes Time Capsule: created &amp; perpetuated by Codefix Consulting Inc.<br />http://blogs.forbes.com/davidewalt/2010/11/05/forbes-email-time-capsule/<br />http://codefix.net/capsule</p>
</blockquote>
<p>Today, I am married to her.</p>
<div class="ref-notes">
<sup>[1]</sup> PGP: Prince George&#8217;s Park (Residences)<br />
<sup>[2]</sup> NUS: National University of Singapore<br />
<sup>[3]</sup> work: Freelancing as a web developer
</div>
<h4>More on this project from Forbes</h4>
<p>05 November 2010 — <a href="http://blogs.forbes.com/davidewalt/2010/11/05/forbes-email-time-capsule/">Another follow-up after 5 years on Forbes.com</a><br />
26 October 2006 — <a href="http://www.forbes.com/2006/10/26/email-time-capsule-tech-media_cx_de_comm05_1026email.html">Follow-up on Forbes.com</a><br />
21 October 2005 — <a href="http://www.forbes.com/2005/10/21/email-future-time-capsule_cx_de_comm05_1024email.html">The original story on Forbes.com</a></p>
<img src="http://feeds.feedburner.com/~r/uzyn/~4/4yC9Rdn2YzU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://uzyn.com/email-from-myself-5-years-ago/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>First111!!!11!</title>
		<link>http://uzyn.com/first11111/</link>
		<comments>http://uzyn.com/first11111/#comments</comments>
		<pubDate>Mon, 23 Aug 2010 06:54:01 +0000</pubDate>
		<dc:creator>uzyn</dc:creator>
				<category><![CDATA[Blogging]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[first]]></category>
		<category><![CDATA[personal]]></category>

		<guid isPermaLink="false">http://uzyn.com/?p=3</guid>
		<description><![CDATA[Alright, I&#8217;m not exactly new to blogging. Have been doing that since 2004. Stopped for 2 years from 2008. Now back again. Good to be back again. 140 chars are killing me.]]></description>
			<content:encoded><![CDATA[<p>Alright, I&#8217;m not exactly new to blogging. Have been doing that since 2004. Stopped for 2 years from 2008. Now back again.</p>
<p>Good to be back again. 140 chars are killing me.</p>
<img src="http://feeds.feedburner.com/~r/uzyn/~4/UbTtFvoeiIY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://uzyn.com/first11111/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

