基于GTID的主從實(shí)踐系列之②半同步搭建

IP架構(gòu)

主:172.17.100.106????3306

從1:172.17.100.107????3306

從2:172.17.100.107? ? 3307


半同步靠的是插件來實(shí)現(xiàn)的苍狰,首先需要對(duì)插件進(jìn)行安裝

通過show plugins可以看到加載的插件

主庫

root@localhost [(none)]>INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';

Query OK, 0 rows affected (0.00 sec)

root@localhost [(none)]>root@localhost [(none)]>show plugins;

+----------------------------+----------+--------------------+--------------------+---------+

| Name? ? ? ? ? ? ? ? ? ? ? | Status? | Type? ? ? ? ? ? ? | Library? ? ? ? ? ? | License |

+----------------------------+----------+--------------------+--------------------+---------+

...

| rpl_semi_sync_master? ? ? | ACTIVE? | REPLICATION? ? ? ? | semisync_master.so | GPL? ? |

+----------------------------+----------+--------------------+--------------------+---------+

45 rows in set (0.00 sec)

也可以通過show variables來查看

root@localhost [(none)]>show variables like '%semi%';

+-------------------------------------------+------------+

| Variable_name? ? ? ? ? ? ? ? ? ? ? ? ? ? | Value? ? ? |

+-------------------------------------------+------------+

| rpl_semi_sync_master_enabled? ? ? ? ? ? ? | OFF? ? ? ? |

| rpl_semi_sync_master_timeout? ? ? ? ? ? ? | 10000? ? ? |? ?(單位是毫秒驶悟,也就是10秒)

| rpl_semi_sync_master_trace_level? ? ? ? ? | 32? ? ? ? |

| rpl_semi_sync_master_wait_for_slave_count | 1? ? ? ? ? |

| rpl_semi_sync_master_wait_no_slave? ? ? ? | ON? ? ? ? |

| rpl_semi_sync_master_wait_point? ? ? ? ? | AFTER_SYNC |

+-------------------------------------------+------------+

6 rows in set (0.00 sec)


從庫

(product)root@localhost [(none)]> install plugin rpl_semi_sync_slave soname 'semisync_slave.so';

Query OK, 0 rows affected (0.00 sec)

(product)root@localhost [(none)]> show variables like '%semi%';

+---------------------------------+-------+

| Variable_name? ? ? ? ? ? ? ? ? | Value |

+---------------------------------+-------+

| rpl_semi_sync_slave_enabled? ? | OFF? |

| rpl_semi_sync_slave_trace_level | 32? ? |

+---------------------------------+-------+

2 rows in set (0.00 sec)


完成安裝之后,主從庫的半同步均為關(guān)閉狀態(tài)憎兽,需要在主庫和從庫上分別開啟半同步

主:

root@localhost [(none)]>SET GLOBAL rpl_semi_sync_master_enabled = 1;

Query OK, 0 rows affected (0.00 sec)

從(雙實(shí)例上分別執(zhí)行冷离,這里和后面都只演示一個(gè)):

(product)root@localhost [(none)]> set global rpl_semi_sync_slave_enabled=1;

Query OK, 0 rows affected (0.01 sec)


重啟一下從庫的io_thread

(product)root@localhost [(none)]> stop slave io_thread;

Query OK, 0 rows affected (0.01 sec)

(product)root@localhost [(none)]> start slave io_thread;

Query OK, 0 rows affected (0.00 sec)


檢查一下從庫的狀態(tài)

show slave status \G

確認(rèn)io和sql線程均為yes


檢查一下主從上的半同步狀態(tài)

root@localhost [(none)]>show variables like '%semi%';

+-------------------------------------------+------------+

| Variable_name? ? ? ? ? ? ? ? ? ? ? ? ? ? | Value? ? ? |

+-------------------------------------------+------------+

| rpl_semi_sync_master_enabled? ? ? ? ? ? ? | ON? ? ? ? |

| rpl_semi_sync_master_timeout? ? ? ? ? ? ? | 10000? ? ? |

| rpl_semi_sync_master_trace_level? ? ? ? ? | 32? ? ? ? |

| rpl_semi_sync_master_wait_for_slave_count | 1? ? ? ? ? |

| rpl_semi_sync_master_wait_no_slave? ? ? ? | ON? ? ? ? |

| rpl_semi_sync_master_wait_point? ? ? ? ? | AFTER_SYNC |

+-------------------------------------------+------------+

6 rows in set (0.00 sec)


(product)root@localhost [(none)]> show variables like '%semi%';

+---------------------------------+-------+

| Variable_name? ? ? ? ? ? ? ? ? | Value |

+---------------------------------+-------+

| rpl_semi_sync_slave_enabled? ? | ON? ? |

| rpl_semi_sync_slave_trace_level | 32? ? |

+---------------------------------+-------+

2 rows in set (0.00 sec)


再來看一下主庫的error.log

2018-05-17T12:10:21.580190Z 28 [Note] While initializing dump thread for slave with UUID <5cbb6cc8-5287-11e8-b786-005056ba0d70>, found a zombie dump thread with the same UUID. Master is killing the zombie dump thread(8).

2018-05-17T12:10:21.580267Z 8 [Note] Stop asynchronous binlog_dump to slave (server_id: 1073306)

2018-05-17T12:10:21.580529Z 28 [Note] Start binlog_dump to master_thread_id(28) slave_server(1073306), pos(, 4)

