innodb 集群_部署MySQL InnoDB集群以实现高可用性

article/2025/9/16 23:27:03

innodb 集群

In this article, I am going to explain how we can deploy the MySQL InnoDB cluster. InnoDB Cluster is a high availability solution provided by MySQL that has single and multi-master capabilities and failover detection.

在本文中,我将解释如何部署MySQL InnoDB集群。 InnoDB Cluster是MySQL提供的高可用性解决方案,具有单主机和多主机功能以及故障转移检测功能。

MySQL InnoDB has three major components:

MySQL InnoDB具有三个主要组件:

  1. MySQL group replication – It is a group of database servers. It replicates the MySQL databases across the multiple nodes, and it has fault tolerance. When changes in the data occur in the MySQL databases, it automatically replicates to the secondary nodes of the server. The concept of the MySQL group replication is similar to the concept of the AlwaysOn availability group MySQL组复制 –它是一组数据库服务器。 它跨多个节点复制MySQL数据库,并且具有容错能力。 当MySQL数据库中的数据发生更改时,它将自动复制到服务器的辅助节点。 MySQL组复制的概念类似于AlwaysOn可用性组的概念
  2. MySQL Router – When a failover occurs, the client application must be aware of the PRIMARY instance and cluster topology. This functionality is handled by the MySQL Router. It routes that redirects the data requests to the available MySQL Server instance. MySQL Router acts as a proxy that is used to hide the multiple MySQL database servers. The concept of the MySQL Router is similar to the MySQL路由器 –发生故障转移时,客户端应用程序必须了解PRIMARY实例和群集拓扑。 该功能由MySQL路由器处理。 它路由将数据请求重定向到可用MySQL Server实例。 MySQL路由器充当用于隐藏多个MySQL数据库服务器的代理。 MySQL路由器的概念类似于Windows Server故障转移群集的Virtual network name of the Windows Server failover cluster 虚拟网络名称
  3. MySQL Shell – It is a configuration tool that can be used to connect, deploy, and manage the MySQL InnoDB cluster. MySQL Shell contains an Admin API that has a MySQL Shell –这是一个配置工具,可用于连接,部署和管理MySQL InnoDB集群。 MySQL Shell包含一个具有dbadbadbadba

To demonstrate the deployment process, I have created three virtual machines on my workstation. I have installed ubuntu 18.04 and MySQL Server 8.0 on the virtual machines. In this article, I am not going to explain the installation process of the MySQL Server on Linux. You can read How to install MySQL on Ubuntu article to understand the step by step installation process of MySQL Server on Ubuntu 18.04.

为了演示部署过程,我在工作站上创建了三个虚拟机。 我已经在虚拟机上安装了ubuntu 18.04MySQL Server 8.0 。 在本文中,我将不解释在Linux上安装MySQL Server的过程。 您可以阅读如何在Ubuntu上安装MySQL的文章,以了解在Ubuntu 18.04上MySQL Server的逐步安装过程。

Following is the configuration of the virtual machines.

以下是虚拟机的配置。

Host Name

IP Address

Operating System and MySQL Server version

SQLLinux01

192.168.0.107

Ubuntu 18.04 , MySQL Server 8.0

SQLLinux02

192.168.0.101

Ubuntu 18.04 , MySQL Server 8.0

SQLLinux03

192.168.0.105

Ubuntu 18.04 , MySQL Server 8.0

主机名

IP地址

操作系统和MySQL服务器版本

SQLLinux01

192.168.0.107

Ubuntu 18.04,MySQL服务器8.0

SQLLinux02

192.168.0.101

Ubuntu 18.04,MySQL服务器8.0

SQLLinux03

192.168.0.105

Ubuntu 18.04,MySQL服务器8.0

I have also installed the following software.

