8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

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

打开官方英文原文 ↗

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

MySQL 8.4 参考手册 / 20 组复制 / 20.10 常见问题
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

20.10 常见问题解答20.10 Frequently Asked Questions

本节提供常见问题的解答。This section provides answers to frequently asked questions.

组中 MySQL 服务器的最大数量是多少?What is the maximum number of MySQL servers in a group?

一个组最多可以包含 9 台服务器。尝试向已有 9 个成员的组中添加另一台服务器时,请求加入将被拒绝。通过测试和基准测评已确认,这一限制是一个安全的界限,使该组在稳定的局域网中能够可靠运行。A group can consist of maximum 9 servers. Attempting to add another server to a group with 9 members causes the request to join to be refused. This limit has been identified from testing and benchmarking as a safe boundary where the group performs reliably on a stable local area network.

组中的服务器如何连接?How are servers in a group connected?

组内的服务器通过建立点对点 TCP 连接来连接组中的其他服务器。这些连接仅用于组内服务器之间的内部通信和消息传递。该地址由 group_replication_local_address 变量配置。Servers in a group connect to the other servers in the group by opening a peer-to-peer TCP connection. These connections are only used for internal communication and message passing between servers in the group. This address is configured by the group_replication_local_address variable.

group_replication_bootstrap_group 选项是用来做什么的?What is the group_replication_bootstrap_group option used for?

bootstrap 标志指示一个成员 创建 一个组并作为初始种子服务器。加入组的第二个成员需要请求启动组的成员动态更改配置,以便将其添加到组中。The bootstrap flag instructs a member to create a group and act as the initial seed server. The second member joining the group needs to ask the member that bootstrapped the group to dynamically change the configuration in order for it to be added to the group.

成员在两种情况下需要引导该组:当组最初创建时,或当关闭并重新启动整个组时。A member needs to bootstrap the group in two scenarios. When the group is originally created, or when shutting down and restarting the entire group.

如何为分布式恢复过程设置凭据?How do I set credentials for the distributed recovery process?

您可以将用户凭据永久设置为 group_replication_recovery 通道的凭据,使用 CHANGE REPLICATION SOURCE TO 语句。您也可以在每次启动 Group Replication 时,在 START GROUP_REPLICATION 语句中指定它们。You can set the user credentials permanently as the credentials for the group_replication_recovery channel, using a CHANGE REPLICATION SOURCE TO statement. You can specify them in the START GROUP_REPLICATION statement each time Group Replication is started.

使用 CHANGE REPLICATION SOURCE TO 设置的用户凭据会以明文形式存储在服务器的复制元数据存储中,而在 START GROUP_REPLICATION 上指定的用户凭据仅保存在内存中,并会在执行 STOP GROUP_REPLICATION 语句或服务器关闭时被移除。因此,使用 START GROUP_REPLICATION 来指定用户凭据有助于保护组复制服务器免受未经授权的访问。然而,此方法与通过 group_replication_start_on_boot 系统变量指定的自动启动组复制不兼容。更多信息,请参见 第 20.6.3.1 节,“分布式恢复的安全用户凭据”。User credentials set using CHANGE REPLICATION SOURCE TO are stored in plain text in the replication metadata repositories on the server, but user credentials specified on START GROUP_REPLICATION are saved in memory only, and are removed by a STOP GROUP_REPLICATION statement or server shutdown. Using START GROUP_REPLICATION to specify the user credentials therefore helps to secure the Group Replication servers against unauthorized access. However, this method is not compatible with starting Group Replication automatically, as specified by the group_replication_start_on_boot system variable. For more information, see Section 20.6.3.1, “Secure User Credentials for Distributed Recovery”.

我可以使用组复制来扩展写入负载吗?Can I scale-out my write-load using Group Replication?