2018-05-17T12:10:21.580566Z 28 [Note] Start semi-sync binlog_dump to slave (server_id: 1073306), pos(, 4)

2018-05-17T12:10:29.166518Z 29 [Note] While initializing dump thread for slave with UUID <5d6b91e1-5418-11e8-9657-005056ba0d70>, found a zombie dump thread with the same UUID. Master is killing the zombie dump thread(9).

2018-05-17T12:10:29.166610Z 29 [Note] Start binlog_dump to master_thread_id(29) slave_server(1073307), pos(, 4)

2018-05-17T12:10:29.166638Z 9 [Note] Stop asynchronous binlog_dump to slave (server_id: 1073307)

2018-05-17T12:10:29.589118Z 29 [Note] Start semi-sync binlog_dump to slave (server_id: 1073307), pos(, 4)


---------------------------------------------------------------------------------------

小測(cè)試

把從庫的2個(gè)實(shí)例都關(guān)閉,然后在主庫上執(zhí)行建庫操作

root@localhost [(none)]>create database qimo;

Query OK, 1 row affected (10.00 sec)

整整花費(fèi)10秒纯命,剛好timeout的設(shè)置時(shí)間


再看主庫上的error.log西剥,無法收到從庫反饋的ack消息,直接報(bào)錯(cuò)亿汞,提示通信錯(cuò)誤

最后一句顯示已經(jīng)從半同步模式切換成了異步模式

2018-05-17T12:41:19.859710Z 0 [ERROR] /usr/local/mysql/bin/mysqld: Got an error reading communication packets

2018-05-17T12:41:28.011673Z 0 [ERROR] /usr/local/mysql/bin/mysqld: Got an error reading communication packets

2018-05-17T12:41:59.179369Z 28 [Note] Stop semi-sync binlog_dump to slave (server_id: 1073306)

2018-05-17T12:41:59.595612Z 29 [Note] Stop semi-sync binlog_dump to slave (server_id: 1073307)

2018-05-17T12:42:00.046895Z 28 [Note] Aborted connection 28 to db: 'unconnected' user: 'repl' host: '172.17.100.107' (failed on flush_net())

2018-05-17T12:42:00.047057Z 0 [ERROR] /usr/local/mysql/bin/mysqld: Got an error reading communication packets

2018-05-17T12:42:01.048156Z 29 [Note] Aborted connection 29 to db: 'unconnected' user: 'repl' host: '172.17.100.107' (failed on flush_net())

2018-05-17T12:42:15.491920Z 31 [Warning] Timeout waiting for reply of binlog (file: mysql-bin.000006, pos: 353), semi-sync up to file , position 4.

2018-05-17T12:42:15.491993Z 31 [Note] Semi-sync replication switched OFF.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末瞭空,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子疗我,更是在濱河造成了極大的恐慌咆畏,老刑警劉巖,帶你破解...
    沈念sama閱讀 218,607評(píng)論 6 507
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件碍粥,死亡現(xiàn)場(chǎng)離奇詭異鳖眼,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)嚼摩,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,239評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門钦讳,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人枕面,你說我怎么就攤上這事愿卒。” “怎么了潮秘?”我有些...
    開封第一講書人閱讀 164,960評(píng)論 0 355
  • 文/不壞的土叔 我叫張陵琼开,是天一觀的道長。 經(jīng)常有香客問我枕荞,道長柜候,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,750評(píng)論 1 294
  • 正文 為了忘掉前任躏精,我火速辦了婚禮渣刷,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘矗烛。我一直安慰自己辅柴,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,764評(píng)論 6 392
  • 文/花漫 我一把揭開白布瞭吃。 她就那樣靜靜地躺著碌嘀,像睡著了一般。 火紅的嫁衣襯著肌膚如雪歪架。 梳的紋絲不亂的頭發(fā)上股冗,一...
    開封第一講書人閱讀 51,604評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音牡拇,去河邊找鬼魁瞪。 笑死穆律,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的导俘。 我是一名探鬼主播峦耘,決...
    沈念sama閱讀 40,347評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼旅薄!你這毒婦竟也來了辅髓?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,253評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤少梁,失蹤者是張志新(化名)和其女友劉穎洛口,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體凯沪,經(jīng)...
    沈念sama閱讀 45,702評(píng)論 1 315
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡第焰,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,893評(píng)論 3 336
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了妨马。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片挺举。...
    茶點(diǎn)故事閱讀 40,015評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖烘跺,靈堂內(nèi)的尸體忽然破棺而出湘纵,到底是詐尸還是另有隱情,我是刑警寧澤滤淳,帶...
    沈念sama閱讀 35,734評(píng)論 5 346
  • 正文 年R本政府宣布梧喷,位于F島的核電站,受9級(jí)特大地震影響脖咐,放射性物質(zhì)發(fā)生泄漏铺敌。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,352評(píng)論 3 330
  • 文/蒙蒙 一屁擅、第九天 我趴在偏房一處隱蔽的房頂上張望适刀。 院中可真熱鬧,春花似錦煤蹭、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,934評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至作谭,卻和暖如春稽物,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背折欠。 一陣腳步聲響...
    開封第一講書人閱讀 33,052評(píng)論 1 270
  • 我被黑心中介騙來泰國打工贝或, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留吼过,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,216評(píng)論 3 371
  • 正文 我出身青樓咪奖,卻偏偏與公主長得像盗忱,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子羊赵,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,969評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容