溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

怎么部署MySQL Group Replication

發(fā)布時間:2021-11-18 11:31:58 來源:億速云 閱讀:259 作者:iii 欄目:MySQL數(shù)據(jù)庫

這篇文章主要介紹“怎么部署MySQL Group Replication”,在日常操作中,相信很多人在怎么部署MySQL Group Replication問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”怎么部署MySQL Group Replication”的疑惑有所幫助!接下來,請跟著小編一起來學(xué)習(xí)吧!

一、環(huán)境準備

名稱    版本    備注
操作系統(tǒng)    RHEL6.5_X86_64    
數(shù)據(jù)庫    5.7.18-15   Percona二進制版本
復(fù)制節(jié)點  10.26.7.129 node1
    10.26.7.142 node2
    10.26.7.166 node3

二、MGR詳細部署步驟
1、MYSQL5.7安裝
本次學(xué)習(xí)實驗采用的是Percona-Server-5.7.18-15-Linux.x86_64.ssl101二進制版本,具體安裝過程略
2、節(jié)點1my.cnf參數(shù)配置(主寫節(jié)點)
#replicate
server-id=1001
skip-slave-start = false
read-only = false
expire_logs_days = 2
max_binlog_size = 1G
max_binlog_cache_size = 2G
log-bin = /home/mysql/mysql-bin
log-bin-index = /home/mysql/bin-index
binlog_format = row

log-slave-updates = 1
sync_binlog = 1
log-slow-slave-statements = 1
max-relay-log-size = 1G
relay-log = /home/mysql/mysql-relay
relay-log-index = /home/mysql/relay-index
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
#group replication
transaction_write_set_extraction  =XXHASH64         
loose-group_replication_group_name  ="2faa74b8-66bb-11e7-ab7e-b8ca3a6a61ec"  #務(wù)必以uuid形式配置
loose-group_replication_start_on_boot  =off
loose-group_replication_local_address  ="10.26.7.129:24001"                                    #不同節(jié)點配置不同節(jié)點本身的IP地址和端口,區(qū)分MYSQL自身的3306端口
loose-group_replication_group_seeds  ="10.26.7.129:24001,10.26.7.142:24001,10.26.7.166:24001"
loose-group_replication_bootstrap_group  =off
3、創(chuàng)建復(fù)制賬戶(主寫節(jié)點)
set sql_log_bin=0;
create user rpl_user@'%';
grant replication slave on *.* to rpl_user@'%'  identified by 'rpl_pass';
flush privileges;
set sql_log_bin=1;
change master to master_user='rpl_user',master_password='rpl_pass' for channel 'group_replication_recovery';
4、安裝組復(fù)制插件并啟動組復(fù)制(主寫節(jié)點)
安裝插件
install plugin group_replication soname 'group_replication.so';
檢查插件是否正確安裝
show plugins
+-----------------------------+----------+--------------------+----------------------+---------+
| Name                        | Status   | Type               | Library              | License |
+-----------------------------+----------+--------------------+----------------------+---------+
| group_replication           | ACTIVE   | GROUP REPLICATION  | group_replication.so | GPL     |
+-----------------------------+----------+--------------------+----------------------+---------+
啟動組復(fù)制
set global group_replication_bootstrap_group=ON;
start group_replication;
set global group_replication_bootstrap_group=OFF;
檢查組復(fù)制成員及狀態(tài)
select * from performance_schema.replication_group_members;
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 2faa74b8-66bb-11e7-ab7e-b8ca3a6a61ec | node1       |        3306 | ONLINE       |
5、添加組復(fù)制成員實例node2 和node3
***添加節(jié)點前,務(wù)必做DNS解析,如果沒有配置DNS解析服務(wù)器,需要在每個節(jié)點配置hosts解析  /etc/hosts***
10.26.7.166 node3
10.26.7.142 node2
10.26.7.129 node1

***節(jié)點my.cnf參數(shù)文件server-id和loose-group_replication_local_address ="node2:24001需要分別更改"***

node2
set sql_log_bin=0;
create user rpl_user@'%';
grant replication slave on *.* to rpl_user@'%'  identified by 'rpl_pass';
flush privileges;

set sql_log_bin=1;
change master to master_user='rpl_user',master_password='rpl_pass' for channel 'group_replication_recovery';

install plugin group_replication soname 'group_replication.so';
show plugins

set global group_replication_allow_local_disjoint_gtids_join=ON;
start group_replication;

node3同樣執(zhí)行上述命令