不能直接扩展,但 MySQL 组复制是一种无共享的完全复制解决方案,组中的所有服务器都复制相同数量的数据。因此,如果组中的一个成员在事务提交操作中向存储写入 N 字节,那么其他成员大约也会写入 N 字节,因为事务会在每个地方进行复制。Not directly, but MySQL Group replication is a shared nothing full replication solution, where all servers in the group replicate the same amount of data. Therefore if one member in the group writes N bytes to storage as the result of a transaction commit operation, then roughly N bytes are written to storage on other members as well, because the transaction is replicated everywhere.

然而,考虑到其他成员不必执行原始成员在最初执行事务时所需的相同处理,它们应用更改的速度更快。事务以仅用于应用行变换的格式进行复制,无需再次重新执行事务(基于行的格式)。However, given that other members do not have to do the same amount of processing that the original member had to do when it originally executed the transaction, they apply the changes faster. Transactions are replicated in a format that is used to apply row transformations only, without having to re-execute transactions again (row-based format).

此外,鉴于更改是以行基格式传播和应用的,这意味着它们以优化和紧凑的格式接收,并且相比于起始成员,可能减少所需的 IO 操作数量。Furthermore, given that changes are propagated and applied in row-based format, this means that they are received in an optimized and compact format, and likely reducing the number of IO operations required when compared to the originating member.

总而言之,你可以通过将无冲突事务分散到组内不同成员中来进行处理的横向扩展。而且,你可能只需扩展少量的 IO 操作,因为远程服务器只接收对稳定存储进行读-修改-写所需的更改。To summarize, you can scale-out processing, by spreading conflict free transactions throughout different members in the group. And you can likely scale-out a small fraction of your IO operations, since remote servers receive only the necessary changes to read-modify-write changes to stable storage.

与简单复制相比,在相同工作负载下,组复制是否需要更多的网络带宽和 CPU?Does Group Replication require more network bandwidth and CPU, when compared to simple replication and under the same workload?

由于服务器需要为了同步目的不断相互交互,因此预计会有一些额外负载。很难量化会产生多少额外数据。这也取决于组的规模(三台服务器对带宽需求的压力小于组中九台服务器)。Some additional load is expected because servers need to be constantly interacting with each other for synchronization purposes. It is difficult to quantify how much more data. It also depends on the size of the group (three servers puts less stress on the bandwidth requirements than nine servers in the group).

此外,内存和 CPU 的占用会更大,因为服务器同步部分和组消息传递部分需要处理更复杂的工作。Also the memory and CPU footprint are larger, because more complex work is done for the server synchronization part and for the group messaging.

我可以在广域网中部署组复制吗?Can I deploy Group Replication across wide-area networks?

可以,但每个成员之间的网络连接必须可靠,并具有适当的性能。低延迟、高带宽的网络连接是实现最佳性能的必要条件。Yes, but the network connection between each member must be reliable and have suitable performance. Low latency, high bandwidth network connections are a requirement for optimal performance.

如果只是网络带宽成为问题,那么可以使用第 20.7.4 节,“消息压缩”来降低所需带宽。然而,如果网络丢包,导致重传和更高的端到端延迟,则吞吐量和延迟都会受到负面影响。If network bandwidth alone is an issue, then Section 20.7.4, “Message Compression” can be used to lower the bandwidth required. However, if the network drops packets, leading to re-transmissions and higher end-to-end latency, throughput and latency are both negatively affected.

Warning

当任意组成员之间的网络往返时间(RTT)达到 5 秒或以上时,您可能会遇到问题,因为内置的故障检测机制可能会被错误触发。When the network round-trip time (RTT) between any group members is 5 seconds or more you could encounter problems as the built-in failure detection mechanism could be incorrectly triggered.

成员在临时连接问题的情况下会自动重新加入组吗?Do members automatically rejoin a group in case of temporary connectivity problems?

