Master-Master(雙主)
1、測試環境
Master/Slave Master1/Slave1
IP 192.168.1.13 192.168.1.10
為了保持幹淨的環境:兩邊伺服器
rm -rf /var/lib/mysql/*
service mysqld restart
IP:192.168.1.13
<a href="http://blog.51cto.com/attachment/201304/150159455.jpg" target="_blank"></a>
IP:192.168.1.10
<a href="http://blog.51cto.com/attachment/201304/150401419.jpg" target="_blank"></a>
2、主伺服器授權
分别在Master/Slave和Master1/Slave1上建立一個使用者并授予相應權限。
<a href="http://blog.51cto.com/attachment/201304/150946216.jpg" target="_blank"></a>
<a href="http://blog.51cto.com/attachment/201304/151347593.jpg" target="_blank"></a>
然後退出mysql控制台,停止mysql服務:
mysql> \q
3、配置Mysql主配置檔案/etc/my.cnf
在/etc/my.cnf配置檔案[mysqld]子產品添加如下參數
Master/Slave(192.168.1.13):
[root@bogon ~]# vim /etc/my.cnf
server-id = 1
log-bin = mysql-bin
master-host = 192.168.1.13
master-user = srepli
master-password = 123
master-port = 3306
replicate-ignore-db = mysql
<a href="http://blog.51cto.com/attachment/201304/153905767.jpg" target="_blank"></a>
Master1/Slave1(192.168.1.10):
[root@repli1 ~]# vim /etc/my.cnf
server-id = 2
log-bin = mysql-bin
master-host = 192.168.1.10
master-user = repli
master-password = 123
master-port = 3306
replicate-ignore-db = mysql
<a href="http://blog.51cto.com/attachment/201304/153645976.jpg" target="_blank"></a>
4、檢視同步狀态
service mysqld restart //兩邊伺服器執行
在Master1/Slave1上檢視
mysql> show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
在master/Slave上檢視:
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
注:如果沒有先啟動的伺服器Slave_IO_Running: NO
mysql> slave stop;
mysql> slave start;
兩邊伺服器建庫,建表,插入語句
本文轉自zhang25yun51CTO部落格,原文連結:http://blog.51cto.com/1585654/1182110 ,如需轉載請自行聯系原作者