我还安装了以下软件。

  1. Vi editor: This tool is used to configure or edit the configuration file. You can install it by executing the following command:

    Vi编辑器:此工具用于配置或编辑配置文件。 您可以通过执行以下命令来安装它:

    nisarg@LinuxSQL01:~$ sudo apt-get install vi 

    nisarg @ LinuxSQL01:〜$ sudo apt-get安装vi

  2. Net tools: It is a networking tool that can be used to test the connectivity between the nodes/servers. You can install it by executing the following command:

    网络工具:这是一种网络工具,可用于测试节点/服务器之间的连接。 您可以通过执行以下命令来安装它:

    nisarg@LinuxSQL01:~$ sudo apt-get install net-tools

    nisarg @ LinuxSQL01:〜$ sudo apt-get install net-tools

I have divided the entire process of deploying the MySQL InnoDB cluster into the following steps:

我已将部署MySQL InnoDB集群的整个过程分为以下步骤:

  1. Map Domain Address with IP Address

    用IP地址映射域名
  2. Configure MySQL Server to allow remote connections

    配置MySQL服务器以允许远程连接
  3. Create a MySQL administrator user in and grant privileges

    在其中创建MySQL管理员用户并授予特权
  4. Configure the group replication using MySQL Shell

    使用MySQL Shell配置组复制
  5. Create a MySQL InnoDB cluster using MySQL Shell

    使用MySQL Shell创建MySQL InnoDB集群
  6. Configure the MySQL Router using MySQL Shell

    使用MySQL Shell配置MySQL路由器
  7. Monitor, manage, and scale the MySQL InnoDB cluster

    监视,管理和扩展MySQL InnoDB集群

用IP地址映射域名 (Map Domain address with IP Address)

To map the domain address with IP Address, we must edit the hosts file. On Linux, the file is in /etc directory. The full path is /etc/hosts. The entries in the hosts file are in the following format:

要将域名与IP地址映射,我们必须编辑主机文件。 在Linux上,该文件位于/ etc目录中。 完整路径是/ etc / hosts 。 主机文件中的条目采用以下格式:

IP addresses DomainName [DomainAliase]

IP地址域名[DomainAliase]

I am going to use vi editor to edit the hosts file. To edit the file, press the ‘I’ key and enter the IP Addresses and the hosts names in the following format.

我将使用vi编辑器来编辑hosts文件。 要编辑文件,请按“ I”键并以以下格式输入IP地址和主机名。

192.168.0.107   LinuxSQL01 
192.168.0.101   LinuxSQL02 
192.168.0.105   LinuxSQL03 

192.168.0.107 LinuxSQL01
192.168.0.101 LinuxSQL02
192.168.0.105 LinuxSQL03

See the following image:

见下图:

MySQL InnoDB Cluster: Map IP Address with host name

Once the file is updated, press ‘:wq’ to save the changes in the hosts file.

文件更新后,按' :wq '将更改保存在主机文件中。

Once IP Addresses are mapped, run the ping command to test the connectivity using the hostname. Run the following command:

映射IP地址后,运行ping命令以使用主机名测试连接性。 运行以下命令:

nisarg@LinuxSQL01:~$ ping LinuxSQL02 

nisarg @ LinuxSQL01:〜$ ping LinuxSQL02

See the following image:

见下图:

MySQL InnoDB Cluster: Check connectivity

The above configuration settings must be performed on LinuxSQL02 and LinuxSQL03.

以上配置设置必须在LinuxSQL02LinuxSQL03上执行。

配置MySQL服务器以允许远程连接 (Configure MySQL Server to allow remote connections)

When we install the MySQL database server, it does not allow remote connection. To connect to the remote connections, we must specify the IP Addresses in the configuration file mysqld.cnf using a text editor. The configuration file is located at /etc/mysql/mysql.conf.d/mysqld.cnf. You must specify the list of IP Addresses in the bind-address parameter. The format is bind-address = ‘IP Address of the Server.’ Specify the IP Addresses in the configuration file. It should look like the following:

当我们安装MySQL数据库服务器时,它不允许远程连接。 要连接到远程连接,我们必须使用文本编辑器在配置文件mysqld.cnf中指定IP地址。 配置文件位于/etc/mysql/mysql.conf.d/mysqld.cnf 。 您必须在bind-address参数中指定IP地址列表。 格式为bind-address ='服务器的IP地址'。 在配置文件中指定IP地址。 它应如下所示:

