【Mysql】Mysql5.7的多源複製搭建
一.基本環境
主庫1: 10.24.65.30 3306 5.7.14
主庫2: 10.24.65.30 3307 mysql 5.7.14
從庫:10.24.65.33 3306 mysql 5.7.14
基於gtid複製
二.搭建注意事項
1.每個例項上DB名字不能一樣。
2.建立或是複製使用者時名字不能一樣,如果經常遇到一樣的帳號若是為了規範建立的帳
號是一樣的,考慮在slave的過濾規則把mysql複製忽略掉。
[stop slave sql_thread;change replication filter replicate_ignore_db=mysql;]
3307啟停:
mysqld_safe --defaults-file=/data/mysql/mysql3307/data/my3307.cnf &
mysqladmin shutdown -S /tmp/mysql3307.sock
mysql -S /tmp/mysql3307.sock
三.主庫配置
1.master1引數設定
gtid-mode=on
enforce-gtid-consistency=1
skip_slave_start=1
2.master2引數設定
gtid-mode=on
enforce-gtid-consistency=1
skip_slave_start=1
3.複製帳號建立
grant replication slave on *.* to identified by 'replsafe';
flush privileges;
4.slave引數設定
gtid-mode=on
enforce-gtid-consistency=1
skip_slave_start=1
master-info-repository=table
relay-log-info-repository=table
5.slave配置連線主庫
change master to
master_host='10.24.65.30',
master_port=3306,
master_user='repl',
master_password='replsafe',
master_auto_position=1 for channel 'master-65303306';
change master to
master_host='10.24.65.30',
master_port=3307,
master_user='repl',
master_password='replsafe',
master_auto_position=1 for channel 'master-65303307';
四.常用命令:
1.開關複製
start slave io_thread|sql_thread for channel 'master-65303306';
stop slave io_thread|sql_thread for channel 'master-65303306'
2.監控複製
show slave status for channel 'master-65303306';
五.校驗
master1:
create database mdb1;
use mdb1;
create table t1(id int);
master2:
create database mdb2;
use mdb2;
create table t2(id int);
slave:
(product)root@localhost [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mdb1 |
| mdb2 |
| mysql |
| performance_schema |
| sys |
+--------------------+
6 rows in set (0.00 sec)
(product)root@localhost [(none)]> use mdb1;
Database changed
(product)root@localhost [mdb1]> show tables;
+----------------+
| Tables_in_mdb1 |
+----------------+
| t1 |
+----------------+
1 row in set (0.00 sec)
(product)root@localhost [mdb1]> use mdb2;
Database changed
(product)root@localhost [mdb2]> show tables;
+----------------+
| Tables_in_mdb2 |
+----------------+
| t2 |
+----------------+
1 row in set (0.00 sec)
六.相關問題
1.多源複製處理之一:
binlog+position:
stop slave sql_thread for channel 'master-65303306';
set sql_slave_skip_counter=n;
start slave sql_thread for channel 'master-65303306';
gtid:
stop slave sql_thread for channel 'master-65303306';
set gtid_next='uuid-N';
begin;commit;
set gtid_next='automatic';
start slave sql_thread for channel 'master-65303306';
2.從多源複製處理之二:
Last_IO_Errno: 1236
Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'A slave with the same server_uuid/server_id as this slave has connected to the master;
the first event 'mysql-bin.000181' at 154, the last event read from '/data/mysql/mysql3306/logs/mysql-bin.000181' at 123, the last byte read from '/data/mysql/mysql3306/logs/mysql-bin.000181' at 154.'
解決方法:
a.由於兩主庫的server-uuid相同,更改其中一個auto.cnf中的server-uuid號
b.並在從庫上執行reset slave all清除slave資訊
c.重新change master
補充:
-
初始化搭建無話可說,畢竟是無業務接入,無資料實時寫入的情況下!
- 接下來要考慮的是資料實時寫入。模擬線上熱搭建多源slave的情況,master1和master2是實時寫入的
- 一:master_auto=1的方式
- 1.dump master1 master2 資料檔案(master-data=2),註釋掉set_gtid——purged
- 2.複製master1.sql master2.sql至slave,將master1 和 master2的gtid_purge合併在一起
- 3.匯入master1.sql 和 master2.sql 並 set global gtid_purged='master1 合併master2的'
- 4.搭建複製通道
- change master to master_host='127.0.0.1',master_user='repluser',master_password='replpass',master_port=3307,master_auto_position=1 for channel 'master_3307';
-
change master to master_host='127.0.0.1',master_user='repluser',master_password='replpass',master_port=3308,master_auto_position=1 for channel 'master_3308';
- 5.檢查無誤
二:master_auto=0的方式
- 1.dump master1 master2 資料檔案(master-data=2)註釋掉set_gtid——purged
- 2.scp master1.sql 至slave ,reset master 並且匯入master1.sql,master_auto=0搭建複製步驟
- 3.scp master2.sql 至slave ,reset master 並且匯入master2.sql,master_auto=0搭建複製步驟
change master to master_host='127.0.0.1',master_user='repluser',master_password='replpass',master_port=3308,MASTER_LOG_FILE='mysql-bin.000005', MASTER_LOG_POS=9460 for channel 'master_3308';
5.檢查無誤
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2137612/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL 5.7搭建多源複製MySql
- MySQL5.7主從複製-半同步複製搭建MySql
- mysql 5.7 多主一從的多源複製搭建MySql
- MySQL 多源複製MySql
- MySQL 5.7.9的多源複製MySql
- mysql 5.7多源複製MySql
- [Mysql]Mysql5.7並行複製MySql並行
- 【Mysql】mysql5.7無損複製MySql
- Mysql5.7半同步複製MySql
- mysql5.7主從複製,主主複製MySql
- MySQL5.7主從複製教程MySql
- MySQL5.6 -> MySQL5.7 跨版本多源複製(Multi-Source Replication)MySql
- 【Mysql】mysql公開課之-mysql5.7複製特性MySql
- MySQL 5.7.9多源複製報錯修復MySql
- MySQL 5.7 多主一從(多源複製)同步配置MySql
- #MySQL# mysql5.7新特性之半同步複製MySql
- MYSQL主從複製的搭建MySql
- MYSQL主主複製的搭建MySql
- MySQL案例07:MySQL5.7併發複製隱式bugMySql
- MySQL5.7半同步複製報錯案例分析MySql
- mysql主從複製搭建MySql
- MySQL 5.5 複製搭建流程MySql
- mysql多源複製跳過錯誤處理方法MySql
- MySQL5.7在滴滴雲主機上的主從複製MySql
- MySQL 複製介紹及搭建MySql
- mysql主從複製的理解和搭建MySql
- Mysql主從複製原理及搭建MySql
- MySQL 5.5 主主複製搭建流程MySql
- 簡單搭建MySQL主從複製MySql
- Mysql 5.6庫級表級複製的搭建MySql
- MySQL搭建帶過濾的複製環境MySql
- 生產環境搭建MySQL複製的教程MySql
- MySQL併發複製系列二:多執行緒複製MySql執行緒
- Mysql分散式部署 - 多級複製MySql分散式
- 【Mysql】mysql5.7新特性之-並行複製實現原理與調優MySql並行
- mysql 5.7 主從複製搭建及原理MySql
- 生產環境中MySQL複製的搭建KPMySql
- MySQL複製--最快的從庫搭建方法(tar包)MySql