作者 主題: [MySQL] 三台雙向 Replication 是否可行  (閱讀 24849 次)

0 會員 與 1 訪客 正在閱讀本文。

Yamaka

  • 俺是博士!
  • *****
  • 文章數: 4913
    • 檢視個人資料
    • http://www.ecmagic.com
[MySQL] 三台雙向 Replication 是否可行
« 於: 2006-10-02 11:39 »
請問大大們...

我安裝了三台系統版本完全相的 MySQL server

OS: CentOS 4.4 (update 10/02)

MySQL:
mysql-server-4.1.20-1.RHEL4.1
mysql-4.1.20-1.RHEL4.1




當只有兩台做雙向 Replication 時, 完全沒問題...

但是如果同時用三台的話就破功了 ..  :cry:

這三台是這樣設定的..

A Server(IP: 192.168.1.131):
代碼: [選擇]
server-id=1
log-bin
sql-bin-update-same
binlog-do-db=test2

master-host=192.168.1.133
master-user=repl
master-password=zxy12345
log-slave-updates
master-port=3306
master-connect-retry=60
replicate-do-db=test2



B Server(IP: 192.168.1.133):
代碼: [選擇]
server-id=3
log-bin
sql-bin-update-same
binlog-do-db=test2

master-host=192.168.1.131
master-user=repl
master-password=zxy12345
log-slave-updates
master-port=3306
master-connect-retry=60
replicate-do-db=test2

master-host=192.168.1.134
master-user=repl
master-password=zxy12345
log-slave-updates
master-port=3306
master-connect-retry=60
replicate-do-db=test2



C Server(IP: 192.168.1.134):
代碼: [選擇]
server-id=4
log-bin
sql-bin-update-same
binlog-do-db=test2

master-host=192.168.1.133
master-user=repl
master-password=zxy12345
log-slave-updates
master-port=3306
master-connect-retry=60
replicate-do-db=test2



三台 Server 啟動時都沒有任何錯誤訊息..

不過當我在 A Server 操作MySQL(刪除或增加資料),

B & C Server 沒有跟著動作, 而且 A, C 會有錯誤出現...

類似這樣...
代碼: [選擇]
061002 11:25:58 [ERROR] Slave: received end packet from server, apparent master shutdown:
061002 11:25:58 [ERROR] Slave I/O thread: Failed reading log event, reconnecting to retry, log 'MySQL03-bin.000001' position 479
061002 11:25:58 [ERROR] Slave I/O thread: error reconnecting to master 'repl@192.168.1.133:3306': Error: 'Lost connection to MySQL server during query'  errno: 2013  retry-time: 60  retries: 86400
061002 11:28:00 [Note] Slave: connected to master 'repl@192.168.1.133:3306',replication resumed in log 'MySQL03-bin.000001' at position 479
061002 11:28:01 [ERROR] Error reading packet from server: Client requested master to start replication from impossible position (server_errno=1236)
061002 11:28:01 [ERROR] Got fatal error 1236: 'Client requested master to start replication from impossible position' from master when reading data from binary log
061002 11:28:01 [ERROR] Slave I/O thread exiting, read up to log 'MySQL03-bin.000001', position 479



是不支援這種同步方式?? 還是設定有錯誤??

有無大大試過這種方式, 或是有無這方面的資料可供參考!!

先謝謝嘍~~
 :lol:  :lol:

Yamaka

  • 俺是博士!
  • *****
  • 文章數: 4913
    • 檢視個人資料
    • http://www.ecmagic.com
[MySQL] 三台雙向 Replication 是否可行
« 回覆 #1 於: 2006-10-03 23:49 »
今天試了一天, 還是不行  :cry:



剛剛改變了一下排列方式,

三台 mysql server 的 replication 用環狀方式連結...

A -> B -> C -> A   => 成功  :lol:  :lol:


A -> B 表示 B 為 A 的 master

啟動時會有一個 error 訊息,

可能因為它的 master 還未啟動,

沒關係, 一分鐘後會再自動嘗試連線..

============================
台三都啟動後,

在其中一台用 phpMyAdmin 刪除或新增資料..

其他兩台會跟著更新資料庫~~

:wink:

Yamaka

  • 俺是博士!
  • *****
  • 文章數: 4913
    • 檢視個人資料
    • http://www.ecmagic.com
[MySQL] 三台雙向 Replication 是否可行
« 回覆 #2 於: 2006-10-04 23:29 »
本來都是用 phpMyAdmin 來測試這三台 MySQL server, 一直都沒問題..

後來寫了一支 php script 用亂數方式分別 insert 資料到三台 server,

結果出現 ...
代碼: [選擇]
[ERROR] Slave: Error 'Duplicate entry '1698' for key 1' on query. Default database: 'test2'. Query: 'insert into table2(number) values(1701)', Error_code: 1062

這類的錯誤, google 找到了一些資料, 說可以用

auto_increment_increment
auto_increment_offset

這兩個 mysql 的系統變數讓三台產生的  key 不會重複..

可是很不幸的, 這兩個變數要 5.0.2 版以後才有支援  :(




那請問大大們,

在 4.1.xx 版有無類似的設定 ?? 還是..... 無解??


==================
PS:

SET GLOBAL SQL_SLAVE_SKIP_COUNTER=1
SLAVE START SQL_THREAD

可以避開錯誤, 但是資料會流失, 三台也就無法同步了

Yamaka

  • 俺是博士!
  • *****
  • 文章數: 4913
    • 檢視個人資料
    • http://www.ecmagic.com
[MySQL] 三台雙向 Replication 是否可行
« 回覆 #3 於: 2006-10-08 18:59 »
這兩天將 MySQL 升級為 5.0.22

然後在 my.cnf 加上兩個設定..

代碼: [選擇]
auto_increment_increment=10
auto_increment_offset=1


auto_increment_offset 各 server 指定不同的值,

restart 所有的 mysqld...



各 server 在 insert 資料時, 便會使用自己的數值,

如此就不會再有 Duplicate entry 的問題..  :lol:  :lol:

micmic3

  • 俺是博士!
  • *****
  • 文章數: 1693
    • 檢視個人資料
回覆: [MySQL] 三台雙向 Replication 是否可行
« 回覆 #4 於: 2008-12-24 17:43 »
這兩天將 MySQL 升級為 5.0.22

然後在 my.cnf 加上兩個設定..

代碼: [選擇]
auto_increment_increment=10
auto_increment_offset=1

auto_increment_offset 各 server 指定不同的值,

restart 所有的 mysqld...



各 server 在 insert 資料時, 便會使用自己的數值,

如此就不會再有 Duplicate entry 的問題..  :lol:  :lol:
yamaka 大.....如果有 primary key 時(like account)...
如果在不同db寫入頻繁,在 replication 也有可能 Duplicate entry
有沒有解法
有找到
http://blog.kirb.us/2008/07/08/mysql-replication-error-duplicate-entry/
    slave-skip-errors = 1062

It worked, BUT is this a good idea? anyone have a better idea?
這也是我的疑問
« 上次編輯: 2008-12-24 18:00 由 micmic3 »