MySQL8.0 MIC高可用集群的搭建过程

44次阅读
没有评论

共计 4979 个字符,预计需要花费 13 分钟才能阅读完成。

本篇内容主要讲解“MySQL8.0 MIC 高可用集群的搭建过程”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让丸趣 TV 小编来带大家学习“MySQL8.0 MIC 高可用集群的搭建过程”吧!

一,集群部署

1.1 安装环境;

操作系统:Linux,版本:CentOS-7-x86

介质准备:无

环境清理

释放 yum 进程

[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

查看是否有多余系统,有则卸载

1

2

[root@bug ~]# rpm -qa|grep mairadb

[root@bug ~]# rpm -qa|grep mysql

关闭防火墙

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)

关闭 selinux,重启系统后生效

[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 自动集群部署

部署节点 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.

第一个节点部署完毕,端口设置为 3310,登陆账号为 root@localhost,密码  ******

使用本地认证的方式,登陆数据库实例,进行验证。

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.

同样的方法,部署节点 2,节点 3。

1

2

3

MySQL  JS   dba.deploySandboxInstance(3320);

 

MySQL  JS dba.deploySandboxInstance(3330);

1.4 创建集群

此实验采用简单的创建本地集群。

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.

集群系统已经创建成功,最后一行:At least 3 instances are needed for the cluster to be able to withstand up to one server failure. 提示需要至少三个实例,才能保证灾备,所以接下来,将节点 2,3 添加进集群。

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.

查看集群状态

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

}

一个简单的包含三个节点的集群已经创建完成。可以完成数据同步,读写分离等功能,比如此刻 3310 端口的状态是 R/W,同时 read 与 write,3320 与 3330 的状态是 R/O,只读模式。

1.5 配置中间件

此时的集群的高可用性还不完整,需要 MySQL-router 来完成集群与外部的对接,实现自动切换,故障转移等功能。

MySQL-router 的作用类似 keepalived 类的中间件。当主机发生故障后,自动将应用切换到其他实例。

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

验证 MySQL-router 安装效果

在 MySQL-router 默认配置下,

主机端口: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 验证集群效果

1, 通过 router 同时登陆三个节点,查看端口号。

2, 在节点 1 构造数据,在节点 2,3 差看状态,验证数据同步性。

3, 节点 1(主机)离线,查看集群状态与节点 2,节点 3 状态,验证灾备能力。

到此,相信大家对“MySQL8.0 MIC 高可用集群的搭建过程”有了更深的了解,不妨来实际操作一番吧!这里是丸趣 TV 网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-07-28发表,共计4979字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)