關於GTID主從複製配置

MySQL 5.6引入的GTID(Global Transaction IDs)使得其複製功能的配置、監控及管理變得更加易於實現,且更加健壯。mysql


要在MySQL 5.6中使用複製功能,其服務配置段[mysqld]中於少應該定義以下選項:sql


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:啓用此兩項,可用於實如今崩潰時保證二進制及從服務器安全的功能;app

sync-master-info:啓用之可確保無信息丟失;socket

slave-paralles-workers:設定從服務器的SQL線程數;0表示關閉多線程複製功能;ide

binlog-checksum、master-verify-checksum和slave-sql-verify-checksum:啓用複製有關的全部校驗功能;this

binlog-rows-query-log-events:啓用之可用於在二進制日誌記錄事件相關的信息,可下降故障排除的複雜度;spa

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.一、配置master節點:

[mysqld]

binlog-format=ROW

log-bin=master-bin

log-slave-updates=true

gtid-mode=on 

enforce-gtid-consistency=true

master-info-repository=TABLE

relay-log-info-repository=TABLE

sync-master-info=1

slave-parallel-workers=2

binlog-checksum=CRC32

master-verify-checksum=1

slave-sql-verify-checksum=1

binlog-rows-query-log_events=1

server-id=1

report-port=3306

port=3306

datadir=/mydata/data

socket=/tmp/mysql.sock

report-host=master.magedu.com


1.二、配置slave節點:

[mysqld]

binlog-format=ROW

log-slave-updates=true

gtid-mode=on 

enforce-gtid-consistency=true

master-info-repository=TABLE

relay-log-info-repository=TABLE

sync-master-info=1

slave-parallel-workers=2

binlog-checksum=CRC32

master-verify-checksum=1

slave-sql-verify-checksum=1

binlog-rows-query-log_events=1

server-id=11

report-port=3306

port=3306

log-bin=mysql-bin.log

datadir=/mydata/data

socket=/tmp/mysql.sock

report-host=slave.magedu.com


二、建立複製用戶


mysql> GRANT REPLICATION SLAVE ON *.* TO repluser@172.16.100.7 IDENTIFIED BY 'replpass';


說明:172.16.100.7是從節點服務器;若是想一次性受權更多的節點,能夠自行根據須要修改;


三、爲備節點提供初始數據集


鎖定主表,備份主節點上的數據,將其還原至從節點;若是沒有啓用GTID,在備份時須要在master上使用show master status命令查看二進制日誌文件名稱及事件位置,以便後面啓動slave節點時使用。


四、啓動從節點的複製線程


若是啓用了GTID功能,則使用以下命令:

mysql> CHANGE MASTER TO MASTER_HOST='master.magedu.com', MASTER_USER='repluser', MASTER_PASSWORD='replpass', MASTER_AUTO_POSITION=1;


沒啓用GTID,須要使用以下命令:

slave> CHANGE MASTER TO MASTER_HOST='172.16.100.6',

-> MASTER_USER='repluser',

-> MASTER_PASSWORD='replpass',

-> MASTER_LOG_FILE='master-bin.000003',

-> MASTER_LOG_POS=1174;

相關文章
相關標籤/搜索