<?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>HBY Consultancy &#187; master master replication</title>
	<atom:link href="http://www.hbyconsultancy.com/tags/master-master-replication/feed" rel="self" type="application/rss+xml" />
	<link>http://www.hbyconsultancy.com</link>
	<description>IT Consultant, PHP Expert, e-Government Specialist and Energy Engineer</description>
	<lastBuildDate>Sun, 01 Jan 2012 12:21:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Create a Master Master MySQL replication &#8211; Ubuntu Server 10.04 x64</title>
		<link>http://www.hbyconsultancy.com/blog/create-a-master-master-mysql-replication-ubuntu-server-10-04-x64.html</link>
		<comments>http://www.hbyconsultancy.com/blog/create-a-master-master-mysql-replication-ubuntu-server-10-04-x64.html#comments</comments>
		<pubDate>Mon, 19 Jul 2010 12:41:23 +0000</pubDate>
		<dc:creator>hatem</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[high availability]]></category>
		<category><![CDATA[master master replication]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[mysql cluster]]></category>
		<category><![CDATA[system architecture]]></category>

		<guid isPermaLink="false">http://www.hbyconsultancy.com/?p=446</guid>
		<description><![CDATA[There are lots of howtos about creating a MySQL cluster, and this is another one that might be useful in some special cases. In this tutorial I will create a Two nodes Master/Master MySQL replication on Ubuntu server 10.04. I used in my cluster two nodes HP DL380G6 with 3 hard disks 15K in RAID5 [...]<h3>Related Posts</h3>
<ol class="yarpp">
		<li><a href="http://www.hbyconsultancy.com/blog/two-nodes-load-balance-and-failover-with-keepalived-and-ubuntu-server-10-04-x64.html" rel="bookmark">Two nodes Load balance and Failover with keepalived and Ubuntu Server 10.04 x64 &raquo;</a><!-- (7.2)--></li>
		<li><a href="http://www.hbyconsultancy.com/blog/shared-ocfs2-partition-on-ubuntu-server-10-04-x64.html" rel="bookmark">Shared OCFS2 partition on Ubuntu Server 10.04 x64 &raquo;</a><!-- (7.2)--></li>
	</ol>
]]></description>
			<content:encoded><![CDATA[<p>There are lots of howtos about creating a MySQL cluster, and this is another one that might be useful in some special cases. In this tutorial I will create a Two nodes Master/Master  MySQL replication on Ubuntu server 10.04. I used in my cluster two nodes  HP DL380G6 with 3 hard disks 15K in RAID5 and connected to a SAN  storage via Fiber.</p>
<p><a href="http://www.hbyconsultancy.com/wp-content/uploads/2010/07/master-master.jpg"><img title="master-master" src="http://www.hbyconsultancy.com/wp-content/uploads/2010/07/master-master.jpg" alt="" width="576" height="201" /></a></p>
<p>Note: Before beginning I want to mention that master/master  configuration is great to avoid single point of failure in your system  architecture, however it will not distribute load across the nodes. I  use Mysql specifically for users management and permissions and then  distribute load via my web application.</p>
<p>Ubuntu Server install ext4 by default, which you will need to change  first to ext3, according to <a href="https://wiki.ubuntu.com/LucidLynx/ReleaseNotes#Performance%20regressions%20with%20ext4%20under%20certain%20workloads">Lucid/Lynx  release notes</a>, if you have performance-sensitive applications &#8211; the  case with a Mysql database server.</p>
<p>We will consider two nodes node1 and node2 with respectively  10.10.0.1 and 10.10.0.2</p>
<p>First install MySQL 5.1 in the two nodes :</p>
<p><code>hatem@node1$ sudo apt-get install mysql-server mysql-client</code></p>
<p>You will have to set the MySQL root password during installation.</p>
<p>Then we have to configure the first master node1</p>
<p><code>hatem@node1$ sudo vi /etc/mysql/my.cnf</code></p>
<p>comment out the line bind-address, then set a unique value to  server-id, and the masterdbname you want to replicate.</p>
<p><code>[mysqld]<br />
# bind-address           = 127.0.0.1<br />
server-id               = 1<br />
log_bin                 = /var/log/mysql/mysql-bin.log<br />
expire_logs_days        = 10<br />
max_binlog_size         = 100M<br />
binlog_do_db            = masterdbname<br />
binlog_ignore_db        = mysql<br />
binlog_ignore_db        = test</code></p>
<p>Restart database to affect changes :</p>
<p><code>hatem@node1$ sudo /etc/init.d/mysql restart</code></p>
<p>If you have a database dump you can import it in node1, however you  can just create the database masterdbname manually :</p>
<p><code>hatem@node1$ mysql -u root -p<br />
mysql&gt; CREATE DATABASE masterdbname;</code></p>
<p>We will have to grant a <em>username</em> and <em>password</em> replication permission on the node1 :</p>
<p><code>mysql&gt; GRANT REPLICATION SLAVE ON *.* TO 'user'@'%'  IDENTIFIED BY 'password';<br />
mysql&gt; FLUSH PRIVILEGES;<br />
mysql&gt; show master status;<br />
+------------------+----------+--------------+------------------+<br />
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |<br />
+------------------+----------+--------------+------------------+<br />
| mysql-bin.000034 |      443 | masterdbname | mysql,test       |<br />
+------------------+----------+--------------+------------------+<br />
1 row in set (0.00 sec)<br />
mysql&gt; quit</code></p>
<p>Now we can move to node2 and configure the mysql server :</p>
<p><code>hatem@node2$ sudo vi /etc/mysql/my.cnf</code></p>
<p>We will have the similar config here too, but with a different  server-id</p>
<p><code>[mysqld]<br />
# bind-address           = 127.0.0.1<br />
server-id               = 2<br />
log_bin                 = /var/log/mysql/mysql-bin.log<br />
expire_logs_days        = 10<br />
max_binlog_size         = 100M<br />
binlog_do_db            = masterdbname<br />
binlog_ignore_db        = mysql<br />
binlog_ignore_db        = test</code></p>
<p>Restart mysql</p>
<p><code>hatem@node2$ sudo /etc/init.d/mysql restart</code></p>
<p>Finally we can connect to node2 server and setup the first  replication :</p>
<p><code>hatem@node2$ mysql -u root -p<br />
mysql&gt; CREATE DATABASE masterdbname;<br />
mysql&gt; CHANGE MASTER TO MASTER_HOST='10.10.0.1', MASTER_USER='user',  MASTER_PASSWORD='password', MASTER_LOG_FILE='mysql-bin.000034',  MASTER_LOG_POS=443;</code></p>
<p>Notice that MASTER_LOG_FILE and MASTER_LOG_POS values are from  previous show master status result.</p>
<p>The first replication is done we can start the slave :</p>
<p><code>mysql&gt; START SLAVE;<br />
mysql&gt; show slave status \G<br />
*************************** 1. row ***************************<br />
Slave_IO_State: Waiting for master to send event<br />
Master_Host: 10.10.0.1<br />
Master_User: user<br />
Master_Port: 3306<br />
Connect_Retry: 60<br />
Master_Log_File: mysql-bin.000034<br />
Read_Master_Log_Pos: 261<br />
Relay_Log_File: Node2-relay-bin.000002<br />
Relay_Log_Pos: 406<br />
Relay_Master_Log_File: mysql-bin.000034<br />
Slave_IO_Running: Yes<br />
Slave_SQL_Running: Yes</code></p>
<p>If the Slave_IO_Running and Slave_SQL_Running are Yes it mean your  first replication is done and you can create a simple table :</p>
<p>At Node1 (actual master) create a table :</p>
<p><code>mysql&gt; use masterdbname;<br />
mysql&gt; create table testmaster21 (mid int(11) auto_increment, PRIMARY  KEY (mid)) Engine=MyISAM;</code></p>
<p>Check available tables at node2 (actual slave)  &#8230; Tada :</p>
<p><code>mysql&gt; show tables;<br />
+------------------------+<br />
| Tables_in_masterdbname |<br />
+------------------------+<br />
| testmaster21           |<br />
+------------------------+<br />
1 rows in set (0.00 sec)</code></p>
<p>Now the second part is very easy, we need first to check master  details in node2 :</p>
<p><code>mysql&gt; show master status;<br />
+------------------+----------+--------------+------------------+<br />
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |<br />
+------------------+----------+--------------+------------------+<br />
| mysql-bin.000034 |      261 | masterdbname | mysql,test       |<br />
+------------------+----------+--------------+------------------+<br />
1 row in set (0.00 sec)</code></p>
<p>Then add in node1 :</p>
<p><code>mysql&gt; CHANGE MASTER TO MASTER_HOST='10.10.0.2',  MASTER_USER='user', MASTER_PASSWORD='password',  MASTER_LOG_FILE='mysql-bin.000034', MASTER_LOG_POS=261;<br />
mysql&gt; START SLAVE;<br />
mysql&gt; show slave status \G<br />
*************************** 1. row ***************************<br />
Slave_IO_State: Waiting for master to send event<br />
Master_Host: 10.10.0.2<br />
Master_User: user<br />
Master_User: user<br />
Master_Port: 3306<br />
Connect_Retry: 60<br />
Master_Log_File: mysql-bin.000034<br />
Read_Master_Log_Pos: 261<br />
Relay_Log_File: Node1-relay-bin.000002<br />
Relay_Log_Pos: 406<br />
Relay_Master_Log_File: mysql-bin.000034<br />
Slave_IO_Running: Yes<br />
Slave_SQL_Running: Yes</code></p>
<p>To test it you can drop table from Node2 and make sure the table is dropped on node1 too.</p>
<p>That&#8217;s all !</p>
<h3>Related Posts</h3>
<ol class="yarpp">
		<li><a href="http://www.hbyconsultancy.com/blog/two-nodes-load-balance-and-failover-with-keepalived-and-ubuntu-server-10-04-x64.html" rel="bookmark">Two nodes Load balance and Failover with keepalived and Ubuntu Server 10.04 x64 &raquo;</a><!-- (7.2)--></li>
		<li><a href="http://www.hbyconsultancy.com/blog/shared-ocfs2-partition-on-ubuntu-server-10-04-x64.html" rel="bookmark">Shared OCFS2 partition on Ubuntu Server 10.04 x64 &raquo;</a><!-- (7.2)--></li>
	</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.hbyconsultancy.com/blog/create-a-master-master-mysql-replication-ubuntu-server-10-04-x64.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

