InnodbCluster部署

三臺(tái)服務(wù)器編輯host文件:

vi /etc/hosts
192.168.137.10  node1
192.168.137.20  node2
192.168.137.30  node3

分別初始化3臺(tái)實(shí)例,或者準(zhǔn)備好三臺(tái)已有數(shù)據(jù)的實(shí)例,無(wú)需提前在配置文件中添加MGR相關(guān)選項(xiàng)。


以下操作只在node1上操作即可:
安裝mysql-shell
安裝mysql-router

mysql -uroot -p123456 -S /data/3306/mysql/mysql3306.sock
>create user zy@'%' identified by '123456';
>grant all on *.* to zy@'%' with grant option;
這里一定加上with grant option,不然后續(xù)步驟會(huì)失敗。

登錄mysqlshell執(zhí)行檢查:
cd /usr/local/mysql-shell/bin/
./mysqlsh
>\c zy@127.0.0.1:3306
>dba.checkInstanceConfiguration()

根據(jù)提示進(jìn)行整改,對(duì)于已有數(shù)據(jù)的數(shù)據(jù)庫(kù)而言,一般是要補(bǔ)充主鍵,對(duì)于參數(shù)的一些適配根據(jù)提示執(zhí)行下面的命令修復(fù)。

>dba.configureInstance()
整改完畢后重新執(zhí)行檢查,通過(guò)為止。

在mysqlshell里面執(zhí)行:

JS > var cluster=dba.createCluster('zy_cluster')
JS > cluster.status()
JS > cluster.addInstance('192.168.137.20:3306')
添加節(jié)點(diǎn)時(shí),發(fā)現(xiàn)即將加入的節(jié)點(diǎn)存在缺乏主鍵以及replica_preserve_commit_order為off的相同問(wèn)題,用mysqlshell鏈接上去執(zhí)行修改:
>\c zy@192.168.137.20:3306
>dba.checkInstanceConfiguration()
修復(fù)問(wèn)題后。
JS > cluster.addInstance('192.168.137.20:3306')
JS > cluster.addInstance('192.168.137.30:3306')

我在部署時(shí)碰到一個(gè)問(wèn)題,當(dāng)添加節(jié)點(diǎn)時(shí),選擇clone plugin選項(xiàng)后,報(bào)錯(cuò):

[ERROR] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] Error connecting to all peers. Member join failed. Local port: 33061'
2022-03-08T11:36:21.353880+08:00 0 [ERROR] [MY-011735] [Repl] Plugin group_replication reported: '[GCS] The member was unable to join the group. Local port: 33061'

仔細(xì)排查時(shí)發(fā)現(xiàn),當(dāng)初引導(dǎo)第一個(gè)節(jié)點(diǎn)時(shí),有如下提示:

Threads: 5 Questions: 3165 Slow queries: 11 Opens: 901 Flush tables: 4 Open tables: 602 Queries per second avg: 0.002
MySQL 127.0.0.1:3306 ssl JS > dba.checkInstanceConfiguration()
Validating local MySQL instance listening at port 3306 for use in an InnoDB cluster...
This instance reports its own address as localhost.localdomain:3306
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.
Checking whether existing tables comply with Group Replication requirements...

注意上面黑體字部分,節(jié)點(diǎn)把自己認(rèn)為成了localhost.localdomain:3306。而不是我們希望的node1,這個(gè)原因我推測(cè)是當(dāng)時(shí)我們mysqlshell中連接時(shí)使用的是zy@127.0.0.1這個(gè)地址,而host文件默認(rèn)對(duì)127.0.0.1的地址認(rèn)為是localhost.localdomain。我當(dāng)時(shí)刪除了元數(shù)據(jù),然后重啟了一下數(shù)據(jù)庫(kù),再create cluster時(shí)變成node1了,但是其實(shí)不用重啟,退出mysqlshell然后連接時(shí)換成IP地址(不用127.0.0.1)就可以了。

JS > dba.dropMetadataSchema()
JS > \sql
SQL> restart;
也可以退出mysqlshell然后如下連接:
JS > \c zy@192.168.137.10:3306

部署mysql-router:

cd /usr/local/mysql-router/bin
./mysqlrouter -B zy@192.168.137.10:3306 --directory=/data/6033/ -u root --force
發(fā)現(xiàn)自動(dòng)創(chuàng)建了/data/6033目錄,并在目錄/data/6033下面自動(dòng)建立了配置文件和啟停腳本等文件。
cd /data/6033/
vi mysqlrouter.conf
./start.sh
mysql -uzy -P6446 -p123456 -h192.168.137.10 (可寫(xiě)端口)
mysql -uzy -P6447 -p123456 -h192.168.137.10 (只讀端口) 

當(dāng)使用6447只讀端口登錄時(shí),每次登入的是不同的secondary庫(kù)(輪詢(xún)),可以如下這樣查看:

>select @@hostname;
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容