这取决于连接问题的原因。如果连接问题是短暂的,并且重新连接足够快以至于故障检测器没有意识到它,那么服务器可能不会被移出组。如果这是一个“长时间”的连接问题,那么故障检测器最终会怀疑出现问题,并且服务器会被移出组。This depends on the reason for the connectivity problem. If the connectivity problem is transient and the reconnection is quick enough that the failure detector is not aware of it, then the server may not be removed from the group. If it is a "long" connectivity problem, then the failure detector eventually suspects a problem and the server is removed from the group.

有两个设置可以增加成员保持在组中或重新加入组的机会:Two settings are available to increase the chances of a member remaining in or rejoining a group:

  • group_replication_member_expel_timeout 增加从创建怀疑(在初始 5 秒检测期后发生)到成员被驱逐之间的时间。你可以设置最长为 1 小时的等待时间。默认的等待时间为 5 秒。group_replication_member_expel_timeout increases the time between the creation of a suspicion (which happens after an initial 5-second detection period) and the expulsion of the member. You can set a waiting period of up to 1 hour. A waiting period of 5 seconds is set by default.

  • group_replication_autorejoin_tries 使成员在被排除或不可达的多数超时后尝试重新加入组。该成员会按五分钟间隔进行指定次数的自动重加入尝试。此功能默认处于启用状态;成员会进行三次自动重新加入尝试。group_replication_autorejoin_tries makes a member try to rejoin the group after an expulsion or unreachable majority timeout. The member makes the specified number of auto-rejoin attempts five minutes apart. This feature is active by default; the member makes three auto-rejoin attempts.

如果服务器被排除出组,并且任何自动重加入尝试都未成功,你需要再次将其加入组。换句话说,在服务器被明确从组中移除后,你需要手动(或者通过脚本自动)重新加入它。If a server is expelled from the group and any auto-rejoin attempts do not succeed, you need to join it back again. In other words, after a server is removed explicitly from the group you need to rejoin it manually (or have a script doing it automatically).

成员在什么情况下会被排除出组?When is a member excluded from a group?

如果成员变得沉默,其他成员会将其从组配置中移除。实际上,当成员崩溃或网络断开时,这种情况可能会发生。If the member becomes silent, the other members remove it from the group configuration. In practice this may happen when the member has crashed or there is a network disconnection.

在给定成员的超时时间过去后,将会检测到故障,并创建一个不包含该沉默成员的新配置。The failure is detected after a given timeout elapses for a given member and a new configuration without the silent member in it is created.

当一个节点明显落后时会发生什么?What happens when one node is significantly lagging behind?

没有定义自动将成员从组中开除的策略的方法。你需要找出成员落后的原因并解决,或者将该成员从组中移除。否则,如果服务器太慢以至于触发流量控制,那么整个组也会变慢。流量控制可以根据你的需求进行配置。There is no method for defining policies for when to expel members automatically from the group. You need to find out why a member is lagging behind and fix that or remove the member from the group. Otherwise, if the server is so slow that it triggers the flow control, then the entire group slows down as well. The flow control can be configured according to the your needs.

当怀疑群组中出现问题时,是否有某个特定成员负责触发重新配置?Upon suspicion of a problem in the group, is there a special member responsible for triggering a reconfiguration?

不,群组中没有特定成员负责触发重新配置。No, there is no special member in the group in charge of triggering a reconfiguration.

任何成员都可以怀疑存在问题。所有成员都需要(自动地)同意某个成员已失败。一个成员负责将其从群组中驱逐,通过触发重新配置。负责驱逐该成员的成员是无法控制或设置的。Any member can suspect that there is a problem. All members need to (automatically) agree that a given member has failed. One member is in charge of expelling it from the group, by triggering a reconfiguration. Which member is responsible for expelling the member is not something you can control or set.

我可以使用群组复制进行分片吗?Can I use Group Replication for sharding?