然后檢查組復(fù)制信息
select * from performance_schema.replication_group_members;     
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| CHANNEL_NAME              | MEMBER_ID                            | MEMBER_HOST | MEMBER_PORT | MEMBER_STATE |
+---------------------------+--------------------------------------+-------------+-------------+--------------+
| group_replication_applier | 2faa74b8-66bb-11e7-ab7e-b8ca3a6a61ec | node1       |        3306 | ONLINE       |
| group_replication_applier | 35e38786-66bb-11e7-bcc3-b8ca3a6a61a4 | node2       |        3306 | ONLINE       |
| group_replication_applier | 3bbedb1e-66bb-11e7-8fc0-b8ca3a6a7c48 | node3       |        3306 | ONLINE       |
+---------------------------+--------------------------------------+-------------+-------------+--------------+

測試組復(fù)制是否正常:
(root:localhost:Sat Jul 15 13:26:33 2017)[(none)]>create database dbtest;
Query OK, 1 row affected (0.01 sec)
(root:localhost:Sat Jul 15 13:26:40 2017)[(none)]>use dbtest;
Database changed
(root:localhost:Sat Jul 15 13:26:45 2017)[dbtest]>create table t1(id int primary key);
Query OK, 0 rows affected (0.01 sec)
(root:localhost:Sat Jul 15 13:26:54 2017)[dbtest]>insert into t1 values(1);
Query OK, 1 row affected (0.00 sec)
node2和node3執(zhí)行查詢
(root:localhost:Sat Jul 15 12:57:32 2017)[db01]>use dbtest;
Database changed
(root:localhost:Sat Jul 15 13:27:26 2017)[dbtest]>select * from t1;
+----+
| id |
+----+
|  1 |
+----+
1 row in set (0.00 sec)
三、錯誤問題以及匯總:
1、錯誤案例01
錯誤信息:2017-07-15T01:36:06.929941Z 4 [ERROR] Plugin group_replication reported: 'The group name 'group-replication-test' is not a valid UUID'
錯誤原因:loose-group_replication_group_name參數(shù)沒有按照UUID格式指定,被認為設(shè)置該參數(shù)無效
解決方案:更改loose-group_replication_group_name參數(shù)值為,loose-group_replication_group_name  ="2faa74b8-66bb-11e7-ab7e-b8ca3a6a61ec"
2、錯誤案例02
錯誤信息:
2017-07-15T01:29:27.271909Z 0 [Warning] unknown variable 'loose-group_replication_group_name=group-replication-test'
2017-07-15T01:29:27.271926Z 0 [Warning] unknown variable 'loose-group_replication_start_on_boot=off'
2017-07-15T01:29:27.271930Z 0 [Warning] unknown variable 'loose-group_replication_local_address=10.26.7.129:3306'
2017-07-15T01:29:27.271935Z 0 [Warning] unknown variable 'loose-group_replication_group_seeds=10.26.7.129:3306,10.26.7.142:3306,10.26.7.166:3306'
2017-07-15T01:29:27.271939Z 0 [Warning] unknown variable 'loose-group_replication_bootstrap_group=off'
錯誤原因:因為先設(shè)置了這些參數(shù),而沒有裝group_replication插件,導(dǎo)致數(shù)據(jù)庫實例無法識別這些參數(shù)
解決方案:安裝group replication插件,install plugin group_replication soname 'group_replication.so'; (uninstall plugin group_replication 卸載,show plugins查看)
3、錯誤案例03
錯誤信息:
2017-07-15T01:54:54.447829Z 0 [Note] Plugin group_replication reported: 'Unable to bind to 0.0.0.0:3306 (socket=60, errno=98)!'
2017-07-15T01:54:54.447948Z 0 [ERROR] Plugin group_replication reported: 'Unable to announce tcp port 3306. Port already in use?'
2017-07-15T01:54:54.448101Z 0 [ERROR] Plugin group_replication reported: '[GCS] Error joining the group while waiting for the network layer to become ready.'
錯誤原因:配置的組復(fù)制監(jiān)聽端口和MYSQL實例端口沖突
解決方案:調(diào)整下面參數(shù)
loose-group_replication_local_address  ="10.26.7.129:24001"                                    #不同節(jié)點配置不同節(jié)點本身的IP地址和端口,區(qū)分MYSQL自身的3306端口
loose-group_replication_group_seeds  ="10.26.7.129:24001,10.26.7.142:24001,10.26.7.166:24001"
4、錯誤案例04
錯誤信息:
2017-07-15T04:20:01.249529Z 21 [ERROR] Slave I/O for channel 'group_replication_recovery': error connecting to master 'rpl_user@node2:3306' - retry-time: 60  retries: 1, Error_code: 2005
錯誤原因:沒有配置DNS解析或者hosts解析,節(jié)點無法連接其他數(shù)據(jù)庫
解決方案:配置hosts解析,每個節(jié)點/etc/hosts添加如下內(nèi)容
10.26.7.166 node3
10.26.7.142 node2
10.26.7.129 node1
5、錯誤案例05
錯誤信息
2017-07-15T03:42:45.395407Z 288 [ERROR] Slave SQL for channel 'group_replication_recovery': Error 'Can't create database 'db01'; database exists' on query. Default database: 'db01'. Query: 'create database db01', Error_code: 1007
2017-07-15T03:42:45.395472Z 288 [Warning] Slave: Can't create database 'db01'; database exists Error_code: 1007
2017-07-15T03:42:45.395503Z 288 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.000005' position 434
錯誤原因:這個錯誤是由于節(jié)點由于各種原因退出mgr組,后面又加入了mgr組,但之前存在的數(shù)據(jù)依舊存在
解決方案:刪除要加入組復(fù)制節(jié)點存在的數(shù)據(jù)庫即可,但其他節(jié)點不是主寫節(jié)點,需要先調(diào)整參數(shù)set global super_read_only=0;然后執(zhí)行drop database db01;再重新加入組
set global group_replication_allow_local_disjoint_gtids_join=ON;
start group_replication;
6、錯誤案例06
錯誤信息:
2017-07-15T03:44:09.982428Z 18 [ERROR] Slave SQL for channel 'group_replication_recovery': Error 'Can't create database 'db01'; database exists' on query. Default database: 'db01'. Query: 'create database db01', Error_code: 1007
2017-07-15T03:44:09.982493Z 18 [Warning] Slave: Can't create database 'db01'; database exists Error_code: 1007
2017-07-15T03:44:09.982522Z 18 [ERROR] Error running query, slave SQL thread aborted. Fix the problem, and restart the slave SQL thread with "SLAVE START". We stopped at log 'mysql-bin.000005' position 434
錯誤原因:同上錯誤案例05
解決方案:同上錯誤案例05
7、錯誤案例07
錯誤信息:
2017-07-15T03:49:10.370846Z 0 [ERROR] Plugin group_replication reported: 'This member has more executed transactions than those present in the group. Local transactions: 2faa74b8-66bb-11e7-ab7e-b8ca3a6a61ec:1-4,35e38786-66bb-11e7-bcc3-b8ca3a6a61a4:1 > Group transactions: 2faa74b8-66bb-11e7-ab7e-b8ca3a6a61ec:1-16'
錯誤原因:同上錯誤案例05,在從庫執(zhí)行了多余的事務(wù)
解決方案:同上錯誤案例05,直接重新加入節(jié)點即可
set global group_replication_allow_local_disjoint_gtids_join=ON;
start group_replication;
8、錯誤案例08
錯誤信息
ERROR 3098 (HY000): The table does not comply with the requirements by an external plugin.
錯誤原因:由于主節(jié)點創(chuàng)建了表t1,但沒有指定主鍵(此時表結(jié)構(gòu)可以復(fù)制到各節(jié)點,一旦插入數(shù)據(jù)DML操作即會報錯)
解決方案:為表增加主鍵,然后做DML操作(MGR需要各表都有主鍵)
alter table t1 add primary key(id);
insert into t1 values(1),(2);    
9、錯誤案例09
錯誤信息:
mysqldump -R -E --triggers --single-transaction  --master-data=2 -B db01 >db01.sql
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.
mysqldump: Couldn't execute 'SAVEPOINT sp': The MySQL server is running with the --transaction-write-set-extraction!=OFF option so it cannot execute this statement (1290)
錯誤原因:mgr不支持mysqldump的事務(wù)一致性備份,因為其不支持savepoint
解決方案:通過xtrabackup或者不加--single-transaction備份
10、錯誤案例10
錯誤信息:
create table t2 as select * from t1;
ERROR 1786 (HY000): Statement violates GTID consistency: CREATE TABLE ... SELECT.
錯誤原因:配置MGR,開啟了GTID,所有GTID不支持的操作,MGR也不支持
解決方案:使用create table t2 like t1; insert into t2 select * from t;分開兩個事務(wù)執(zhí)行

到此,關(guān)于“怎么部署MySQL Group Replication”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識,請繼續(xù)關(guān)注億速云網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

向AI問一下細節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI