根據(jù)官方文檔搭建MySQL Innodb Cluster

MySQL Innodb Cluster搭建

本次測試使用三臺機器搭建mysql innodb cluster production mode,官方架構(gòu)如下圖所示:

機器列表:


1雕擂、創(chuàng)建數(shù)據(jù)庫實例

首先在三臺主機上創(chuàng)建3307數(shù)據(jù)庫實例肉瓦,數(shù)據(jù)庫版本為mysql-8.0.13套耕,配置文件如下:


[mysqld]

server-id = 1

port = 3307

socket = /data/mysql8/3306/mysql.sock

basedir = /data/mysql8/mysql8

datadir = /data/mysql8/3306/data

pid-file = /data/mysql8/3306/mysql.pid

log-error = /data/mysql8/3306/mysql-error.log

plugin-dir = /data/mysql8/mysql8/lib/plugin

#gernal setting

lower_case_table_names = 1

max_binlog_size = 1G

sync_binlog=1

innodb_flush_log_at_trx_commit = 1

#semi-sync

#rpl_semi_sync_master_enabled=1

#rpl_semi_sync_master_timeout=1000

#rpl_semi_sync_slave_enabled=1


#innodb

innodb_buffer_pool_size = 8G

innodb_buffer_pool_instances =8

#MGR

log-bin = /data/mysql8/3306/bin/mysql-bin

relay-log = /data/mysql8/3306/bin/relay-log

log-slave-updates

binlog-format=row

gtid-mode=ON

enforce-gtid-consistency=true

master-info-repository=table

relay-log-info-repository=table

transaction-write-set-extraction=XXHASH64


標(biāo)紅為必須設(shè)置的參數(shù),其他GR配置前提:

必須使用innodb存儲引擎,主要為了避免事務(wù)提交時沖突。

必須定義主鍵。

節(jié)點間網(wǎng)絡(luò)延遲小毅访。

使用IPV4協(xié)議。

每個節(jié)點上啟動MySQL數(shù)據(jù)庫實例盘榨,注意serverid配置:


./bin/mysqld --defaults-file=/data/mysql8/3306/3306.cfg --initialize-insecure

./bin/mysqld_safe --defaults-file=/data/mysql8/3306/3306.cfg --user=mysql &

mysql -uroot -p -S /data/mysql8/3306/mysql.sock

mysql> alter user root@’localhost’?identified by ‘xxxxxxx’;

mysql>flush privileges;



2俺抽、安裝mysql shell

需要使用python2.7及以上。

1)安裝python2.7



./configure

make && make install


2)解壓mysql shell


tar zxvf ?mysql-shell-8.0.13-linux-glibc2.12-x86-64bit.tar.gz



3)安裝router

Router安裝包被封裝在mysql8.0.13壓縮包中较曼,直接解壓使用即可磷斧。

3、部署innodb cluster

首先在10.191.143.24創(chuàng)建cluster


> mysqlsh --log-level=DEBUG3

JS> \connect mysql://root@localhost:3307?socket=(/data/mysql8/3306/mysql.sock)

JS> dba.verbose=2

JS > dba.configureInstance()


Mysqlsh自動檢查當(dāng)前實例配置是否滿足創(chuàng)建cluster


Configuring local MySQL instance listening at port 3307 for use in an InnoDB cluster...

This instance reports its own address as OaasSvr

Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQL system variable should be changed.

WARNING: User 'root' can only connect from localhost.

If you need to manage this instance while connected from other hosts, new account(s) with the proper source address specification must be created.

1) Create remotely usable account for 'root' with same grants and password

2) Create a new admin account for InnoDB cluster with minimal required grants

3) Ignore and continue

4) Cancel

Please select an option [1]: 2


檢測到root用戶只限定本地登陸,需要重新創(chuàng)建用戶


Account Name: cluster@10.191.143.%


繼續(xù)檢測


Some configuration options need to be fixed:

+-----------------+---------------+----------------+----------------------------+

| Variable ???????| Current Value | Required Value | Note ??????????????????????|

+-----------------+---------------+----------------+----------------------------+

| binlog_checksum | CRC32 ????????| NONE ??????????| Update the server variable |

+-----------------+---------------+----------------+----------------------------+

Do you want to perform the required configuration changes? [y/n]: y


發(fā)現(xiàn)參數(shù)需要調(diào)整弛饭,自動調(diào)整冕末。

創(chuàng)建用戶后重新使用新用戶驗證后創(chuàng)建集群


JS > \connect mysql://cluster@10.191.143.24:3307

Please provide the password for 'cluster@10.191.143.24:3307': *********

Save password for 'cluster@10.191.143.24:3307'? [Y]es/[N]o/Ne[v]er (default No): YY

Fetching schema names for autocompletion... Press ^C to stop.

Your MySQL connection id is 22

Server version: 8.0.13 MySQL Community Server - GPL

No default schema selected; type \use <schema> to set one.

JS > dba.configureInstance()dba.configureInstance()

Configuring local MySQL instance listening at port 3307 for use in an InnoDB cluster...


This instance reports its own address as OaasSvr

Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQL system variable should be changed.


The instance '10.191.143.24:3307' is valid for InnoDB cluster usage.

JS > var cluster = dba.createCluster('testCluster')

Validating instance at 10.191.143.24:3307...

This instance reports its own address as OaasSvr

Instance configuration is suitable.

Creating InnoDB cluster 'testCluster' on 'cluster@10.191.143.24:3307'...

Adding Seed Instance...


Cluster successfully created. Use Cluster.addInstance() to add MySQL instances.

At least 3 instances are needed for the cluster to be able to withstand up to

one server failure.





?MySQL ?10.191.143.24:3307 ssl ?JS > cluster.status()cluster.status()

{

????"clusterName": "testCluster",

????"defaultReplicaSet": {

????????"name": "default",

????????"primary": "10.191.143.24:3307",

????????"ssl": "REQUIRED",

????????"status": "OK_NO_TOLERANCE",

????????"statusText": "Cluster is NOT tolerant to any failures.",

????????"topology": {

????????????"10.191.143.24:3307": {

????????????????"address": "10.191.143.24:3307",

????????????????"mode": "R/W",

????????????????"readReplicas": {},

????????????????"role": "HA",

????????????????"status": "ONLINE"

????????????}

????????}

????},

????"groupInformationSourceMember": "mysql://cluster@10.191.143.24:3307"

}


登陸2節(jié)點創(chuàng)建cluster用戶


JS > \connect mysql://root@localhost:3307?socket=(/data/mysql8/3306/mysql.sock)

JS >dba.configureInstance('root@localhost:3307',{clusterAdmin:"'cluster'@'10.191.143.%'",clusterAdminPassword:'XXXXX'});

Configuring local MySQL instance listening at port 3307 for use in an InnoDB cluster...


This instance reports its own address as AaasSvr

Clients and other cluster members will communicate with it through this address by default. If this is not correct, the report_host MySQL system variable should be changed.


Some configuration options need to be fixed:

+-----------------+---------------+----------------+----------------------------+

| Variable ???????| Current Value | Required Value | Note ??????????????????????|

+-----------------+---------------+----------------+----------------------------+

| binlog_checksum | CRC32 ????????| NONE ??????????| Update the server variable |

+-----------------+---------------+----------------+----------------------------+


Do you want to perform the required configuration changes? [y/n]: YY


Cluster admin user 'cluster'@'10.191.143.%' created.

Configuring instance...

The instance 'localhost:3307' was configured for use in an InnoDB cluster.


然后在1節(jié)點的mysqlshell中加入2節(jié)點


?MySQL ?10.191.143.24:3307 ssl ?JS > cluster.addInstance('cluster@10.191.143.25:3307')cluster.addInstance('cluster@10.191.143.25:3307')

A new instance will be added to the InnoDB cluster. Depending on the amount of

data on the cluster this might take from a few seconds to several hours.


Adding instance to the cluster ...


Validating instance at 10.191.143.25:3307...


This instance reports its own address as AaasSvr


Instance configuration is suitable.

Cluster.addInstance: WARNING: Not running locally on the server and can not access its error log.

ERROR:

Group Replication join failed.

ERROR: Error joining instance to cluster: '10.191.143.25:3307' - Query failed. MySQL Error (3092): ClassicSession.query: The server is not configured properly to be an active member of the group. Please see more details on error log.. Query: START group_replication: MySQL Error (3092): ClassicSession.query: The server is not configured properly to be an active member of the group. Please see more details on error log. (RuntimeError)


結(jié)果報錯:Group Replication join failed.


在10.191.143.25上查看錯誤日志

2018-11-06T06:17:35.694946Z 0 [ERROR] [MY-011526] [Repl] Plugin group_replication reported: 'This member has more executed transactions than those present in the group. Local transactions: 9f50c222-e0e3-11e8-a687-0050569719f1:1-2 > Group transactions: 638b7777-e174-11e8-90f6-0050569770fd:1-6,

8a673b74-e0dd-11e8-818c-0050569770fd:1-21'

2018-11-06T06:17:35.695067Z 0 [ERROR] [MY-011522] [Repl] Plugin group_replication reported: 'The member contains transactions not present in the group. The member will now exit the group.'


因為新創(chuàng)建實例后我們修改了root用戶密碼,并創(chuàng)建了新的用戶導(dǎo)致binlog日志gtid變化侣颂,啟用GR時候報錯档桃。登陸2節(jié)點數(shù)據(jù)庫,執(zhí)行reset master將日志清除后重新執(zhí)行


mysql> reset master;

Query OK, 0 rows affected (0.07 sec)

mysql> show master status\G

*************************** 1. row ***************************

?????????????File: mysql-bin.000001

?????????Position: 151

?????Binlog_Do_DB:

?Binlog_Ignore_DB:

Executed_Gtid_Set:

1 row in set (0.00 sec)

在1節(jié)點上重新加入集群實例:

?MySQL ?10.191.143.24:3307 ssl ?JS > ?cluster.addInstance('cluster@10.191.143.25:3307') cluster.addInstance('cluster@10.191.143.25:3307')

A new instance will be added to the InnoDB cluster. Depending on the amount of

data on the cluster this might take from a few seconds to several hours.

Adding instance to the cluster ...

Validating instance at 10.191.143.25:3307...

This instance reports its own address as AaasSvr

Instance configuration is suitable.

The instance 'cluster@10.191.143.25:3307' was successfully added to the cluster.


成功憔晒,同樣在3節(jié)點上執(zhí)行一次藻肄。


?MySQL ?10.191.143.24:3307 ssl ?JS > cluster.status()cluster.status()

{

????"clusterName": "testCluster",

????"defaultReplicaSet": {

????????"name": "default",

????????"primary": "10.191.143.24:3307",

????????"ssl": "REQUIRED",

????????"status": "OK",

????????"statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",

????????"topology": {

????????????"10.191.143.24:3307": {

????????????????"address": "10.191.143.24:3307",

????????????????"mode": "R/W",

????????????????"readReplicas": {},

????????????????"role": "HA",

????????????????"status": "ONLINE"

????????????},

????????????"10.191.143.25:3307": {

????????????????"address": "10.191.143.25:3307",

????????????????"mode": "R/O",

????????????????"readReplicas": {},

????????????????"role": "HA",

????????????????"status": "ONLINE"

????????????},

????????????"10.191.143.26:3307": {

????????????????"address": "10.191.143.26:3307",

????????????????"mode": "R/O",

????????????????"readReplicas": {},

????????????????"role": "HA",

????????????????"status": "ONLINE"

????????????}

????????}

????},

????"groupInformationSourceMember": "mysql://cluster@10.191.143.24:3307"

}


最終,innodb cluster創(chuàng)建成功拒担。

測試集群嘹屯,在10.191.143.24上創(chuàng)建test庫并新建test表:

10.191.143.24:


create database test;

use test;

mysql> create table test(id int(11),primary key (id) );

Query OK, 0 rows affected (0.03 sec)

mysql> insert into test values (1);

Query OK, 1 row affected (0.05 sec)

mysql> insert into test values(2),(3);

Query OK, 2 rows affected (0.03 sec)

Records: 2 ?Duplicates: 0 ?Warnings: 0

mysql>


