8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 20 组复制 / 20.2 入门 / 20.2.2 本地部署组复制
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

20.2.2 本地部署 Group Replication20.2.2 Deploying Group Replication Locally

部署 Group Replication 最常见的方式是使用多个服务器实例,以提供高可用性。也可以在本地部署 Group Replication,例如用于测试目的。本节说明了如何在本地部署 Group Replication。The most common way to deploy Group Replication is using multiple server instances, to provide high availability. It is also possible to deploy Group Replication locally, for example for testing purposes. This section explains how you can deploy Group Replication locally.

Important

组复制通常部署在多个主机上,因为这可以确保提供高可用性。本节中的说明不适用于生产环境部署,因为所有 MySQL 服务器实例都运行在同一个主机上。如果该主机发生故障,整个组将失败。因此,这些信息应仅用于测试目的,不应在生产环境中使用。Group Replication is usually deployed on multiple hosts because this ensures that high-availability is provided. The instructions in this section are not suitable for production deployments because all MySQL server instances are running on the same single host. In the event of failure of this host, the whole group fails. Therefore this information should be used for testing purposes and it should not be used in a production environments.

本节说明如何在一台物理机器上使用三个 MySQL 服务器实例创建复制组。这意味着需要三个数据目录,每个服务器实例一个,并且需要独立配置每个实例。本程序假设 MySQL 服务器已下载并解压到名为 mysql-8.4 的目录中。每个 MySQL 服务器实例都需要一个特定的数据目录。创建一个名为 data 的目录,然后在该目录中为每个服务器实例创建一个子目录,例如 s1、s2 和 s3,并初始化每个实例。This section explains how to create a replication group with three MySQL Server instances on one physical machine. This means that three data directories are needed, one per server instance, and that you need to configure each instance independently. This - procedure assumes that MySQL Server was downloaded and unpacked - into the directory named mysql-8.4. Each MySQL server instance requires a specific data directory. Create a directory named data, then in that directory create a subdirectory for each server instance, for example s1, s2 and s3, and initialize each one.

mysql-8.4/bin/mysqld --initialize-insecure --basedir=$PWD/mysql-8.4 --datadir=$PWD/data/s1
mysql-8.4/bin/mysqld --initialize-insecure --basedir=$PWD/mysql-8.4 --datadir=$PWD/data/s2
mysql-8.4/bin/mysqld --initialize-insecure --basedir=$PWD/mysql-8.4 --datadir=$PWD/data/s3

在 data/s1、data/s2、data/s3 目录中,是一个已初始化的数据目录,包含 mysql 系统数据库及相关表格等更多内容。要了解有关初始化过程的更多信息,请参见 第 2.9.1 节,“初始化数据目录”。Inside data/s1, data/s2, data/s3 is an initialized data directory, containing the mysql system database and related tables and much more. To learn more about the initialization procedure, see Section 2.9.1, “Initializing the Data Directory”.

Warning

不要在生产环境中使用 -initialize-insecure,这里仅用于简化教程。有关安全设置的更多信息,请参见 第 20.6 节,“组复制安全”。Do not use -initialize-insecure in production environments, it is only used here to simplify the tutorial. For more information on security settings, see Section 20.6, “Group Replication Security”.

本地组复制成员的配置Configuration of Local Group Replication Members

当您按照第 20.2.1.2 节,“为组复制配置实例”操作时,您需要为上一节中添加的数据目录添加配置。例如:When you are following Section 20.2.1.2, “Configuring an Instance for Group Replication”, you need to add configuration for the data directories added in the previous section. For example:

[mysqld]

# server configuration
datadir=<full_path_to_data>/data/s1
basedir=<full_path_to_bin>/mysql-8.4/

port=24801
socket=<full_path_to_sock_dir>/s1.sock

这些设置配置 MySQL 服务器使用先前创建的数据目录,以及服务器应该开启哪个端口并开始监听传入连接。These settings configure MySQL server to use the data directory created earlier and which port the server should open and start listening for incoming connections.

Note

使用非默认端口 24801 是因为在本教程中三个服务器实例使用相同的主机名。在三台不同机器的设置中,这将不是必需的。The non-default port of 24801 is used because in this tutorial the three server instances use the same hostname. In a setup with three different machines this would not be required.

组复制需要成员之间的网络连接,这意味着每个成员必须能够解析所有其他成员的网络地址。例如,在本教程中,三个实例都运行在一台机器上,所以为了确保成员能够互相联系,你可以在选项文件中添加一行,如 report_host=127.0.0.1。Group Replication requires a network connection between the members, which means that each member must be able to resolve the network address of all of the other members. For example in this tutorial all three instances run on one machine, so to ensure that the members can contact each other you could add a line to the option file such as report_host=127.0.0.1.

然后每个成员需要能够连接到其他成员的 group_replication_local_address。例如,在成员 s1 的选项文件中添加:Then each member needs to be able to connect to the other members on their group_replication_local_address. For example in the option file of member s1 add:

group_replication_local_address= "127.0.0.1:24901"
group_replication_group_seeds= "127.0.0.1:24901,127.0.0.1:24902,127.0.0.1:24903"

此配置使 s1 使用端口 24901 与种子成员进行内部组通信。对于要添加到组中的每个服务器实例,请在该成员的选项文件中进行这些更改。对于每个成员,必须确保指定唯一的地址,因此每个实例的 group_replication_local_address 使用唯一的端口。通常,希望所有成员都能作为加入组且尚未处理组事务的成员的种子。在这种情况下,如上所示,将所有端口添加到 group_replication_group_seeds。This configures s1 to use port 24901 for internal group communication with seed members. For each server instance you want to add to the group, make these changes in the option file of the member. For each member you must ensure a unique address is specified, so use a unique port per instance for group_replication_local_address. Usually you want all members to be able to serve as seeds for members that are joining the group and have not got the transactions processed by the group. In this case, add all of the ports to group_replication_group_seeds as shown above.

第 20.2.1 节,“以单主模式部署组复制”的其余步骤同样适用于您以这种方式在本地部署的组。The remaining steps of Section 20.2.1, “Deploying Group Replication in Single-Primary Mode” apply equally to a group which you have deployed locally in this way.