一、MariaDB的GTID
MySQL 5.6引入的GTID(Global Transaction IDs)使得其複制功能的配置、監控及管理變得更加易于實作,且更加健壯。
要在MySQL 5.6中使用複制功能,其服務配置段[mysqld]中于少應該定義如下選項:
binlog-format:二進制日志的格式,有row、statement和mixed幾種類型;
需要注意的是:當設定隔離級别為READ-COMMITED必須設定二進制日志格式為ROW,現在MySQL官方認為STATEMENT這個已經不再适合繼續使用;但mixed類型在預設的事務隔離級别下,可能會導緻主從資料不一緻;
log-slave-updates、gtid-mode、enforce-gtid-consistency、report-port和report-host:用于啟動GTID及滿足附屬的其它需求;
master-info-repository和relay-log-info-repository:啟用此兩項,可用于實作在崩潰時保證二進制及從伺服器安全的功能;
sync-master-info:啟用之可確定無資訊丢失;
slave-paralles-workers:設定從伺服器的SQL線程數;0表示關閉多線程複制功能;
binlog-checksum、master-verify-checksum和slave-sql-verify-checksum:啟用複制有關的所有校驗功能;
binlog-rows-query-log-events:啟用之可用于在二進制日志記錄事件相關的資訊,可降低故障排除的複雜度;
log-bin:啟用二進制日志,這是保證複制功能的基本前提;
server-id:同一個複制拓撲中的所有伺服器的id号必須惟一;
report-host:
The host name or IP address of the slave to be reported to the master during slave registration. This value appears in the output of SHOW SLAVE HOSTS on the master server.
report-port:
The TCP/IP port number for connecting to the slave, to be reported to the master during slave registration.
master-info-repository:
The setting of this variable determines whether the slave logs master status and connection information to a FILE (master.info), or to a TABLE (mysql.slave_master_info)
relay-log-info-repository:
This option causes the server to log its relay log info to a file or a table.
log_slave_updates:
Whether updates received by a slave server from a master server should be logged to the slave's own binary log. Binary logging must be enabled on the slave for this variable to have any effect.
enforce_gtid_consistency:
1、簡單主從模式配置步驟
1、配置主從節點的服務配置檔案
1.1、配置master節點:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<code>[mysqld]</code>
<code>binlog-format=ROW</code>
<code>log-bin=master-bin</code>
<code>log-slave-updates=</code><code>true</code>
<code>gtid-mode=on</code>
<code>enforce-gtid-consistency=</code><code>true</code>
<code>master-info-repository=TABLE</code>
<code>relay-log-info-repository=TABLE</code>
<code>sync-master-info=</code><code>1</code>
<code>slave-parallel-workers=</code><code>2</code>
<code>binlog-checksum=CRC32</code>
<code>master-verify-checksum=</code><code>1</code>
<code>slave-sql-verify-checksum=</code><code>1</code>
<code>binlog-rows-query-log_events=</code><code>1</code>
<code>server-id=</code><code>1</code>
<code>report-port=</code><code>3306</code>
<code>port=</code><code>3306</code>
<code>datadir=/mydata/data</code>
<code>socket=/tmp/mysql.sock</code>
<code>report-host=master.wangfeng7399.com</code>
1.2、配置slave節點:
<code>server-id=</code><code>11</code>
<code>log-bin=mysql-bin.log</code>
<code>report-host=slave.wangfeng7399.com</code>
2、建立複制使用者
<code>MariaDB[none]> GRANT REPLICATION SLAVE ON *.* TO repluser@</code><code>192.168</code><code>.</code><code>1.201</code> <code>IDENTIFIED BY </code><code>'replpass'</code><code>;</code>
說明:192.168.1.201是從節點伺服器;如果想一次性授權更多的節點,可以自行根據需要修改;
3、為備節點提供初始資料集
鎖定主表,備份主節點上的資料,将其還原至從節點;如果沒有啟用GTID,在備份時需要在master上使用show master status指令檢視二進制日志檔案名稱及事件位置,以便後面啟動slave節點時使用。
4、啟動從節點的複制線程
如果啟用了GTID功能,則使用如下指令:
<code>MariaDB[none]> CHANGE MASTER TO MASTER_HOST=</code><code>'master.waangfeng7399.com'</code><code>, MASTER_USER=</code><code>'repluser'</code><code>, MASTER_PASSWORD=</code><code>'replpass'</code><code>, MASTER_AUTO_POSITION=</code><code>1</code><code>;</code>
沒啟用GTID,需要使用如下指令:
<code>slave> CHANGE MASTER TO MASTER_HOST=</code><code>'192.168.1.201'</code><code>,MASTER_USER=</code><code>'repluser'</code><code>,MASTER_PASSWORD=</code><code>'replpass'</code><code>,MASTER_LOG_FILE=</code><code>'master-bin.000005'</code><code>,MASTER_LOG_POS=</code><code>453</code><code>;</code>
二、半同步複制
1、分别在主從節點上安裝相關的插件
master> INSTALL PLUGIN rpl_semi_sync_master SONAME 'semisync_master.so';
slave> INSTALL PLUGIN rpl_semi_sync_slave SONAME 'semisync_slave.so';
2、啟用半同步複制
在master上的配置檔案中,添加 rpl_semi_sync_master_enabled=ON
在至少一個slave節點的配置檔案中添加 rpl_semi_sync_slave_enabled=ON
而後重新啟動mysql服務即可生效。或者,也可以mysql服務上動态啟動其相關功能:
master> SET GLOBAL rpl_semi_sync_master_enabled = ON;
slave> SET GLOBAL rpl_semi_sync_slave_enabled = ON;
slave> STOP SLAVE IO_THREAD; START SLAVE IO_THREAD;
3、确認半同步功能已經啟用
master> CREATE DATABASE magedudb;
master> SHOW STATUS LIKE 'Rpl_semi_sync_master_yes_tx';
slave> SHOW DATABASES;
本文轉自wangfeng7399 51CTO部落格,原文連結:http://blog.51cto.com/wangfeng7399/1395041,如需轉載請自行聯系原作者