MySQL InnoDB Cluster: Change mysqld.cnf file
  • Note: If you want to allow all the incoming connections, the value of the 注意:如果要允许所有传入连接,则bind-addressbind-address0.0.0.00.0.0.0

Once changes are applied, save the configuration file by pressing ‘:wq’.

应用更改后,请按' :wq '保存配置文件。

The above configuration settings must be performed on LinuxSQL02 and LinuxSQL03.

以上配置设置必须在LinuxSQL02LinuxSQL03上执行。

在其中创建MySQL管理员用户并授予特权 (Create a MySQL administrator user in and grant privileges)

Now, let us create a MySQL user and grant appropriate permission to it. To create a user, first, connect to MySQL using the following command:

现在,让我们创建一个MySQL用户并为其授予适当的权限。 要创建用户,首先,使用以下命令连接到MySQL:

root@LinuxSQL01:~# mysql 

root @ LinuxSQL01:〜# mysql

Once connected, execute the following command to create a user.

连接后,执行以下命令来创建用户。

Mysql> create user ‘nisarg’ identified by ‘N*****@****’; 

Mysql>创建由'N ***** @ ****'标识的用户'nisarg';

Once the user is created, execute the following command to grant appropriate permission to it.

创建用户后,执行以下命令为其授予适当的权限。

GRANT ALL PRIVILEGES ON *.* To ‘nisarg’

将所有特权授予*。*到'nisarg'

If you are not using the root user to configure the group replication, you must grant the following set of permissions on metadata databases to the user.

如果您没有使用root用户来配置组复制,则必须向用户授予对元数据数据库的以下权限集。

Metadata database

List of permissions to be assigned.

All databases

CREATE USER, FILE, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SELECT, SHUTDOWN, SUPER

All databases that start with mysql

DELETE, INSERT, UPDATE

All databases that start with mysql_innodb_cluster_metadata

ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, INDEX, INSERT, LOCK TABLES, REFERENCES, SHOW VIEW, TRIGGER, UPDATE

All databases that start with mysql_innodb_cluster_metadata_bkp

ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, INDEX, INSERT, LOCK TABLES, REFERENCES, SHOW VIEW, TRIGGER, UPDATE

All databases that start with mysql_innodb_cluster_metadata_previous

ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, INDEX, INSERT, LOCK TABLES, REFERENCES, SHOW VIEW, TRIGGER, UPDATE

元数据数据库

要分配的权限列表。

所有数据库

创建用户,文件,过程,重新加载,复制客户端,复制从属,选择,关闭,超级

所有以mysql开头的数据库

删除,插入,更新

mysql_innodb_cluster_metadata开头的所有数据库

更改,更改例程,创建,创建例程,创建临时表,创建视图,删除,拖放,事件,执行,索引,插入,锁定表,引用,显示视图,触发,更新

mysql_innodb_cluster_metadata_bkp开头的所有数据库

更改,更改例程,创建,创建例程,创建临时表,创建视图,删除,拖放,事件,执行,索引,插入,锁定表,引用,显示视图,触发,更新

mysql_innodb_cluster_metadata_previous开头的所有数据库

更改,更改例程,创建,创建例程,创建临时表,创建视图,删除,拖放,事件,执行,索引,插入,锁定表,引用,显示视图,触发,更新

Execute the following command to grant permission to the user.

执行以下命令向用户授予权限。

GRANT CREATE USER, FILE, PROCESS, RELOAD, REPLICATION CLIENT, REPLICATION SLAVE, SELECT, SHUTDOWN, SUPER ON *.* TO ‘nisarg’@’%’ WITH GRANT OPTION;
GRANT DELETE, INSERT, UPDATE ON mysql.* TO ‘nisarg’@’%’ WITH GRANT OPTION;

GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, INDEX, INSERT, LOCK TABLES, REFERENCES, SHOW VIEW, TRIGGER, UPDATE ON mysql_innodb_cluster_metadata.* TO ‘nisarg’@’%’ WITH GRANT OPTION;

GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, INDEX, INSERT, LOCK TABLES, REFERENCES, SHOW VIEW, TRIGGER, UPDATE ON mysql_innodb_cluster_metadata_bkp.* TO ‘nisarg’@’%’ WITH GRANT OPTION;

GRANT ALTER, ALTER ROUTINE, CREATE, CREATE ROUTINE, CREATE TEMPORARY TABLES, CREATE VIEW, DELETE, DROP, EVENT, EXECUTE, INDEX, INSERT, LOCK TABLES, REFERENCES, SHOW VIEW, TRIGGER, UPDATE ON mysql_innodb_cluster_metadata_previous.* TO ‘nisarg’@’%’ WITH GRANT OPTION;

授予创建用户,文件,过程,重载,复制客户端,复制从属,选择,关闭,超级打开*。*到GRANT选项的'nisarg'@'%';
GRANT DELETE,INSERT,UPDATE on mysql。*使用GRANT OPTION到'nisarg'@'%';

授予ALTER,ALTER ROUTINE,CREATE,CREATE ROUTINE,CREATE TEMPORARY TABLE,CREATE VIEW,DELETE,DROP,EVENT,EXECUTE,INDEX,INSERT,LOCK TABLE,引用,SHOW VIEW,TRIGGER,在mysql_innodb_cluster上更新UPDATE * '%',带有格randint选项;

授予ALTER,ALTER ROUTINE,CREATE,CREATE ROUTINE,CREATE TEMPORARY TABLE,CREATE VIEW,DELETE,DROP,EVENT,EXECUTE,INDEX,INSERT,LOCK TABLE,引用,SHOW VIEW,TRIGGER,在mysql_innodb_club_metadata上的更新**。 '%',带有格randint选项;

授予ALTER,ALTER ROUTINE,CREATE,CREATE ROUTINE,CREATE TEMPORARY TABLE,CREATE VIEW,DELETE,DROP,EVENT,EXECUTE,INDEX,INSERT,LOCK TABLE,引用,SHOW VIEW,TRIGGER,在mysql_innodb_prenis_metadata上的更新TO **。 '%',带有格randint选项;

配置组复制 (Configure the group replication)

To configure the group replication, we are going to use MySQL Shell. We will configure the group replication using the root user.

要配置组复制,我们将使用MySQL Shell。 我们将使用root用户配置组复制。

nisarg@LinuxSQL01:~# Sudo -s
[sudo] password for nisarg:

nisarg @ LinuxSQL01:〜# Sudo -s
nisarg的[sudo]密码:

Provide the correct password of user nisarg and hit enter.

提供用户nisarg的正确密码,然后按Enter。

Once we are connected to the root user, we will connect to the MySQL shell. To do that, execute the following command on terminal

连接到root用户后,我们将连接到MySQL shell。 为此,请在终端上执行以下命令

root@LinuxSQL01:~# mysqlsh LinuxSQL01 -u nisarg 

root @ LinuxSQL01:〜# mysqlsh LinuxSQL01 -u nisarg

See the following image:

见下图:

MySQL InnoDB Cluster: connect to MySQL Shell

We have performed a fresh installation of MySQL Server; hence we must change some configurations. The configuration changes are performed by using dba.ConfigureLocalInstance() command. This command is used to configure the InnoDB cluster administration. This command can be used locally and remotely.

我们已经完成了MySQL Server的全新安装; 因此我们必须更改一些配置。 使用dba.ConfigureLocalInstance()命令执行配置更改。 此命令用于配置InnoDB集群管理。 该命令可以在本地和远程使用。

The syntax of the command is dba.configurelocalinstance(username@MySQLServer:Portnumber);

该命令的语法为dba.configurelocalinstance(username @ MySQLServer:Portnumber);

Execute the following command on MySQL Shell to configure the group replication:

在MySQL Shell上执行以下命令以配置组复制:

MySQL  JS > dba.configureLocalInstance(“nisarg@LinuxSQL01:3306”); 

MySQL JS> dba.configureLocalInstance(“ nisarg @ LinuxSQL01:3306”);

The command shows the list of configuration parameters that need to be fixed. See the following image:

