{"id":6182,"date":"2016-08-23T13:51:41","date_gmt":"2016-08-23T05:51:41","guid":{"rendered":"http:\/\/rmohan.com\/?p=6182"},"modified":"2016-09-05T11:25:58","modified_gmt":"2016-09-05T03:25:58","slug":"db","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6182","title":{"rendered":"db"},"content":{"rendered":"<p>[root@clusterserver2 ~]# cat \/etc\/hosts<br \/>\n127.0.0.1\u00a0\u00a0 localhost localhost.localdomain localhost4 localhost4.localdomain4<br \/>\n::1\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 localhost localhost.localdomain localhost6 localhost6.localdomain6<br \/>\n192.168.1.20 clusterserver1.rmohan.com clusterserver1<br \/>\n192.168.1.21 clusterserver2.rmohan.com clusterserver2<br \/>\n[root@clusterserver2 ~]#<\/p>\n<p>wget https:\/\/dev.mysql.com\/get\/mysql57-community-release-el7-8.noarch.rpm<\/p>\n<p>[root@clusterserver2 software]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm<br \/>\nwarning: mysql57-community-release-el7-8.noarch.rpm: Header V3 DSA\/SHA1 Signature, key ID 5072e1f5: NOKEY<br \/>\nPreparing&#8230;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ################################# [100%]<br \/>\nUpdating \/ installing&#8230;<br \/>\n1:mysql57-community-release-el7-8\u00a0 ################################# [100%]<\/p>\n<p>wo*fk9,yVb!y<\/p>\n<p>EIJQW-y6:hhe<\/p>\n<p>set password for root@localhost=password(&#8216;Test@123&#8217;);<\/p>\n<p>Master1<br \/>\nserver_id\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 1<br \/>\nlog_bin\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = \/var\/log\/mysql\/mysql-bin.log<br \/>\nlog_bin_index\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = \/var\/log\/mysql\/mysql-bin.log.index<br \/>\nrelay_log\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = \/var\/log\/mysql\/mysql-relay-bin<br \/>\nrelay_log_index\u00a0\u00a0\u00a0\u00a0 = \/var\/log\/mysql\/mysql-relay-bin.index<br \/>\nexpire_logs_days\u00a0\u00a0\u00a0 = 10<br \/>\nmax_binlog_size\u00a0\u00a0\u00a0\u00a0 = 100M<br \/>\nlog_slave_updates\u00a0\u00a0 = 1<br \/>\nauto-increment-increment = 2<br \/>\nauto-increment-offset = 1<\/p>\n<p>GRANT ALL ON sonar.* TO &#8216;sonar&#8217;@&#8217;172.27.59.54&#8217; IDENTIFIED BY &#8216;sonar&#8217;;<\/p>\n<p>create user &#8216;replicator&#8217;@&#8217;%&#8217; identified by &#8216;Test@123&#8217;;<br \/>\ngrant replication slave on *.* to &#8216;replicator&#8217;@&#8217;%&#8217; identified by &#8216;Test@123&#8217;;<\/p>\n<p>SHOW MASTER STATUS;<br \/>\nstop slave;<br \/>\nCHANGE MASTER TO MASTER_HOST = &#8216;192.168.1.21&#8217;, master_port=3306, MASTER_USER = &#8216;replicator&#8217;, MASTER_PASSWORD = &#8216;Test@123&#8217;, MASTER_LOG_FILE = &#8216;mysql-bin.000007&#8217;, MASTER_LOG_POS = 1058;<br \/>\nstart slave;<\/p>\n<p>Master2<\/p>\n<p>server_id\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 2<br \/>\nlog_bin\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = \/var\/log\/mysql\/mysql-bin.log<br \/>\nlog_bin_index\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = \/var\/log\/mysql\/mysql-bin.log.index<br \/>\nrelay_log\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = \/var\/log\/mysql\/mysql-relay-bin<br \/>\nrelay_log_index\u00a0\u00a0\u00a0\u00a0 = \/var\/log\/mysql\/mysql-relay-bin.index<br \/>\nexpire_logs_days\u00a0\u00a0\u00a0 = 10<br \/>\nmax_binlog_size\u00a0\u00a0\u00a0\u00a0 = 100M<br \/>\nlog_slave_updates\u00a0\u00a0 = 1<br \/>\nauto-increment-increment = 2<br \/>\nauto-increment-offset = 2<\/p>\n<p>stop slave;<br \/>\nCHANGE MASTER TO MASTER_HOST = &#8216;192.168.1.20&#8217;,master_port=3306, MASTER_USER = &#8216;replicator&#8217;, MASTER_PASSWORD = &#8216;Test@123&#8217;, MASTER_LOG_FILE = &#8216;mysql-bin.000005&#8217;, MASTER_LOG_POS = 2964;<br \/>\nstart slave;<\/p>\n<p>show master status \\G<br \/>\nshow slave status \\G<\/p>\n<p>You can try this:<\/p>\n<p>Slave: stop slave;<br \/>\nMaster: flush logs<\/p>\n<p>Master: show master status; \u2014 take note of the master log file and master log position<\/p>\n<p>Slave: CHANGE MASTER TO MASTER_LOG_FILE=\u2019log-bin.00000X?, MASTER_LOG_POS=106;<br \/>\nSlave: start slave;<\/p>\n<p>SELECT user, host FROM mysql.user;<br \/>\nSELECT USER(), CURRENT_USER();<br \/>\nSHOW VARIABLES LIKE &#8216;skip_networking&#8217;;<\/p>\n<p>create user &#8216;replicator&#8217;@&#8217;%&#8217; identified by &#8216;Test@123&#8217;;<br \/>\ngrant replication slave on *.* to &#8216;replicator&#8217;@&#8217;%&#8217; identified by &#8216;Test@123&#8217;;<br \/>\ngrant replication slave on *.* to &#8216;replicator&#8217;@&#8217;192.168.1.20&#8217; identified by &#8216;Test@123&#8217;;<br \/>\ngrant replication slave on *.* to &#8216;replicator&#8217;@&#8217;192.168.1.21&#8217; identified by &#8216;Test@123&#8217;;<br \/>\nGRANT ALL ON replicator.* TO &#8216;replicator&#8217;@&#8217;192.168.1.21&#8217; IDENTIFIED BY &#8216;Test@123&#8217;;<br \/>\nGRANT ALL ON replicator.* TO &#8216;replicator&#8217;@&#8217;192.168.1.20&#8217; IDENTIFIED BY &#8216;Test@123&#8217;;<br \/>\ngrant all privileges on *.*\u00a0 to root@&#8221;192.168.1.%&#8221; identified by &#8216;Test@123&#8217; with grant option;<br \/>\nFLUSH PRIVILEGES;<\/p>\n<p>Lest start with the advantage for Master-Master replication: allows data to be copied from either server to the other one, it adds redundancy and increases efficiency when dealing with accessing the data, high availability . Now about Disadvantage : cost ( instead of using one machine you will be using two machine with high speed connection).<\/p>\n<p>Requirements: two servers ( you can use one server but it is not recommended unless its for testing)<\/p>\n<p>How to setup: lets say you have machines one m1 with IP 1.1.1.1 and machine two m2 with IP 2.2.2.2<\/p>\n<p>1) login to M1 you need to edit the cnf file for it by adding or comment\\un-comment the following:<\/p>\n<p>server-id\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 1<br \/>\nlog_bin\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = \/var\/log\/mysql\/mysql-bin.log<br \/>\nbinlog_do_db\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = MyDB\u00a0\u00a0\u00a0\u00a0 &#8212; if you want the replication for one db, comment this if you want to replicate all the SID<br \/>\n# bind-address\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 127.0.0.1<\/p>\n<p>then restart the SID for M1 and log in to MySQL using the command<\/p>\n<p>mysql -uroot -P[port] -p[password]<\/p>\n<p>2) create a replica user using the following command<\/p>\n<p>create user &#8216;replicator&#8217;@&#8217;M2&#8217; identified by &#8216;password&#8217;; &#8212; note you can use the IP instead of the host name<\/p>\n<p>3) Next grant the replication privliges to the replica user using:<\/p>\n<p>grant replication slave on *.* to &#8216;replicator&#8217;@&#8217;M2&#8217;;<\/p>\n<p>4) check the master status to get the log id ** after finish configuration the server one M1 you need to move to server 2 M2 (the same thing you did for server one but you need to make sure to change the host names as needed):<\/p>\n<p>5) edit the cnf file but make sure the server id it not the same as M1<\/p>\n<p>server-id\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 2<br \/>\nlog_bin\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = \/var\/log\/mysql\/mysql-bin.log<br \/>\nbinlog_do_db\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = MyDB\u00a0\u00a0\u00a0\u00a0 &#8212; if you want the replication for one db, comment this if you want to replicate all the SID<br \/>\n# bind-address\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 = 127.0.0.1<\/p>\n<p>6) restart the service<\/p>\n<p>7) create a replication user and provide it with the replication privliges<\/p>\n<p>create user &#8216;replicator&#8217;@&#8217;M1&#8217; identified by &#8216;password&#8217;;<br \/>\ngrant replication slave on *.* to &#8216;replicator&#8217;@&#8217;M1&#8217;;<\/p>\n<p>now lets configure the master for M2:<\/p>\n<p>slave stop;<\/p>\n<p>CHANGE MASTER TO MASTER_HOST = &#8216;1.1.1.1&#8217;, MASTER_USER = &#8216;replicator&#8217;, MASTER_PASSWORD = &#8216;password&#8217;, MASTER_LOG_FILE = &#8216;mysql-bin..xxxxx&#8217;, MASTER_LOG_POS = xxx;<br \/>\nslave start;<\/p>\n<p>8) now check the master status<\/p>\n<p>9) then go back to the M1 and start the load balance:<\/p>\n<p>slave stop;<\/p>\n<p>CHANGE MASTER TO MASTER_HOST = &#8216;2.2.2.2&#8217;, MASTER_USER = &#8216;replicator&#8217;, MASTER_PASSWORD = &#8216;password&#8217;, MASTER_LOG_FILE = &#8216;mysql-bin.xxxxx&#8217;, MASTER_LOG_POS = xxx;<br \/>\nslave start;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[root@clusterserver2 ~]# cat \/etc\/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.1.20 clusterserver1.rmohan.com clusterserver1 192.168.1.21 clusterserver2.rmohan.com clusterserver2 [root@clusterserver2 ~]#<\/p>\n<p>wget https:\/\/dev.mysql.com\/get\/mysql57-community-release-el7-8.noarch.rpm<\/p>\n<p>[root@clusterserver2 software]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm warning: mysql57-community-release-el7-8.noarch.rpm: Header V3 DSA\/SHA1 Signature, key ID 5072e1f5: NOKEY Preparing&#8230; ################################# [100%] Updating \/ installing&#8230; 1:mysql57-community-release-el7-8 ################################# [100%]<\/p>\n<p>wo*fk9,yVb!y<\/p>\n<p>EIJQW-y6:hhe<\/p>\n<p>set password for root@localhost=password(&#8216;Test@123&#8217;);<\/p>\n<p>Master1 [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6182"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6182"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6182\/revisions"}],"predecessor-version":[{"id":6191,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6182\/revisions\/6191"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}