本篇內(nèi)容主要講解“MySQL8.0 MIC高可用集群的搭建過程”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“MySQL8.0 MIC高可用集群的搭建過程”吧!
郯城網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)公司,郯城網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為郯城成百上千家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的郯城做網(wǎng)站的公司定做!
一,集群部署
1.1 安裝環(huán)境;
操作系統(tǒng):Linux,版本:CentOS-7-x86
介質(zhì)準(zhǔn)備:無
環(huán)境清理
釋放yum進(jìn)程
[root@bug ~]# ps -ef|grep yum root 22481 1694 5 17:23 ? 00:00:03 /usr/bin/python /usr/share/PackageKit/helpers/yum/yumBackend.py get-updates none root 22591 22507 1 17:24 pts/ 00:00:00 grep --color=auto yum [root@bug ~]# kill -9 22481
查看是否有多余系統(tǒng),有則卸載
1 2 | [root@bug ~]# rpm -qa|grep mairadb [root@bug ~]# rpm -qa|grep mysql |
關(guān)閉防火墻
1 2 3 4 | [root@bug ~]# systemctl status firewalld.service ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled) Active: inactive (dead) |
關(guān)閉selinux,重啟系統(tǒng)后生效
[root@bug selinux]# vi /etc/selinux/config SELINUX=disabled
[root@bug selinux]# reboot
1.2 安裝MySQL8.0
1 2 3 | [root@bug ~]# yum install -y wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm [root@bug ~]# yum list|grep mysql [root@bug ~]# yum install -y mysql-community-client.x86_64 mysql-router.x86_64 mysql-shell.x86_64 |
采用YUM源安裝方式,總下載量約400M,
1.3自動(dòng)集群部署
部署節(jié)點(diǎn)1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | [root@bug ~]# mysqlsh
MySQL JS > dba.deploySandboxInstance(3310); A new MySQL sandbox instance will be created on this host in /root/mysql-sandboxes/3310
Warning: Sandbox instances are only suitable for deploying and running on your local machine for testing purposes and are not accessible from external networks.
Please enter a MySQL root password for the new instance: ****** Deploying new MySQL instance...
Instance localhost:3310 successfully deployed and started. Use shell.connect('root@localhost:3310'); to connect to the instance. |
第一個(gè)節(jié)點(diǎn)部署完畢,端口設(shè)置為3310,登陸賬號(hào)為root@localhost,密碼 ******
使用本地認(rèn)證的方式, 登陸數(shù)據(jù)庫實(shí)例,進(jìn)行驗(yàn)證。
1 2 3 | [root@bug ~]# mysql -uroot -porange -S /root/mysql-sandboxes/3310/sandboxdata/mysqld.sock mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. |
同樣的方法,部署節(jié)點(diǎn)2,節(jié)點(diǎn)3。
1 2 3 | MySQL JS > dba.deploySandboxInstance(3320);
MySQL JS > dba.deploySandboxInstance(3330); |
1.4創(chuàng)建集群
此實(shí)驗(yàn)采用簡單的創(chuàng)建本地集群。
1 2 3 4 5 6 7 8 9 10 11 12 | MySQL JS > \connect root@localhost:3310 Creating a session to 'root@localhost:3310'
***************************************************** MySQL localhost:3310 ssl JS > var cluster=dba.createCluster('test') A new InnoDB cluster will be created on instance 'root@localhost:3310'.
*********************************************************
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. |
集群系統(tǒng)已經(jīng)創(chuàng)建成功,最后一行:At least 3 instances are needed for the cluster to be able to withstand up to one server failure.提示需要至少三個(gè)實(shí)例,才能保證災(zāi)備,所以接下來,將節(jié)點(diǎn)2,3添加進(jìn)集群。
1 2 3 4 5 6 7 8 | MySQL localhost:3310 ssl JS > cluster.addInstance( 'root@localhost:3320')
The instance 'root@localhost:3320' was successfully added to the cluster.
MySQL localhost:3310 ssl JS > cluster.addInstance( 'root@localhost:3330')
The instance 'root@localhost:3330' was successfully added to the cluster. |
查看集群狀態(tài)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | MySQL localhost:3310 ssl JS > dba.getCluster().status() { "clusterName": "test", "defaultReplicaSet": { "name": "default", "primary": "localhost:3310", "ssl": "REQUIRED", "status": "OK", "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.", "topology": { "localhost:3310": { "address": "localhost:3310", "mode": "R/W", "readReplicas": {}, "role": "HA", "status": "ONLINE" }, "localhost:3320": { "address": "localhost:3320", "mode": "R/O", "readReplicas": {}, "role": "HA", "status": "ONLINE" }, "localhost:3330": { "address": "localhost:3330", "mode": "R/O", "readReplicas": {}, "role": "HA", "status": "ONLINE" } } }, "groupInformationSourceMember": "mysql://root@localhost:3310" } |
一個(gè)簡單的包含三個(gè)節(jié)點(diǎn)的集群已經(jīng)創(chuàng)建完成??梢酝瓿蓴?shù)據(jù)同步,讀寫分離等功能,比如此刻3310端口的狀態(tài)是"R/W",同時(shí)read與write,3320與3330的狀態(tài)是"R/O",只讀模式。
1.5配置中間件
此時(shí)的集群的高可用性還不完整,需要MySQL-router來完成集群與外部的對(duì)接,實(shí)現(xiàn)自動(dòng)切換,故障轉(zhuǎn)移等功能。
MySQL-router的作用類似keepalived 類的中間件。當(dāng)主機(jī)發(fā)生故障后,自動(dòng)將應(yīng)用切換到其他實(shí)例。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | [root@bug ~]# mysqlrouter --bootstrap root@localhost:3310 --user=mysqlrouter Please enter MySQL password for root: *****
Bootstrapping system MySQL Router instance... Checking for old Router accounts Creating account mysql_router2_j05xzi45m81x@'%' MySQL Router has now been configured for the InnoDB cluster 'test'.
The following connection information can be used to connect to the cluster.
Classic MySQL protocol connections to cluster 'test': - Read/Write Connections: localhost:6446 - Read/Only Connections: localhost:6447 X protocol connections to cluster 'test': - Read/Write Connections: localhost:64460 - Read/Only Connections: localhost:64470
Existing configurations backed up to '/etc/mysqlrouter/mysqlrouter.conf.bak' [root@bug ~]# mysqlrouter& [1] 25602 [root@bug ~]# ps -ef|grep router mysqlro+ 25602 22507 8 19:35 pts/0 00:00:01 mysqlrouter root 25619 22507 0 19:36 pts/0 00:00:00 grep --color=auto router |
驗(yàn)證MySQL-router安裝效果
在MySQL-router默認(rèn)配置下,
主機(jī)端口:6446
從庫端口:6447
1 2 3 4 5 | [root@bug ~]# mysql -uroot -h 127.0.0.1 -P 6446 -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. ********************************************************8 mysql> |
證明MySQL-router配置完成可用。
1.6驗(yàn)證集群效果
1,通過router同時(shí)登陸三個(gè)節(jié)點(diǎn),查看端口號(hào)。
2,在節(jié)點(diǎn)1構(gòu)造數(shù)據(jù),在節(jié)點(diǎn)2,3差看狀態(tài),驗(yàn)證數(shù)據(jù)同步性。
3,節(jié)點(diǎn)1(主機(jī))離線,查看集群狀態(tài)與節(jié)點(diǎn)2,節(jié)點(diǎn)3狀態(tài),驗(yàn)證災(zāi)備能力。
到此,相信大家對(duì)“MySQL8.0 MIC高可用集群的搭建過程”有了更深的了解,不妨來實(shí)際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!