组复制旨在提供高可用的副本集;数据和写入会在组中的每个成员上复制。为了实现超出单个系统所能提供的扩展,您需要一个围绕多个组复制集构建的编排和分片框架,其中每个副本集维护和管理总数据集的某个分片或分区。这种类型的设置,通常称为“分片集群”,允许您线性且无限地扩展读写能力。Group Replication is designed to provide highly available replica sets; data and writes are duplicated on each member in the group. For scaling beyond what a single system can provide, you need an orchestration and sharding framework built around a number of Group Replication sets, where each replica set maintains and manages a given shard or partition of your total dataset. This type of setup, often called a “sharded cluster”, allows you to scale reads and writes linearly and without limit.

如何在 SELinux 下使用组复制?How do I use Group Replication with SELinux?

如果启用了 SELinux,您可以使用 sestatus -v 来验证,那么您需要启用组复制通信端口的使用。请参阅 为组复制设置 TCP 端口上下文。If SELinux is enabled, which you can verify using sestatus -v, then you need to enable the use of the Group Replication communication port. See Setting the TCP Port Context for Group Replication.

我如何在 iptables 中使用组复制?How do I use Group Replication with iptables?

如果启用了iptables,那么您需要开放组复制端口以便机器之间进行通信。要查看每台机器上当前的规则,执行 iptables -L。假设配置的端口是 33061,通过执行 iptables -A INPUT -p tcp --dport 33061 -j ACCEPT 来启用必要端口的通信。If iptables is enabled, then you need to open up the Group Replication port for communication between the machines. To see the current rules in place on each machine, issue iptables -L. Assuming the port configured is 33061, enable communication over the necessary port by issuing iptables -A INPUT -p tcp --dport 33061 -j ACCEPT.

我如何恢复某个组成员使用的复制通道的中继日志?How do I recover the relay log for a replication channel used by a group member?

组复制使用的复制通道的行为与异步源到副本复制中使用的复制通道相同,因此依赖中继日志。如果更改了relay_log变量,或者当该选项未设置且主机名发生变化时,可能会出现错误。有关此情况下的恢复程序,请参阅第 19.2.4.1 节,“中继日志”。或者,在组复制中解决此问题的另一种方法是先执行STOP GROUP_REPLICATION语句,然后执行START GROUP_REPLICATION语句以重启实例。组复制插件将再次创建group_replication_applier通道。The replication channels used by Group Replication behave in the same way as replication channels used in asynchronous source to replica replication, and as such rely on the relay log. In the event of a change of the relay_log variable, or when the option is not set and the host name changes, there is a chance of errors. See Section 19.2.4.1, “The Relay Log” for a recovery procedure in this situation. Alternatively, another way of fixing the issue specifically in Group Replication is to issue a STOP GROUP_REPLICATION statement and then a START GROUP_REPLICATION statement to restart the instance. The Group Replication plugin creates the group_replication_applier channel again.

为什么组复制使用两个绑定地址?Why does Group Replication use two bind addresses?

组复制使用两个绑定地址,以便在 SQL 地址(客户端用于与成员通信)和 group_replication_local_address(组成员内部用于通信)之间分配网络流量。例如,假设一个服务器有两个网络接口,分配到网络地址 203.0.113.1 和 198.51.100.179。在这种情况下,可以通过设置 group_replication_local_address=203.0.113.1:33061 来使用 203.0.113.1:33061 作为内部组网络地址。然后可以使用 198.51.100.179 作为 hostname,并使用 3306 作为 port。客户端 SQL 应用程序随后将连接到成员的 198.51.100.179:3306。这使您能够在不同网络上配置不同的规则。同样,内部组通信可以与用于客户端应用程序的网络连接分离,从而提高安全性。Group Replication uses two bind addresses in order to split network traffic between the SQL address, used by clients to communicate with the member, and the group_replication_local_address, used internally by the group members to communicate. For example, assume a server with two network interfaces assigned to the network addresses 203.0.113.1 and 198.51.100.179. In such a situation you could use 203.0.113.1:33061 for the internal group network address by setting group_replication_local_address=203.0.113.1:33061. Then you could use 198.51.100.179 for hostname and 3306 for the port. Client SQL applications would then connect to the member at 198.51.100.179:3306. This enables you to configure different rules on the different networks. Similarly, the internal group communication can be separated from the network connection used for client applications, for increased security.