10.191.143.25上檢查數(shù)據(jù)成功復(fù)制,但只能讀不能寫:

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末从撼,一起剝皮案震驚了整個濱河市州弟,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌低零,老刑警劉巖婆翔,帶你破解...
    沈念sama閱讀 211,042評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異掏婶,居然都是意外死亡啃奴,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,996評論 2 384
  • 文/潘曉璐 我一進店門雄妥,熙熙樓的掌柜王于貴愁眉苦臉地迎上來纺腊,“玉大人,你說我怎么就攤上這事茎芭。” “怎么了誓沸?”我有些...
    開封第一講書人閱讀 156,674評論 0 345
  • 文/不壞的土叔 我叫張陵梅桩,是天一觀的道長。 經(jīng)常有香客問我拜隧,道長宿百,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 56,340評論 1 283
  • 正文 為了忘掉前任洪添,我火速辦了婚禮垦页,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘干奢。我一直安慰自己痊焊,他們只是感情好,可當(dāng)我...
    茶點故事閱讀 65,404評論 5 384
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著薄啥,像睡著了一般辕羽。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上垄惧,一...
    開封第一講書人閱讀 49,749評論 1 289
  • 那天刁愿,我揣著相機與錄音,去河邊找鬼到逊。 笑死铣口,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的觉壶。 我是一名探鬼主播脑题,決...
    沈念sama閱讀 38,902評論 3 405
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼掰曾!你這毒婦竟也來了旭蠕?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 37,662評論 0 266
  • 序言:老撾萬榮一對情侶失蹤旷坦,失蹤者是張志新(化名)和其女友劉穎掏熬,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體秒梅,經(jīng)...
    沈念sama閱讀 44,110評論 1 303
  • 正文 獨居荒郊野嶺守林人離奇死亡旗芬,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 36,451評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了捆蜀。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片疮丛。...
    茶點故事閱讀 38,577評論 1 340
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖辆它,靈堂內(nèi)的尸體忽然破棺而出誊薄,到底是詐尸還是另有隱情,我是刑警寧澤锰茉,帶...
    沈念sama閱讀 34,258評論 4 328
  • 正文 年R本政府宣布呢蔫,位于F島的核電站,受9級特大地震影響飒筑,放射性物質(zhì)發(fā)生泄漏片吊。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 39,848評論 3 312
  • 文/蒙蒙 一协屡、第九天 我趴在偏房一處隱蔽的房頂上張望俏脊。 院中可真熱鬧,春花似錦肤晓、人聲如沸爷贫。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,726評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽沸久。三九已至季眷,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間卷胯,已是汗流浹背子刮。 一陣腳步聲響...
    開封第一講書人閱讀 31,952評論 1 264
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留窑睁,地道東北人挺峡。 一個月前我還...
    沈念sama閱讀 46,271評論 2 360
  • 正文 我出身青樓,卻偏偏與公主長得像担钮,于是被迫代替她去往敵國和親橱赠。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 43,452評論 2 348

推薦閱讀更多精彩內(nèi)容

  • 【MySQL】Linux下MySQL 5.5饼拍、5.6和5.7的RPM、二進制和源碼安裝 1.1BLOG文檔結(jié)構(gòu)圖 ...
    小麥苗DB寶閱讀 10,519評論 0 31
  • 1)介紹 PerconaXtraBackup(簡稱PXB)是Percona公司開發(fā)的一個用于MySQL數(shù)據(jù)庫物理熱...
    溫東閱讀 2,484評論 0 6
  • 第一章 “您的快遞到貨了田炭∈Τ” 打開了網(wǎng)購郵寄過來的包裹,里面是用極具科技設(shè)計元素包裝的VR頭盔教硫,此刻他抑制不住內(nèi)心...
    soul殤閱讀 275評論 0 5
  • “受戒幫助你持戒叨吮,也因此避免種下產(chǎn)生痛苦的負面習(xí)氣。你要隨時記得佛的慈悲制戒瞬矩,這位圣者的愛與虔誠會保護你不犯惡行茶鉴。...
    柔光寶寶閱讀 150評論 0 0
  • 即將虛歲二十了,傳說可以領(lǐng)證的年紀(jì)景用,說到這里會有很多人竊喜終于可以有自己的家了涵叮,日出而耕,日落而息丛肢。這又是多么...
    f2541e8081e3閱讀 116評論 0 0