Mysql、MariaDB 新型主從叢集配置GTID

來源:互聯網
上載者:User

標籤:mysql   mariadb   gtid   master   slave   cluster   

前文謝了《Mysql、MariaDB 傳統主從叢集配置》,該技術已經非常成熟。從Mysql5.6和MariaDB10.0開始,有了新型的主從方案GTID,不過這兩個系統到這個版本出現了分支,具體實現已經不同,配置方法也不同,下文分別講述。


MariaDB

我用的版本還是10.1版,目前該版本還不是穩定版,但不影響測試。先部署部署好兩個資料庫執行個體,參見http://bangbangba.blog.51cto.com/3180873/1701857

直到建立好複製使用者。

我們這裡的由於是新建立的資料庫,因此先重設下主庫的狀態,

reset master,

這時可以發現舊的bin-log都已刪除,已經只剩下一個新建立的記錄檔。

然後執行下面的語句,注意後面 master_use_gtid=current_pos 這行跟傳統模式不同。

MariaDB [mysql]> change master to master_host=‘localhost‘, master_port=10001, master_user=‘rep‘, master_password=‘123456‘, master_use_gtid=current_pos;Query OK, 0 rows affected (0.36 sec)MariaDB [mysql]> start slave;Query OK, 0 rows affected (0.18 sec)MariaDB [mysql]> show slave status \G;*************************** 1. row ***************************               Slave_IO_State: Waiting for master to send event                  Master_Host: localhost                  Master_User: rep                  Master_Port: 10001                Connect_Retry: 60              Master_Log_File: mysql-bin.000001          Read_Master_Log_Pos: 313               Relay_Log_File: lyw-hp-relay-bin.000002                Relay_Log_Pos: 601        Relay_Master_Log_File: mysql-bin.000001             Slave_IO_Running: Yes            Slave_SQL_Running: Yes        。。。                   Using_Gtid: Current_Pos

後面比傳統的主從方式多了一行內容  Using_Gtid: Current_Pos,說明使用了新的主從方式。

設定好後,同樣需要跟測試下,對主庫的修改是否影響到從庫的內容。



Mysql

Mysql5.6版本開始支援GTID複製方式,其配置方式跟MariaDB不同,需要先在設定檔裡修改相關配置。新增內容如下

[mysqld]gtid-mode               = onlog-slave-updates       = trueenforce-gtid-consistency= true

然後啟動這兩個資料庫。同樣需要配置相應的同步處理的使用者。

然後在從庫執行下面的命令,注意最後這行 master_auto_position=1 跟 MariaDB的不同。

mysql> change master to  master_host=‘localhost‘,  master_port=20001,  master_user=‘rep‘,  master_password=‘123456‘, master_auto_position=1;mysql> start slave;mysql> show slave status \G;*************************** 1. row ***************************               Slave_IO_State: Waiting for master to send event                  Master_Host: localhost                  Master_User: rep                  Master_Port: 20001                Connect_Retry: 60              Master_Log_File: mysql-bin.000004          Read_Master_Log_Pos: 850               Relay_Log_File: lyw-hp-relay-bin.000002                Relay_Log_Pos: 1060        Relay_Master_Log_File: mysql-bin.000004             Slave_IO_Running: Yes            Slave_SQL_Running: Yes            ……           Retrieved_Gtid_Set: a34819a9-700f-11e5-a841-34238703623c:1-3            Executed_Gtid_Set: a34819a9-700f-11e5-a841-34238703623c:1-3

可見最後增加了兩行跟GTID相關的狀態,Retrieved_Gtid_Set,Executed_Gtid_Set,說明採用了GTID這種新型同步方式。


以上主從配置是最基本配置,線上上使用還不夠,主掛了後,並不會自動進行切換,請關注後續文章。

本文出自 “棒棒吧” 部落格,請務必保留此出處http://bangbangba.blog.51cto.com/3180873/1701898

Mysql、MariaDB 新型主從叢集配置GTID

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.