组复制如何使用网络地址和主机名?How does Group Replication use network addresses and hostnames?

组复制使用成员之间的网络连接,因此其功能直接受到您配置主机名和端口的方式的影响。例如,组复制的分布式恢复过程会使用服务器的主机名和端口与现有组成员建立连接。当成员加入组时,它会接收组成员信息,使用在performance_schema.replication_group_members中列出的网络地址信息。该表中列出的成员之一会被选为向加入成员提供组中缺失数据的捐赠者。Group Replication uses network connections between members and therefore its functionality is directly impacted by how you configure hostnames and ports. For example, Group Replication's distributed recovery process creates a connection to an existing group member using the server's hostname and port. When a member joins a group it receives the group membership information, using the network address information that is listed at performance_schema.replication_group_members. One of the members listed in that table is selected as the donor of the missing data from the group to the joining member.

这意味着您使用主机名配置的任何值,例如 SQL 网络地址或组种子地址,必须是完全限定的名称,并且能够被组中的每个成员解析。您可以通过 DNS、正确配置的 /etc/hosts 文件或其他本地进程来确保这一点。例如,如果您想在服务器上配置 MEMBER_HOST 值,请在服务器加入组之前使用 --report-host 选项指定。This means that any value you configure using a hostname, such as the SQL network address or the group seeds address, must be a fully qualified name and resolvable by each member of the group. You can ensure this for example through DNS, or correctly configured /etc/hosts files, or other local processes. If a you want to configure the MEMBER_HOST value on a server, specify it using the --report-host option on the server before joining it to the group.

Important

分配的值将被直接使用,不受 skip_name_resolve 系统变量的影响。The assigned value is used directly and is not affected by the skip_name_resolve system variable.

要在服务器上配置 MEMBER_PORT,请使用 report_port 系统变量指定它。To configure MEMBER_PORT on a server, specify it using the report_port system variable.

为什么服务器上的自增设置会改变?Why did the auto increment setting on the server change?

当在服务器上启动组复制时,auto_increment_increment 的值会更改为 group_replication_auto_increment_increment 的值,默认值为 7,并且 auto_increment_offset 的值会更改为服务器 ID。当停止组复制时,这些更改会被恢复。这些设置可以避免在组成员上写入时选择重复的自动递增值,从而导致事务回滚。组复制的默认自动递增值 7 代表了可用值数量和允许的复制组最大规模(9 个成员)之间的平衡。When Group Replication is started on a server, the value of auto_increment_increment is changed to the value of group_replication_auto_increment_increment, which defaults to 7, and the value of auto_increment_offset is changed to the server ID. The changes are reverted when Group Replication is stopped. These settings avoid the selection of duplicate auto-increment values for writes on group members, which causes rollback of transactions. The default auto increment value of 7 for Group Replication represents a balance between the number of usable values and the permitted maximum size of a replication group (9 members).

这些更改只有在 auto_increment_increment 和 auto_increment_offset 的值都为默认值(两者均为 1)时才会进行并被恢复。如果它们的值已经被修改过,Group Replication 不会更改它们。当 Group Replication 处于单主模式(只有一个服务器写入)时,系统变量也不会被修改。The changes are made and reverted only if auto_increment_increment and auto_increment_offset each has its default value (1 in both cases). If their values have already been modified from the default, Group Replication does not alter them. The system variables are also not modified when Group Replication is in single-primary mode, where only one server writes.

我如何找到主节点?How do I find the primary?

如果该组以单主模式运行,找出哪个成员是主节点可能会很有用。参见 第 20.1.3.1.2 节,“查找主节点”If the group is operating in single-primary mode, it can be useful to find out which member is the primary. See Section 20.1.3.1.2, “Finding the Primary”