除了中央配置文件之外,集群还可以通过管理客户端提供的命令行界面进行控制,ndb_mgm。这是对正在运行的集群进行管理的主要接口。In addition to the central configuration file, a cluster may also be controlled through a command-line interface available through the management client ndb_mgm. This is the primary administrative interface to a running cluster.
事件日志的命令在第 25.6.3 节,“在 NDB 集群中生成的事件报告”中给出;创建备份和从备份恢复的命令在第 25.6.8 节,“NDB 集群的在线备份”中提供。Commands for the event logs are given in Section 25.6.3, “Event Reports Generated in NDB Cluster”; commands for creating backups and restoring from them are provided in Section 25.6.8, “Online Backup of NDB Cluster”.
在 MySQL 集群管理器中使用 ndb_mgm。 MySQL 集群管理器负责启动和停止进程,并在内部跟踪其状态,因此对于在 MySQL 集群管理器控制下的 NDB 集群来说,不需要使用 ndb_mgm 来执行这些任务。建议 不要 使用随 NDB 集群发行版提供的 ndb_mgm 命令行客户端来执行涉及启动或停止节点的操作。这些操作包括但不限于 START、STOP、RESTART 和 SHUTDOWN 命令。欲了解更多信息,请参见 MySQL 集群管理器进程命令。Using ndb_mgm with MySQL Cluster Manager.
MySQL Cluster Manager handles starting and stopping processes and tracks their
states internally, so it is not necessary to use
ndb_mgm for these tasks for an NDB Cluster
that is under MySQL Cluster Manager control. It is recommended
not to use the ndb_mgm
command-line client that comes with the NDB Cluster distribution
to perform operations that involve starting or stopping nodes.
These include but are not limited to the
START,
STOP,
RESTART, and
SHUTDOWN commands. For more
information, see MySQL Cluster Manager Process Commands.
管理客户端具有以下基本命令。在下列列表中,node_id 表示数据节点 ID 或关键字 ALL,表示命令应应用于集群的所有数据节点。The management client has the following basic commands. In the
listing that follows, node_id denotes
either a data node ID or the keyword ALL, which
indicates that the command should be applied to all of the
cluster's data nodes.
连接到由连接字符串指定的管理服务器。如果客户端已经连接到此服务器,客户端将重新连接。Connects to the management server indicated by the connection string. If the client is already connected to this server, the client reconnects.
CREATE NODEGROUPnodeid[,nodeid, ...]创建一个新的 NDB 集群节点组,并使数据节点加入该组。Creates a new NDB Cluster node group and causes data nodes to join it.
此命令在向 NDB 集群在线添加新数据节点后使用,使它们加入新的节点组,从而开始在集群中完全参与。该命令的唯一参数是以逗号分隔的节点 ID 列表——这些是刚刚添加并启动的节点的 ID,它们将加入新的节点组。列表中不得有重复的 ID;如果存在任何重复,则命令将返回错误。列表中的节点数量必须与集群中每个已有节点组的节点数量相同(每个 NDB 集群节点组必须有相同数量的节点)。换句话说,如果 NDB 集群由 2 个节点组组成,每个节点组有 2 个数据节点,那么新的节点组也必须有 2 个数据节点。This command is used after adding new data nodes online to an NDB Cluster, and causes them to join a new node group and thus to begin participating fully in the cluster. The command takes as its sole parameter a comma-separated list of node IDs—these are the IDs of the nodes just added and started, and that are to join the new node group. The list must contain no duplicate IDs; the presence of any duplicates causes the command to return an error. The number of nodes in the list must be the same as the number of nodes in each node group that is already part of the cluster (each NDB Cluster node group must have the same number of nodes). In other words, if the NDB Cluster consists of 2 node groups having 2 data nodes each, then the new node group must also have 2 data nodes.
由此命令创建的新节点组的节点组 ID 会自动确定,并且始终是集群中下一个未使用的最高节点组 ID;无法手动设置。The node group ID of the new node group created by this command is determined automatically, and always the next highest unused node group ID in the cluster; it is not possible to set it manually.
有关更多信息,请参见 第 25.6.7 节,“在线添加 NDB Cluster 数据节点”。For more information, see Section 25.6.7, “Adding NDB Cluster Data Nodes Online”.
删除具有指定
nodegroup_id的 NDB Cluster 节点组。Drops the NDB Cluster node group with the givennodegroup_id.此命令可用于从 NDB Cluster 中删除节点组。
DROP NODEGROUP的唯一参数是要删除的节点组的节点组 ID。This command can be used to drop a node group from an NDB Cluster.DROP NODEGROUPtakes as its sole argument the node group ID of the node group to be dropped.DROP NODEGROUP仅用于从受影响的节点组中移除数据节点。它不会停止数据节点,不会将它们分配到其他节点组,也不会将它们从集群配置中移除。一个不属于任何节点组的数据节点将在管理客户端的SHOW命令输出中显示为no nodegroup以替代节点组 ID,如下所示(用粗体文本表示):DROP NODEGROUPacts only to remove the data nodes in the effected node group from that node group. It does not stop data nodes, assign them to a different node group, or remove them from the cluster's configuration. A data node that does not belong to a node group is indicated in the output of the management clientSHOWcommand withno nodegroupin place of the node group ID, like this (indicated using bold text):id=3 @10.100.2.67 (8.4.7-ndb-8.4.7, no nodegroup)DROP NODEGROUP仅在要删除的节点组中的所有数据节点完全没有任何表数据和表定义时才有效。由于目前无法使用 ndb_mgm 或 mysql 客户端从特定数据节点或节点组中删除所有数据,这意味着该命令仅在以下两种情况下成功:DROP NODEGROUPworks only when all data nodes in the node group to be dropped are completely empty of any table data and table definitions. Since there is currently no way using ndb_mgm or the mysql client to remove all data from a specific data node or node group, this means that the command succeeds only in the two following cases:在 ndb_mgm 客户端中发出
CREATE NODEGROUP之后,但在 mysql 客户端中发出任何ALTER TABLE ... REORGANIZE PARTITION语句之前。After issuingCREATE NODEGROUPin the ndb_mgm client, but before issuing anyALTER TABLE ... REORGANIZE PARTITIONstatements in the mysql client.使用
DROP TABLE删除所有NDBCLUSTER表之后。After dropping allNDBCLUSTERtables usingDROP TABLE.TRUNCATE TABLE对此目的无效,因为它只会删除表数据;数据节点仍然会存储NDBCLUSTER表的定义,直到执行DROP TABLE语句,从而导致表元数据被删除。TRUNCATE TABLEdoes not work for this purpose because this removes only the table data; the data nodes continue to store anNDBCLUSTERtable's definition until aDROP TABLEstatement is issued that causes the table metadata to be dropped.
有关
DROP NODEGROUP的更多信息,请参见 第 25.6.7 节,“在线添加 NDB 集群数据节点”。For more information aboutDROP NODEGROUP, see Section 25.6.7, “Adding NDB Cluster Data Nodes Online”.ENTER SINGLE USER MODE node_idENTER SINGLE USER MODEnode_id进入单用户模式,此模式下只有由节点 ID
node_id标识的 MySQL 服务器被允许访问数据库。Enters single user mode, whereby only the MySQL server identified by the node IDnode_idis permitted to access the database.ndb_mgm 客户端会清楚地确认已发出此命令并已生效,如下所示:The ndb_mgm client provides a clear acknowledgement that this command has been issued and has taken effect, as shown here:
ndb_mgm>
ENTER SINGLE USER MODE 100Single user mode entered Access is granted for API node 100 only.此外,当处于单用户模式时,API 或 SQL 节点拥有独占访问权限,这在
SHOW命令的输出中会显示如下:In addition, the API or SQL node having exclusive access when in single user mode is indicated in the output of theSHOWcommand, like this:ndb_mgm>
SHOWCluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=5 @127.0.0.1 (mysql-8.4.7 ndb-8.4.7, single user mode, Nodegroup: 0, *) id=6 @127.0.0.1 (mysql-8.4.7 ndb-8.4.7, single user mode, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s) id=50 @127.0.0.1 (mysql-8.4.7 ndb-8.4.7) [mysqld(API)] 2 node(s) id=100 @127.0.0.1 (mysql-8.4.7 ndb-8.4.7, allowed single user) id=101 (not connected, accepting connect from any host)退出单用户模式,使所有 SQL 节点(即所有运行中的 mysqld 进程)可以访问数据库。Exits single user mode, enabling all SQL nodes (that is, all running mysqld processes) to access the database.
Note即使不处于单用户模式,也可以使用
EXIT SINGLE USER MODE,尽管在这种情况下该命令不会产生任何效果。It is possible to useEXIT SINGLE USER MODEeven when not in single user mode, although the command has no effect in this case.显示所有可用命令的信息。Displays information on all available commands.
node_id NODELOG DEBUG {ON|OFF}node_idNODELOG DEBUG {ON|OFF}切换节点日志中的调试日志,就像受影响的数据节点已使用
--verbose选项启动一样。NODELOG DEBUG ON启动调试日志;NODELOG DEBUG OFF关闭调试日志。Toggles debug logging in the node log, as though the effected data node or nodes had been started with the--verboseoption.NODELOG DEBUG ONstarts debug logging;NODELOG DEBUG OFFswitches debug logging off.将ndb_mgm显示的提示符更改为字符串字面值
prompt。Changes the prompt shown by ndb_mgm to the string literalprompt.prompt不应加引号(除非你希望提示符包含引号)。与 mysql 客户端不同,特殊字符序列和转义不会被识别。如果在没有参数的情况下调用该命令,提示符将重置为默认值(ndb_mgm>)。promptshould not be quoted (unless you want the prompt to include the quotation marks). Unlike the case with the mysql client, special character sequences and escapes are not recognized. If called without an argument, the command resets the prompt to the default value (ndb_mgm>).以下是一些示例:Some examples are shown here:
ndb_mgm>
PROMPT mgm#1:mgm#1:SHOWCluster Configuration ... mgm#1:PROMPT mymgm >mymgm >PROMPT 'mymgm:''mymgm:'PROMPT mymgm:mymgm:PROMPTndb_mgm>EXIT$>请注意,
prompt字符串的前导空格和中间空格不会被去掉。尾随空格将被删除。Note that leading spaces and spaces within thepromptstring are not trimmed. Trailing spaces are removed.终止管理客户端。Terminates the management client.
此命令不会影响连接到集群的任何节点。This command does not affect any nodes connected to the cluster.
显示由
node_id标识的数据节点的report-type类型报告,或者使用ALL显示所有数据节点的报告。Displays a report of typereport-typefor the data node identified bynode_id, or for all data nodes usingALL.目前,对于
report-type,有三个可接受的值:Currently, there are three accepted values forreport-type:BackupStatus提供正在进行的集群备份的状态报告BackupStatusprovides a status report on a cluster backup in progressMemoryUsage显示每个数据节点使用了多少数据内存和索引内存,如下示例所示:MemoryUsagedisplays how much data memory and index memory is being used by each data node as shown in this example:ndb_mgm>
ALL REPORT MEMORYNode 1: Data usage is 5%(177 32K pages of total 3200) Node 1: Index usage is 0%(108 8K pages of total 12832) Node 2: Data usage is 5%(177 32K pages of total 3200) Node 2: Index usage is 0%(108 8K pages of total 12832)这些信息也可以从
ndbinfo.memoryusage表中获取。This information is also available from thendbinfo.memoryusagetable.EventLog报告来自一个或多个数据节点的事件日志缓冲区的事件。EventLogreports events from the event log buffers of one or more data nodes.
report-type不区分大小写,并且是“模糊”的;对于MemoryUsage,你可以使用MEMORY(如前例所示)、memory,甚至可以简单地使用MEM(或mem)。你也可以以类似的方式缩写BackupStatus。report-typeis case-insensitive and “fuzzy”; forMemoryUsage, you can useMEMORY(as shown in the prior example),memory, or even simplyMEM(ormem). You can abbreviateBackupStatusin a similar fashion.node_idRESTART [-n] [-i] [-a] [-f]重启由
node_id指定的数据节点(或所有数据节点)。Restarts the data node identified bynode_id(or all data nodes).使用
-i选项配合RESTART会导致数据节点执行初始重启;也就是说,节点的文件系统会被删除并重新创建。其效果与先停止数据节点进程,然后使用系统 shell 通过 ndbd--initial再次启动节点相同。Using the-ioption withRESTARTcauses the data node to perform an initial restart; that is, the node's file system is deleted and recreated. The effect is the same as that obtained from stopping the data node process and then starting it again using ndbd--initialfrom the system shell.Note使用此选项时,备份文件和磁盘数据文件不会被删除。Backup files and Disk Data files are not removed when this option is used.
使用
-n选项会导致数据节点进程重新启动,但数据节点实际上不会上线,直到执行相应的START命令为止。此选项的效果与停止数据节点然后使用 ndbd--nostart或 ndbd-n从系统命令行再次启动获得的效果相同。Using the-noption causes the data node process to be restarted, but the data node is not actually brought online until the appropriateSTARTcommand is issued. The effect of this option is the same as that obtained from stopping the data node and then starting it again using ndbd--nostartor ndbd-nfrom the system shell.使用
-a会导致所有依赖此节点的当前事务被中止。当节点重新加入集群时,不会进行 GCP 检查。Using the-acauses all current transactions relying on this node to be aborted. No GCP check is done when the node rejoins the cluster.通常,如果将节点下线会导致集群不完整,
RESTART会失败。-f选项会强制节点在不检查的情况下重新启动。如果使用此选项并且导致集群不完整,则整个集群会被重启。Normally,RESTARTfails if taking the node offline would result in an incomplete cluster. The-foption forces the node to restart without checking for this. If this option is used and the result is an incomplete cluster, the entire cluster is restarted.显示有关集群和集群节点的基本信息。对于所有节点,输出包括节点的 ID、类型以及
NDB软件版本。如果节点已连接,还会显示其 IP 地址;否则输出会显示not connected, accepting connect from ip_address,对于允许从任何地址连接的节点,则显示any host。Displays basic information about the cluster and cluster nodes. For all nodes, the output includes the node's ID, type, andNDBsoftware version. If the node is connected, its IP address is also shown; otherwise the output showsnot connected, accepting connect from, withip_addressany hostused for nodes that are permitted to connect from any address.此外,对于数据节点,如果节点尚未启动,输出中会包括
starting,并显示该节点所属的节点组。如果数据节点充当主节点,则会用星号 (*) 表示。In addition, for data nodes, the output includesstartingif the node has not yet started, and shows the node group of which the node is a member. If the data node is acting as the master node, this is indicated with an asterisk (*).考虑一个其配置文件包括此处显示信息的集群(为了清晰省略了可能的其他设置):Consider a cluster whose configuration file includes the information shown here (possible additional settings are omitted for clarity):
[ndbd default] DataMemory= 128G NoOfReplicas= 2 [ndb_mgmd] NodeId=50 HostName=198.51.100.150 [ndbd] NodeId=5 HostName=198.51.100.10 DataDir=/var/lib/mysql-cluster [ndbd] NodeId=6 HostName=198.51.100.20 DataDir=/var/lib/mysql-cluster [ndbd] NodeId=7 HostName=198.51.100.30 DataDir=/var/lib/mysql-cluster [ndbd] NodeId=8 HostName=198.51.100.40 DataDir=/var/lib/mysql-cluster [mysqld] NodeId=100 HostName=198.51.100.100 [api] NodeId=101
在启动此集群(包括一个 SQL 节点)后,
SHOW显示以下输出:After this cluster (including one SQL node) has been started,SHOWdisplays the following output:ndb_mgm>
SHOWConnected to Management Server at: localhost:1186 (using cleartext) Cluster Configuration --------------------- [ndbd(NDB)] 4 node(s) id=5 @198.51.100.10 (mysql-8.4.7 ndb-8.4.7, Nodegroup: 0, *) id=6 @198.51.100.20 (mysql-8.4.7 ndb-8.4.7, Nodegroup: 0) id=7 @198.51.100.30 (mysql-8.4.7 ndb-8.4.7, Nodegroup: 1) id=8 @198.51.100.40 (mysql-8.4.7 ndb-8.4.7, Nodegroup: 1) [ndb_mgmd(MGM)] 1 node(s) id=50 @198.51.100.150 (mysql-8.4.7 ndb-8.4.7) [mysqld(API)] 2 node(s) id=100 @198.51.100.100 (mysql-8.4.7 ndb-8.4.7) id=101 (not connected, accepting connect from any host)此命令的输出还会指示集群处于单用户模式的时间(请参见
ENTER SINGLE USER MODE命令的说明,以及 第 25.6.6 节,“NDB 集群单用户模式”)。它还会指示在此模式生效时哪个 API 或 SQL 节点拥有独占访问权限。The output from this command also indicates when the cluster is in single user mode (see the description of theENTER SINGLE USER MODEcommand, as well as Section 25.6.6, “NDB Cluster Single User Mode”). It also indicates which API or SQL node has exclusive access when this mode is in effect.关闭所有集群数据节点和管理节点。完成此操作后,要退出管理客户端,请使用
EXIT或QUIT。Shuts down all cluster data nodes and management nodes. To exit the management client after this has been done, useEXITorQUIT.此命令 不会 关闭连接到集群的任何 SQL 节点或 API 节点。This command does not shut down any SQL nodes or API nodes that are connected to the cluster.
上线由
node_id标识的数据节点(或所有数据节点)。Brings online the data node identified bynode_id(or all data nodes).ALL START仅对所有数据节点生效,不影响管理节点。ALL STARTworks on all data nodes only, and does not affect management nodes.显示由
node_id标识的数据节点(或所有数据节点)的状态信息。Displays status information for the data node identified bynode_id(or for all data nodes).可能的节点状态值包括
UNKNOWN、NO_CONTACT、NOT_STARTED、STARTING、STARTED、SHUTTING_DOWN和RESTARTING。Possible node status values includeUNKNOWN,NO_CONTACT,NOT_STARTED,STARTING,STARTED,SHUTTING_DOWN, andRESTARTING.此命令的输出还指示集群何时处于单用户模式。The output from this command also indicates when the cluster is in single user mode.
停止由
node_id标识的数据节点或管理节点。Stops the data or management node identified bynode_id.NoteALL STOP只能停止所有数据节点,不影响管理节点。ALL STOPworks to stop all data nodes only, and does not affect management nodes.受此命令影响的节点将从集群断开,其关联的 ndbd 或 ndb_mgmd 进程会终止。A node affected by this command disconnects from the cluster, and its associated ndbd or ndb_mgmd process terminates.
-a选项会导致节点立即停止,而不等待任何未完成事务的完成。The-aoption causes the node to be stopped immediately, without waiting for the completion of any pending transactions.通常,如果操作结果会导致集群不完整,
STOP会失败。-f选项强制节点关闭,而不检查这一点。如果使用此选项且结果导致集群不完整,则集群会立即关闭。Normally,STOPfails if the result would cause an incomplete cluster. The-foption forces the node to shut down without checking for this. If this option is used and the result is an incomplete cluster, the cluster immediately shuts down.Warning使用
-a选项还会禁用在调用STOP时通常执行的安全检查,以确保停止节点不会导致集群不完整。换句话说,由于该选项可能导致集群强制关闭,因为它不再拥有存储在NDB中的所有数据的完整副本,因此在使用-a选项与STOP命令时,应非常小心。Use of the-aoption also disables the safety check otherwise performed whenSTOPis invoked to insure that stopping the node does not cause an incomplete cluster. In other words, you should exercise extreme care when using the-aoption with theSTOPcommand, due to the fact that this option makes it possible for the cluster to undergo a forced shutdown because it no longer has a complete copy of all data stored inNDB.显示集群 TLS 信息,例如当前连接是否使用 TLS、管理节点当前已知的 TLS 证书,以及管理节点的总连接数、升级为 TLS 的连接数和授权失败次数。示例输出如下所示:Displays cluster TLS information such as whether the current connection is using TLS, TLS certificates currently known to the management node, and the management node's counts of total connections, connections upgraded to TLS, and authorization failures. Sample output is shown here:
ndb_mgm>
TLS INFOSession ID: 1 Peer address: 127.0.0.1 Certificate name: NDB Management Node Jun 2023 Certificate serial: B5:23:8F:D1:11:85:E5:93:ED Certificate expires: 23-Nov-2023 Server statistics since restart Total accepted connections: 6 Total connections upgraded to TLS: 2 Current connections: 3 Current connections using TLS: 2 Authorization failures: 0 ndb_mgm>有关更多信息,请参见 第 25.6.19.5 节,“NDB 集群的 TLS 链接加密”。For more information, see Section 25.6.19.5, “TLS Link Encryption for NDB Cluster”.
其他命令。 在 ndb_mgm 客户端中还提供了许多其他命令,这些命令在其他地方有描述,如下所示:Additional commands. A number of other commands available in the ndb_mgm client are described elsewhere, as shown in the following list:
START BACKUP用于在 ndb_mgm 客户端执行在线备份;ABORT BACKUP命令用于取消已经进行中的备份。更多信息,请参见 第 25.6.8 节,“NDB 集群在线备份”。START BACKUPis used to perform an online backup in the ndb_mgm client; theABORT BACKUPcommand is used to cancel a backup already in progress. For more information, see Section 25.6.8, “Online Backup of NDB Cluster”.CLUSTERLOG命令用于执行各种日志功能。有关更多信息和示例,请参见 第 25.6.3 节,“NDB 集群生成的事件报告”。NODELOG DEBUG用于激活或停用节点日志中的调试输出,如本节前面所述。TheCLUSTERLOGcommand is used to perform various logging functions. See Section 25.6.3, “Event Reports Generated in NDB Cluster”, for more information and examples.NODELOG DEBUGactivates or deactivates debug printouts in node logs, as described previously in this section.对于测试和诊断工作,客户端支持一个
DUMP命令,可用于在集群上执行内部命令。除非 MySQL 支持指示,否则绝不应在生产环境中使用它。有关更多信息,请参见 NDB 集群管理客户端 DUMP 命令。For testing and diagnostics work, the client supports aDUMPcommand which can be used to execute internal commands on the cluster. It should never be used in a production setting unless directed to do so by MySQL Support. For more information, see NDB Cluster Management Client DUMP Commands.