標籤:伺服器 資料庫 虛擬機器 mysql主主
接http://wsw26.blog.51cto.com/1442148/1749125我這個A已做了BC的主架構上增加一台D的虛擬機器(同一個環境),我的目的是D和A主主互備,BC繼續做A的從,既是D<-->A-->BC這樣架構(類似級聯的)
650) this.width=650;" src="http://s1.51cto.com/wyfs02/M02/7E/6E/wKiom1b-vunTUbfJAAAQQD0Y3M4340.jpg" title="圖.jpg" alt="wKiom1b-vunTUbfJAAAQQD0Y3M4340.jpg" />
準備工作:
(1)D的IP是192.168.0.190,A的IP是192.168.0.8,B的IP是192.168.0.140,C的IP是192.168.0.141
(2)將A的mysql備份的sql通過scp傳去D那裡再從D那裡建立對應的資料庫名字後匯入剛剛scp傳過來的sql庫,BC兩個從庫基本不用動它的了
一、首先在D和A的my.cnf做如下配置(紅色圈住的代表是要配置正確)
650) this.width=650;" src="http://s2.51cto.com/wyfs02/M01/7E/6A/wKioL1b-wBjjYQ7zAAIjy5k3ylc233.jpg" title="D1.jpg" alt="wKioL1b-wBjjYQ7zAAIjy5k3ylc233.jpg" />
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M02/7E/6E/wKiom1b-vy_g7aaIAAHGO7-MD_g313.jpg" style="float:none;" title="A1.jpg" alt="wKiom1b-vy_g7aaIAAHGO7-MD_g313.jpg" />650) this.width=650;" src="http://s2.51cto.com/wyfs02/M02/7E/6E/wKiom1b-v4ODYyOOAAHGO7-MD_g283.jpg" title="A1.jpg" alt="wKiom1b-v4ODYyOOAAHGO7-MD_g283.jpg" />
read-only = 0/1 0: 允許從屬伺服器獨立地執行SQL命令(預設設定); 1: 從屬伺服器只能執行來自主控伺服器的SQL命令。
配置auto-increment-increment&auto-increment-offset的值
關於sync_binlog的數值:
http://blog.csdn.net/wulantian/article/details/9965905,http://my.oschina.net/erichd/blog/499606?p=1
二、在D和A的mysql裡先將各自同步的庫鎖表:flush tables with read lock;後,根據show master status\G;查到master的資訊,再執行change master to master命令來做主從,只是D和A都先要執行:
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/7E/6E/wKiom1b-v6WxKitXAADX-4OF7Wk031.jpg" style="float:none;" title="D3.jpg" alt="wKiom1b-v6WxKitXAADX-4OF7Wk031.jpg" />
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/7E/6E/wKiom1b-v6bBe_SUAADxob7fA0g245.jpg" style="float:none;" title="A2.jpg" alt="wKiom1b-v6bBe_SUAADxob7fA0g245.jpg" />
如果show slave status\G;提示有錯誤的,各自就要先stop slave;reset slave;,再執行以下:
D:mysql> grant replication slave on *.* to ‘repl‘@‘192.168.0.8‘ identified by ‘123456‘;
A: mysql> grant replication slave on *.* to ‘repl‘@‘192.168.0.190‘ identified by ‘123456‘;
D:mysql> flush tables with read lock;
A:mysql> flush tables with read lock;
D: mysql> change master to master_host=‘192.168.0.8‘,master_user=‘repl‘,master_password=‘123456‘,master_log_file=‘mysql-bin.000010‘,master_log_pos=357;
A: mysql> change master to master_host=‘192.168.0.190‘,master_user=‘repl‘,master_password=‘123456‘,master_log_file=‘mysql-bin.000013‘,master_log_pos=440;
各自flush privileges;start slave;unlock tables;show slave status\G;
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M01/7E/6A/wKioL1b-wKGiLf0PAADq7TM3Y6Q006.jpg" style="float:none;" title="A.jpg" alt="wKioL1b-wKGiLf0PAADq7TM3Y6Q006.jpg" />
650) this.width=650;" src="http://s5.51cto.com/wyfs02/M02/7E/6E/wKiom1b-wDaBZzM7AAEns7DwDFM587.jpg" title="D2.jpg" alt="wKiom1b-wDaBZzM7AAEns7DwDFM587.jpg" />
三、即可測試,D和A分別對db2的庫各自操作,use db2(我的mysql庫備份出來的庫檔案名稱)來刪除庫裡面的其中一個表可否同步刪除成功(能各自同步資料了,mysql_binlog會產生變化)
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M02/7E/6A/wKioL1b-wRygXQSzAABarfep4Yg861.jpg" style="float:none;" title="A3.jpg" alt="wKioL1b-wRygXQSzAABarfep4Yg861.jpg" />
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/7E/6E/wKiom1b-wJ_SmEVXAABbI-w6lZo680.jpg" title="D4.jpg" alt="wKiom1b-wJ_SmEVXAABbI-w6lZo680.jpg" />
650) this.width=650;" src="http://s2.51cto.com/wyfs02/M01/7E/6A/wKioL1b-wVOzt21iAABvFnsg1RE236.jpg" title="B1.jpg" alt="wKioL1b-wVOzt21iAABvFnsg1RE236.jpg" />
650) this.width=650;" src="http://s5.51cto.com/wyfs02/M00/7E/6A/wKioL1b-wV7hzkDFAABf0tlez_8905.jpg" title="C1.jpg" alt="wKioL1b-wV7hzkDFAABf0tlez_8905.jpg" />
這樣就可以基本大功告成了,資料同步,主主(DA)互備+mysql一主二從(A,BC)的架構
本文出自 “Steven一直不放棄” 部落格,請務必保留此出處http://wsw26.blog.51cto.com/1442148/1759460
mysql主主互備+原來mysql主從架構