mysql8.0带来的新特性,结合MySQLshell,不需要第三方中间件,自动构建高可用集群。

mysql8.0作为一款新产品,其内置的mysq-innodb-cluster(MIC)高可用集群的技术确实惊艳,结合MySQLshell能够实施集群的快速部署,MySQL-route能够实现灾备快速切换,内置读写分离技术,负载均衡技术。结合但实际效果如何,还需验证。

一,集群部署

1.1 安装环境;

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

介质准备:无

环境清理

释放yum进程

[root@bug ~]# ps -ef|grep yum
root : ? :: /usr/bin/python /usr/share/PackageKit/helpers/yum/yumBackend.py get-updates none
root : pts/ :: grep --color=auto yum
[root@bug ~]# kill -

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

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

关闭防火墙

[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

[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

[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,密码 ******

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

[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。

MySQL  JS >  dba.deploySandboxInstance(3320); 

MySQL  JS > dba.deploySandboxInstance(3330);

1.4创建集群

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

 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添加进集群。

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.

查看集群状态

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 类的中间件。当主机发生故障后,自动将应用切换到其他实例。

[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

[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高可用集群搭建的更多相关文章

  1. Hadoop 3.1.2(HA)+Zookeeper3.4.13+Hbase1.4.9(HA)+Hive2.3.4+Spark2.4.0(HA)高可用集群搭建

    目录 目录 1.前言 1.1.什么是 Hadoop? 1.1.1.什么是 YARN? 1.2.什么是 Zookeeper? 1.3.什么是 Hbase? 1.4.什么是 Hive 1.5.什么是 Sp ...

  2. Spark高可用集群搭建

    Spark高可用集群搭建 node1    node2    node3   1.node1修改spark-env.sh,注释掉hadoop(就不用开启Hadoop集群了),添加如下语句 export ...

  3. Hadoop HA高可用集群搭建(Hadoop+Zookeeper+HBase)

    声明:作者原创,转载注明出处. 作者:帅气陈吃苹果 一.服务器环境 主机名 IP 用户名 密码 安装目录 master188 192.168.29.188 hadoop hadoop /home/ha ...

  4. MongoDB高可用集群搭建(主从、分片、路由、安全验证)

    目录 一.环境准备 1.部署图 2.模块介绍 3.服务器准备 二.环境变量 1.准备三台集群 2.安装解压 3.配置环境变量 三.集群搭建 1.新建配置目录 2.修改配置文件 3.分发其他节点 4.批 ...

  5. RabbitMQ高级指南:从配置、使用到高可用集群搭建

    本文大纲: 1. RabbitMQ简介 2. RabbitMQ安装与配置 3. C# 如何使用RabbitMQ 4. 几种Exchange模式 5. RPC 远程过程调用 6. RabbitMQ高可用 ...

  6. MongoDB 3.4 高可用集群搭建(二)replica set 副本集

    转自:http://www.lanceyan.com/tech/mongodb/mongodb_repset1.html 在上一篇文章<MongoDB 3.4 高可用集群搭建(一):主从模式&g ...

  7. Hbase 完全分布式 高可用 集群搭建

    1.准备 Hadoop 版本:2.7.7 ZooKeeper 版本:3.4.14 Hbase 版本:2.0.5 四台主机: s0, s1, s2, s3 搭建目标如下: HMaster:s0,s1(备 ...

  8. MHA 高可用集群搭建(二)

    MHA 高可用集群搭建安装scp远程控制http://www.cnblogs.com/kevingrace/p/5662839.html yum install openssh-clients mys ...

  9. .Net Core2.1 秒杀项目一步步实现CI/CD(Centos7.2)系列一:k8s高可用集群搭建总结以及部署API到k8s

    前言:本系列博客又更新了,是博主研究很长时间,亲自动手实践过后的心得,k8s集群是购买了5台阿里云服务器部署的,这个集群差不多搞了一周时间,关于k8s的知识点,我也是刚入门,这方面的知识建议参考博客园 ...

随机推荐

  1. 服务发现之eureka

    一.什么是服务发现? 问题: 我们现在有多少个服务? 服务越来越多时,服务 URL 配置管理变得非常乱 服务对外的地址变了,其他所有有使用到的服务都要改地址 增加服务,增加服务实例等,都要做运维工作 ...

  2. ELK学习实验002:Elasticsearch介绍及单机安装

    一 简介 ElasticSearch是一个基于Luncene的搜索服务器.它提供了一个分布式多用户能力全文搜索引擎,基于RESTful web接口,ElsticSearch使用Java开发的,并作为A ...

  3. $ CometOJ-Contest\#11\ D$ $Kruscal$重构树

    正解:$Kruscal$重构树 解题报告: 传送门$QwQ$ 发现一个图上搞就很麻烦,考虑变为生成树达到原有效果. 因为在询问的时候是要求走到的点编号尽量小,发现这个时候点的编号就成为限制了,于是不难 ...

  4. 浅谈Java的默认和静态方法

    目录 浅谈Java的默认和静态方法 Java新增默认方法有啥用 Java新增的静态方法有啥用 浅谈Java的默认和静态方法 允许在接口中声明默认方法和静态方法,是JDK1.8新增的特性.存在即合理,两 ...

  5. 微信小程序开发笔记(一)

    一.为什么要学习微信小程序开发 微信小程序是一个可以在微信上打开的轻应用,他是由多个页面组成的程序,跟传统APP比较如下: 优点 1.不需要在应用商店下载,不占用内存空间,即开即用 2.可以在微信内直 ...

  6. 菜鸟学习Fabric源码学习 — 背书节点和链码容器交互

    Fabric 1.4 源码分析 背书节点和链码容器交互 本文档主要介绍背书节点和链码容器交互流程,在Endorser背书节点章节中,无论是deploy.upgrade或者调用链码,最后都会调用Chai ...

  7. docker 修改实例名称

    docker 容器(服务)重命名只要一个命令就可以: docker rename 原容器名 新容器名 如:

  8. Redis系列之----Redis的过期设置及淘汰策略

    Redis的过期时间机制和内存淘汰策略    Redis的数据是存储在内存中的,而服务器的内存大小是有限制的,除非宕机,否则这些数据会一直存在,对于一些不再使用的key,也应当进行删除,否则会浪费内存 ...

  9. Project Settings之Quality翻译

    (版本是2018.4......翻译是自己的渣翻译水平) Unity allows you to set the level of graphical quality it attempts to r ...

  10. git版本管理工具(二)

    1.查看历史版本 ·git log ·git reflog 2.版本回退 ·git reset --hard HEAD^(HEAD代表当前版本) ·HEAD^代表回退到上一个版本 以此类推 ·HEAD ...