该命令显示需要修复的配置参数列表。 见下图:

MySQL InnoDB Cluster: Configure group replication

When you run the command, it prompts for the confirmation of the changes in the mysqld.cnf configuration file. The standard location of the file is /etc/mysql/mysql.conf.d/mysqld.cnf. Once you review and confirm the changes, it updates the mysqld.cnf file.

运行命令时,它会提示您确认mysqld.cnf配置文件中的更改。 该文件的标准位置是/etc/mysql/mysql.conf.d/mysqld.cnf 。 查看并确认更改后,它将更新mysqld.cnf文件。

The above steps must be performed on LinuxSQL02 and LinuxSQL03.

以上步骤必须在LinuxSQL02LinuxSQL03上执行。

In my next article, I plan to explain the following:

在下一篇文章中,我打算解释以下内容:

  1. Create a MySQL InnoDB cluster using MySQL Shell

    使用MySQL Shell创建MySQL InnoDB集群
  2. Configure the MySQL Router using MySQL Shell and test the failover

    使用MySQL Shell配置MySQL路由器并测试故障转移
  3. How to monitor, manage, and scale the MySQL InnoDB cluster

    如何监视,管理和扩展MySQL InnoDB集群

摘要 (Summary)

In this article, I have covered how we can:

在本文中,我介绍了如何:

  1. Map Domain Address with IP Address

    用IP地址映射域名
  2. Configure MySQL Server to allow remote connections

    配置MySQL服务器以允许远程连接
  3. Create a MySQL administrator user in and grant privileges

    在其中创建MySQL管理员用户并授予特权
  4. Configure the group replication using MySQL Shell

    使用MySQL Shell配置组复制

翻译自: https://www.sqlshack.com/deploy-mysql-innodb-clusters-for-high-availability/

innodb 集群


http://chatgpt.dhexx.cn/article/0KWfL9CW.shtml

相关文章

ping命令和它的“亲友”们

前面在《kali主机发现背后的秘密》文章里,介绍了几个*ping的命令。ping可是“可人儿”。瞧,它们都来攀亲戚了,蹭热度来了。今天我们就来认识一下它们。 关系 名称 功能特点 备注 本宗 ping 网络诊断工具,测试互联网协议网络…

搞了运维开发这么多年,原来 Ping 还能这么玩儿

作者:刘勇 腾讯后台研发工程师,就读于北京大学。目前主要从事腾讯云-云拨测项目后台开发相关工作。 网络:良辰有一百种方法让你 Ping 不通,你却无可奈何 为什么 Ping 不通了?为什么又通了? 这些居然都能…

同一局域网下访问vue项目

同一局域网: 在你的电脑上用快捷键windows R打开cmd,使用ping ip地址(想要访问你项目的那台电脑的ip地址),如果成功后就表示你们处于同一局域网下。 本机ip地址 在你的电脑上用快捷键windows R打开cmd&#xff…

【Java 并发编程】一文详解 Java 中有几种创建线程的方式

Java 中有几种创建线程的方式? 1. Java 程序天然就是多线程的2. 线程的启动与终止2.1 线程的启动(1)继承 Thread 类,重写 run() 方法(2)实现 Runnable 接口,重写 run() 方法(3)Thre…

【操作系统】创建线程的方式

学习目标: 目标:掌握操作系统知识 学习内容: 本文内容:创建线程的方式 文章目录 学习目标:学习内容:1创建线程的方法一 : 继承Thread类1.1 写法一1.2 写法二 2 创建线程的方法二 :…

想不到吧,Java创建线程的方式只有一种

目录 前言继承Thread方式实现Runnable接口实现callable接口总结 前言 看到这个标题的小伙伴先别着急喷我……在面试的时候,我们经常会被问到这种基础题:Java创建线程的方式有几种? 比较正常的答法当然是三种: 继承Thread实现Ru…

【 java 多线程】创建多线程的方式三:使用 Callable 接口创建多线程

📋 个人简介 💖 作者简介:大家好,我是阿牛,全栈领域优质创作者。😜📝 个人主页:馆主阿牛🔥🎉 支持我:点赞👍收藏⭐️留言&#x1f4d…

