mysql多源複製

多源複製就是多個master複製,允許一個slave對應多個master;


change master語法(參考:http://dev.mysql.com/doc/refman/5.7/en/change-master-to.html):

CHANGE MASTER TO option [, option] ... [ channel_option ] 

option:
    MASTER_BIND = 'interface_name'
  | MASTER_HOST = 'host_name'
  | MASTER_USER = 'user_name'
  | MASTER_PASSWORD = 'password'
  | MASTER_PORT = port_num
  | MASTER_CONNECT_RETRY = interval
  | MASTER_RETRY_COUNT = count
  | MASTER_DELAY = interval
  | MASTER_HEARTBEAT_PERIOD = interval
  | MASTER_LOG_FILE = 'master_log_name'
  | MASTER_LOG_POS = master_log_pos
  | MASTER_AUTO_POSITION = {0|1}
  | RELAY_LOG_FILE = 'relay_log_name'
  | RELAY_LOG_POS = relay_log_pos
  | MASTER_SSL = {0|1}
  | MASTER_SSL_CA = 'ca_file_name'
  | MASTER_SSL_CAPATH = 'ca_directory_name'
  | MASTER_SSL_CERT = 'cert_file_name'
  | MASTER_SSL_CRL = 'crl_file_name'
  | MASTER_SSL_CRLPATH = 'crl_directory_name'
  | MASTER_SSL_KEY = 'key_file_name'
  | MASTER_SSL_CIPHER = 'cipher_list'
  | MASTER_SSL_VERIFY_SERVER_CERT = {0|1}
  | MASTER_TLS_VERSION = 'protocol_list'
  | IGNORE_SERVER_IDS = (server_id_list)

channel_option: 
    FOR CHANNEL channelserver_id_list:
    [server_id [, server_id] ... ]
一、環境配置
master 192.168.0.109
master 192.168.0.112
slave  192.168.0.110
確保都開啓gtid_mode,基於事務的複製。配置如下:
[mysqld]
gtid-mode=on
enforce-gtid-consistency=true

避免relay.info更新不及時,SLAVE 重啓後導致的主從複製出錯,,在從服務器上實現事故安全功能,增加配置:
master_info_repository=TABLE
relay_log_info_repository=TABLE

對於多源複製是必須的不然會出現錯誤:
ERROR 3077 (HY000): To have multiple channels, repository cannot be of type FILE; Please check the repository configuration and convert them to TABLE.
查看:show variables like 'gtid_mode';
二、配置步驟
1.在master創建複製用戶。
mysql>create user 'repltest'@'192.168.0.%'  identified by 'Repltest123#@!';
mysql>grant  replication slave on *.* to 'repltest'@'192.168.0.%';

2.在slave配置change master
change master to master_host='192.168.0.109',
master_user='repltest',
master_password='Repltest123#@!',
master_auto_position=1 FOR CHANNEL 'channe1';
啓動複製  start slave FOR CHANNEL 'channe1';

change master to master_host='192.168.0.112',
master_user='repltest',
master_password='Repltest123#@!',
MASTER_AUTO_POSITION=1 FOR CHANNEL 'channe2';
啓動複製 start slave FOR CHANNEL 'channe2';

可以通過show  slave status \G查看複製狀態。如果同步相同庫,同一張表,需要處理,庫和表創建衝突以及,表主鍵衝突情況。
3.可以查看performance_schema下的複製表變化
show tables like 'replication%';

另外可以通過如下全局參數設置多線程複製,提高複製速度:
在slave服務器上停止所有鏈路的複製
stop slave [for channel  'channel']
set global slave_parallel_type='logical_clock'   併發類型, 默認DATABASE
set global  slave_parallel_workers=4    併發工作線程數 默認爲0
start slave [for channel  'channel']
重新啓動複製鏈接。
通過查看線程數:
show  processlist;

查詢系統視圖的變化:
 replication_applier_status_by_coordinator  協調複製線程
replication_applier_status_by_worker  複製線程的工作狀態

參考文章:

發佈了404 篇原創文章 · 獲贊 205 · 訪問量 227萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章