{"id":17735,"date":"2015-03-10T12:19:23","date_gmt":"2015-03-10T06:49:23","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=17735"},"modified":"2015-10-02T20:40:58","modified_gmt":"2015-10-02T15:10:58","slug":"mysql-master-master-replication-using-rds","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/mysql-master-master-replication-using-rds\/","title":{"rendered":"MySQL Master-Master Replication using RDS"},"content":{"rendered":"<p>Herein, we are looking into a solution of RDS master-master replication. Unfortunately, AWS don&#8217;t support master-master replication on RDS but we walk through a different approach, master-master replication between RDS and External MySql Instance.\u00a0This External MySql instance might be EC2 or your own server. Here are few things those are already setup:-<\/p>\n<p>1. MySql 5.6 running on EC2 instance.<br \/>\n2. DB does exist and synced on RDS and EC2 instance.<br \/>\n3. Port 3306 accessible between RDS and EC2 instance.<\/p>\n<h3 style=\"text-align: justify;color: #ff9900\">Let&#8217;s move to Configuration Steps:-<\/h3>\n<p>1. Configure Mysql Instance as Master.<br \/>\n2. Configure RDS as Master and then Slave.<br \/>\n3. Configure Mysql Instance as Slave.<\/p>\n<p><strong>1. Configure Mysql Instance as Master:-<\/strong><\/p>\n<p>First we setting up Mysql Instance as a Master, \u00a0here some changes in my.cnf file<\/p>\n<p>[js]<\/p>\n<p>server-id = 14 # any unique number<br \/>\nlog_bin = \/var\/lib\/mysql\/mysql-bin.log<br \/>\nreplicate-wild-ignore-table=mysql.rds_% # exclude mysq.rds_* tales during replication from RDS<br \/>\nauto_increment_increment = 2  # total number of master server<br \/>\nauto_increment_offset = 2     # any number, but not higher then above value.<br \/>\n[\/js]<\/p>\n<p>After making all changes restart mysql<\/p>\n<p>[js]<br \/>\n\/etc\/init.d\/mysql restart<br \/>\n[\/js]<\/p>\n<p>We done with configuration of mysql, Now first have to create a user for replication and secondly check binlog file name with it&#8217;s position.<\/p>\n<p>[js]<br \/>\nmysql -uroot -p<br \/>\nmysql&gt; grant replication slave on *.* to &#8216;&lt;REPLI_USER&gt;&#8217;@'&lt;RDS_IP&gt;&#8217; identified by &#8216;&lt;REPLI_PASSWORD&gt;&#8217;;<br \/>\nmysql&gt; show master status;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n| mysql-bin.000015 | 2249     |              |                 |                    |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n[\/js]<\/p>\n<p>Record this output as we need these information later in next step.<\/p>\n<p><strong> 2. Configure RDS as Master and then Slave:- <\/strong><\/p>\n<p>By default in RDS binlog already enabled and we can verify this by ruuning &#8220;show master status&#8221; command in mysql shell. We jut need to set two variables in &#8220;Parameter Groups&#8221;. So login to AWS console to set these parameter and don&#8217;t forget to reboot your instance.<\/p>\n<p><img decoding=\"async\" src=\"\/blog\/wp-ttn-blog\/uploads\/2015\/03\/Screenshot-from-2015-03-04-162315.png\" alt=\"\" \/><\/p>\n<p>If we need to exclude some table, then sorry to say RDS not come with this option but don&#8217;t bother about it we already did this in previous step. Here first we repeat some of above steps, like replication user creation and check master records.<\/p>\n<p>[js]<br \/>\nmysql-uroot -p -h&lt;RDS_HOST&gt;;<br \/>\nmysql&gt; grant replication slave on *.* to &#8216;&lt;REPLI_USER&gt;;&#8217;@'&lt;MYSQL_INSTANCE_IP&gt;&#8217; identified by &#8216;&lt;REPLI_PASSWORD&gt;&#8217;;<br \/>\nmysql&gt; show master status;<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n| File \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 | Position | Binlog_Do_DB | Binlog_Ignore_DB |Executed_Gtid_Set  |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n| mysql-bin-changelog.074711 | 2249     |              |                  |                   |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;-+&#8212;&#8212;&#8212;&#8212;&#8211;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;+&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-+<br \/>\n[\/js]<\/p>\n<p>Note down these information as we need this to make Mysql instance slave of RDS. Now we are going to configure RDS as slave. Please make sure the file name and position value same as noted in step 1.<\/p>\n<p>[js]<br \/>\nmysql -uroot -p&lt;password&gt; -h&lt;RDS EndPonit&gt;<br \/>\nmysq&gt; call mysql.rds_set_external_master(&#8216;&lt;mysql_instance_ip&gt;&#8217;,3306,'&lt;REPLI_USER&gt;&#8217;,'&lt;REPLI_PASSWORD&gt;&#8217;,&#8217;mysql-bin.000015&#8242;,2249,0);<br \/>\nmysql&gt; call mysql.rds_start_replication;<br \/>\n[\/js]<\/p>\n<p>Check slave status by running below command. If every thing is good then out put would be like this<\/p>\n<p>[js]<br \/>\nmysql -uroot -p&lt;password&gt; -h&lt;RDS_EndPoint&gt; -e &quot;show slave status\\G;&quot; | grep Running<br \/>\nSlave_IO_Running: Yes<br \/>\nSlave_SQL_Running: Yes<br \/>\n[\/js]<\/p>\n<p><strong>3. Configure Mysql Instance as Slave:-<\/strong><\/p>\n<p>Now proceeding to make Mysql Instance slave of RDS. We need to repeat steps as we did earlier. Also here make sure value of position and file name match your information.<\/p>\n<p>[js]<br \/>\nmysql -uroot -p;<br \/>\nmysql&gt; CHANGE MASTER TO MASTER_HOST = &#8216;&lt;rds_host_ip&gt;&#8217;, MASTER_USER = &#8216;&lt;REPLI_USER&gt;&#8217;, MASTER_PASSWORD = &#8216;&lt;REPLI_PASSWORD&gt;&#8217;, MASTER_LOG_FILE = &#8216;mysql-bin-changelog.074711&#8217;, MASTER_LOG_POS = 2249;<br \/>\nmysql&gt; start slave;&quot;<br \/>\n[\/js]<\/p>\n<p>Now slave activated and we can check slave replication by using below command<\/p>\n<p>[js]<br \/>\nmysql -uroot -p&lt;password&gt;  -e &quot;show slave status\\G;&quot; | grep Running<br \/>\nSlave_IO_Running: Yes<br \/>\nSlave_SQL_Running: Yes<br \/>\n[\/js]<\/p>\n<p>So both DB replicating data from each other. We can test while creating one table in RDS and second table in Mysql Instance and you can see these tables mirrored on both server. We didn&#8217;t cover up much theoretical part, this was just a brief overview. You can write me your queries at rajdeeps[at]intelligrape.com.<\/p>\n<p>Thanks<br \/>\nRajdeep Singh<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Herein, we are looking into a solution of RDS master-master replication. Unfortunately, AWS don&#8217;t support master-master replication on RDS but we walk through a different approach, master-master replication between RDS and External MySql Instance.\u00a0This External MySql instance might be EC2 or your own server. Here are few things those are already setup:- 1. MySql 5.6 [&hellip;]<\/p>\n","protected":false},"author":165,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":65},"categories":[1174],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/17735"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/165"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=17735"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/17735\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=17735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=17735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=17735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}