关于创建线程的方式有几种

导语 在我们平常的面试中,我们经常会被面试官问道:你知道Java中多线程的实现方式有几种吗?在网上刷过面试题的童鞋们,一般都会说两种:继承Thread、实现Runnable,甚至还有甚者可能会说三种、四种的&#xf…

Java创建线程的方式只有一种:Thread+Runnable

Java创建线程的方式其实只有一种 👨‍🎓一、继承Thread👨‍🎓二、实现Runnable接口👨‍🎓三、实现Callable接口👨‍🎓四、通过线程池创建👨‍🎓五、总结 一般…

java中创建线程的4种方式

写在前面的话 java线程创建方式有几种?这种问题在面试中经常被问到,你可能心里马上反映出两种方式(实现Runnable、继承Thread),当你把这两种叙述给面试官听后,面试官会觉得你该掌握的知识已经有了&#xf…

【 java 多线程】创建多线程的方式四:使用线程池创建多线程

📋 个人简介 💖 作者简介:大家好,我是阿牛,全栈领域优质创作者。😜📝 个人主页:馆主阿牛🔥🎉 支持我:点赞👍收藏⭐️留言&#x1f4d…

创建线程的方式

一般来说,创建线程有三种方式:继承 Thread 类、实现 Runnable 接口和实现 Callable 接口。 继承 Thread 类:继承 Thread 类,重写 run() 方法,调用 start() 方法启动线程。 public class MyThread {public static cla…

【JAVAEE】创建线程的方式及线程的常用方法

目录 1.创建线程的四种方式 1.1继承Thread类 1.2实现Runnable接口 1.3匿名内部类 1.4lambda表达式 2.多线程的优势-增加运行速度 3.Thread类及常用方法 3.1构造方法 3.2常见属性 演示后台线程 演示线程是否存活 3.3线程中断 3.4线程等待-join() 3.5获取当前线程 …

创建线程的方式有那些?

目录 一.创建线程的4种方式 二.创建线程方式有什么区别? 一.创建线程的4种方式 (1)写一个类继承Thread,覆盖重写run方法 (2)创建一个Runnable类型的对象,实现run()方法,传入Thread的构造方法中 &#x…

创建线程几种方式

创建线程的几种方式: 方式1:通过继承Thread类创建线程 步骤:1.定义Thread类的子类,并重写该类的run方法,该方法的方法体就是线程需要执行的任务,因此run()方法也被称为线程执行体 2.创建Thread子类的实例&a…

线程创建的四种方式

java中创建线程的四种方法以及区别 Java使用Thread类代表线程,所有的线程对象都必须是Thread类或其子类的实例。Java可以用四种方式来创建线程,如下所示: 1)继承Thread类创建线程 2)实现Runnable接口创建线程 3&am…

四种线程创建方式

一. 继承Thread类 继承Thread类创建线程的步骤: 创建一个自定义类继承Thread类,重写run()方法,将所要单独线程运行写入run()方法中;创建Thread类的子类的对象;调用该对象的start()方法,该start()方法表示开启线程,然后调用执行run方法; Testpublic void test() {Thread.curre…

创建线程的四种方式

我们创建线程池一般有四种方式,分别是: 1.继承Thread类,重写run()方法; 2.实现Runnable接口,重写run()方法; 3.实现Callable接口,重写call()方法; 4.使用线程池创建线程;…

线程创建常用的四种方式

java中创建线程的四种方法以及区别 Java使用Thread类代表线程,所有的线程对象都必须是Thread类或其子类的实例。Java可以用四种方式来创建线程,如下所示: 1)继承Thread类创建线程 2)实现Runnable接口创建线程 3&…

银行测试核心项目之测试阶段分享

最近有小伙伴说「想了解核心系统建设中,冒烟、SIT、UAT、回归测试的重点,如何设计测试案例,或相关的资料推荐等」。 这个话题很笼统,测试这一块儿除了业务测试,还有性能测试、安全测试等;以及不同的角色对…