Skip to content

Manage Clusters

chengshiwen edited this page Sep 9, 2024 · 9 revisions

管理集群

CN doc EN doc LICENSE Releases GitHub stars Docker pulls

官方文档请参考:Manage InfluxDB Cluster clusters

InfluxDB Cluster 包括两个用于与集群交互和管理的实用工具

  • influxd-ctl 工具提供用于管理 InfluxDB Cluster 集群的命令,influxd-ctl 可用于所有 Meta 节点,更多信息请参考官方文档 influxd-ctl CLI
  • influx 工具用于与数据交互和管理数据,influx 可用于所有 Data 节点,更多信息请参考官方文档 influx CLI

以下仅介绍 influxd-ctl 集群管理实用工具:

目录:

语法

influxd-ctl [ global-options ] <command> [ arguments ]

全局选项

可选参数在括号中

[ -auth-type [ none | basic | jwt ] ]

Specify the type of authentication to use. Default value is none.

[ -bind <hostname>:<port> ]

指定要连接的 Meta 节点的绑定 HTTP 地址,默认值为 localhost:8091

[ -bind-tls ]

使用 TLS。如果您启用了 HTTPS,则必须使用此参数才能连接到 Meta 节点。

[ -k ]

跳过证书验证;将此参数与自签名证书一起使用。如果未指定 -bind-tls,则忽略 -k

[ -pwd <password> ]

Specify the user’s password. This argument is ignored if -auth-type basic isn’t specified.

[ -secret <JWT-shared-secret> ]

Specify the JSON Web Token (JWT) shared secret. This argument is ignored if -auth-type jwt isn’t specified.

[ -user <username> ]

Specify the user’s username. This argument is ignored if -auth-type basic | jwt isn’t specified.

示例

以下示例使用 influxd-ctl 工具的 show 命令:

绑定到远程 Meta 节点

The influxd-ctl utility binds to the meta node with the hostname meta-node-02 at port 8091. By default, the tool binds to the meta node with the hostname localhost at port 8091.

influxd-ctl -bind meta-node-02:8091 show

Authenticate with JWT

The influxd-ctl utility uses JWT authentication with the shared secret oatclusters.

influxd-ctl -auth-type jwt -secret oatclusters show

Authenticate with basic authentication

To authenticate a user with basic authentication, use the -auth-type basic option on the influxd-ctl utility, with the -user and -password options.

In the following example, the influxd-ctl utility uses basic authentication for a cluster user.

influxd-ctl -auth-type basic -user admini -pwd mouse show

命令

add-data

将 Data 节点添加到集群。默认情况下,influxd-ctl 将指定的 Data 节点添加到本地 Meta 节点的集群中。在执行 InfluxDB Cluster 集群的生产环境安装时,使用 add-data 命令。

语法

influxd-ctl add-data <data-node-TCP-bind-address>

示例

使用本地 Meta 节点将 Data 节点添加到集群

在以下示例中,add-data 命令连接在 localhost:8091 上运行的本地 Meta 节点,并将 Data 节点添加到该 Meta 节点的集群。Data 节点具有主机名 cluster-data-node 并在端口 8088 上运行。

$ influxd-ctl add-data cluster-data-node:8088

Added data node 3 at cluster-data-node:8088
使用远程 Meta 节点将 Data节点添加到集群

在以下示例中,该命令连接在 cluster-meta-node-01:8091 上运行的 Meta 节点,并将 Data 节点添加到该 Meta 节点的集群。Data 节点具有主机名 cluster-data-node 并在端口 8088 上运行。

$ influxd-ctl -bind cluster-meta-node-01:8091 add-data cluster-data-node:8088

Added data node 3 at cluster-data-node:8088

add-meta

将 Meta 节点添加到集群。默认情况下,influxd-ctl 将指定的 Meta 节点添加到本地 Meta 节点的集群中。执行 InfluxDB Cluster 集群的生产环境安装时,使用 add-meta 命令。

语法

influxd-ctl add-meta <meta-node-HTTP-bind-address>

示例

使用本地 Meta 节点将 Meta 节点添加到集群

在以下示例中,add-meta 命令连接在 localhost:8091 上运行的本地 Meta 节点,并将 Meta 节点添加到该本地 Meta 节点的集群中。添加的 Meta 节点具有主机名 cluster-meta-node-03 并在端口 8091 上运行。

$ influxd-ctl add-meta cluster-meta-node-03:8091

Added meta node 3 at cluster-meta-node:8091
使用远程 Meta 节点将 Meta 节点添加到集群

在以下示例中,add-meta 命令连接在 cluster-meta-node-01:8091 处运行的 Meta 节点,并将 Meta 节点添加到该 Meta 节点的集群。添加的 Meta 节点具有主机名 cluster-meta-node-03 并在端口 8091 上运行。

$ influxd-ctl -bind cluster-meta-node-01:8091 add-meta cluster-meta-node-03:8091

Added meta node 3 at cluster-meta-node-03:8091

copy-shard

Copies a shard from a source data node to a destination data node.

语法

influxd-ctl copy-shard <data-node-source-TCP-address> <data-node-destination-TCP-address> <shard-id>

相关资源: 重新平衡集群 / Rebalance InfluxDB Cluster clusters

示例

Copy a shard from one data node to another data node

In the following example, the copy-shard command copies the shard with the id 22 from the data node running at cluster-data-node-01:8088 to the data node running at cluster-data-node-02:8088.

$ influxd-ctl copy-shard cluster-data-node-01:8088 cluster-data-node-02:8088 22

Copied shard 22 from cluster-data-node-01:8088 to cluster-data-node-02:8088

join

Joins a meta node and/or data node to a cluster. By default, influxd-ctl joins the local meta node and/or data node into a new cluster.

语法

influxd-ctl join [-v] <meta-node-HTTP-bind-address>

参数

可选参数在括号中

[ -v ]

Print verbose information about the join.

<meta-node-HTTP-bind-address>

Address of a meta node in an existing cluster. Use this argument to add the un-joined meta node and/or data node to an existing cluster.

示例

Join a meta and data node into a cluster

In this example, the join command joins the meta node running at cluster-node-03:8091 and the data node running at cluster-node-03:8088 into a new cluster.

$ influxd-ctl join

Joining meta node at localhost:8091
Searching for meta node on cluster-node-03:8091...
Searching for data node on cluster-node-03:8088...

Successfully created cluster

  * Added meta node 1 at cluster-node-03:8091
  * Added data node 2 at cluster-node-03:8088

  To join additional nodes to this cluster, run the following command:

  influxd-ctl join cluster-node-03:8091
Join a meta and data node to an existing cluster

The command joins the meta node running at cluster-node-03:8091 and the data node running at cluster-node-03:8088 to an existing cluster. The existing cluster includes the meta node running at cluster-meta-node-02:8091.

$ influxd-ctl join cluster-meta-node-02:8091

Joining meta node at cluster-meta-node-02:8091
Searching for meta node on cluster-node-03:8091...
Searching for data node on cluster-node-03:8088...

Successfully joined cluster

  * Added meta node 3 at cluster-node-03:8091
  * Added data node 4 at cluster-node-03:8088
Join a meta node to an existing cluster

The command joins the meta node running at cluster-meta-node-03:8091 to an existing cluster. The existing cluster includes the meta node running at cluster-meta-node-02:8091. The system doesn’t join a data node to the cluster because it doesn’t find a data node at cluster-meta-node-03:8088.

$ influxd-ctl join cluster-meta-node-02:8091

Joining meta node at cluster-meta-node-02:8091
Searching for meta node on cluster-meta-node-03:8091...
Searching for data node on cluster-meta-node-03:8088...

Successfully joined cluster

  * Added meta node 18 at cluster-meta-node-03:8091
  * No data node added.  Run with -v to see more information
Join a meta node to an existing cluster and show detailed information about the join

The command joins the meta node running at cluster-meta-node-03:8091 to an existing cluster. The existing cluster includes the meta node running at cluster-meta-node-02:8091. The -v argument prints detailed information about the join.

$ influxd-ctl join -v meta-node-02:8091

Joining meta node at meta-node-02:8091
Searching for meta node on meta-node-03:8091...
Searching for data node on data-node-03:8088...

No data node found on data-node-03:8091!

  If a data node is running on this host,
  you may need to add it manually using the following command:

  influxd-ctl -bind meta-node-02:8091 add-data <dataAddr:port>

  Common problems:

    * The influxd process is using a non-standard port (default 8088).
    * The influxd process is not running.  Check the logs for startup errors.

Successfully joined cluster

  * Added meta node 18 at meta-node-03:8091
  * No data node added.  Run with -v to see more information

leave

Removes a meta node and/or data node from the cluster.

The leave argument is destructive; it erases all metastore information from meta nodes and all data from data nodes. Use leave only if you want to permanently remove a node from a cluster.

语法

influxd-ctl leave [-y]

参数

可选参数在括号中

[ -y ]

Assume yes (y) to all prompts.

示例

Remove a meta and data node from a cluster

In this example, the leave command removes the meta node running at cluster-node-03:8091 and the data node running at cluster-node-03:8088 from an existing cluster. Here, we respond yes (y) to the two prompts that ask if we’d like to remove the data node and if we’d like to remove the meta node from the cluster.

$ influxd-ctl leave

Searching for data node on cluster-node-03:8088...
Remove data node cluster-node-03:8088 from the cluster [y/N]: y
Removed cluster-node-03:8088 from the cluster
Searching for meta node on cluster-node-03:8091...
Remove meta node cluster-node-03:8091 from the cluster [y/N]: y

Successfully left cluster

  * Removed data node cluster-node-03:8088 from cluster
  * Removed meta node cluster-node-03:8091 from cluster
Remove a meta and data node from a cluster and assume yes to all prompts

In this example, the leave command removes the meta node running at cluster-node-03:8091 and the data node running at cluster-node-03:8088 from an existing cluster. Because we specify the -y flag, the system assumes that we’d like to remove both the data node and meta node from the cluster and does not prompt us for responses.

$ influxd-ctl leave -y

Searching for data node on cluster-node-03:8088...
Removed cluster-node-03:8088 from the cluster
Searching for meta node on cluster-node-03:8091...

Successfully left cluster

  * Removed data node cluster-node-03:8088 from cluster
  * Removed meta node cluster-node-03:8091 from cluster
Remove a meta node from a cluster

In this example, the leave command removes the meta node running at cluster-meta-node-03:8091 from an existing cluster. The system doesn’t remove a data node from the cluster because it doesn’t find a data node running at cluster-meta-node-03:8088.

$ influxd-ctl leave

Searching for data node on cluster-meta-node-03:8088...
  * No data node found.
Searching for meta node on cluster-meta-node-03:8091...
Remove meta node cluster-meta-node-03:8091 from the cluster [y/N]: y

Successfully left cluster

  * No data node removed from cluster
  * Removed meta node cluster-meta-node-03:8091 from cluster

remove-data

从集群中删除 Data 节点。如果您在生产环境安装过程设置 InfluxDB Cluster 集群,请使用 remove-data 命令。

remove-data 参数是破坏性的;它擦除指定 Data 节点中的所有数据。仅当您想从集群中永久删除 Data 节点时才使用 remove-data

语法

influxd-ctl remove-data [ -force ] <data-node-TCP-bind-address>

参数

可选参数在括号中

[ -force ]

强制删除 Data 节点。如果 Data 节点进程未运行,请使用 -force

示例

从集群中删除 Data 节点

在此示例中,remove-data 命令从现有集群中删除在 cluster-data-node-03:8088 运行的 Data 节点。

$ influxd-ctl remove-data cluster-data-node-03:8088
Removed data node at cluster-data-node-03:8088

remove-meta

从集群中删除 Meta 节点。如果您在生产安装过程设置 InfluxDB Cluster 集群,请使用 remove-meta 命令。

remove-meta 参数是破坏性的;它从指定的 Meta 节点中删除所有元存储信息。仅当您想从集群中永久删除 Meta 节点时才使用 remove-meta

语法

influxd-ctl remove-meta [ -force | -tcpAddr <meta-node-TCP-bind_address> | -y ] <meta-node-HTTP-bind-address>

参数

可选参数在括号中

[ -force ]

强制删除 Meta 节点。如果 Meta 节点进程未运行,且节点不可访问且不可恢复,则使用 -force。如果 Meta 节点在被 -force 删除后重新启动,它可能会干扰集群。此参数需要 -tcpAddr 参数。

[ -tcpAddr <meta-node-TCP-bind_address> ]

要从集群中删除的 Meta 节点的 TCP 地址。将此参数与 -force 参数一起使用。

[ -y ]

对所有提示假定 Yes

示例

从集群中删除 Meta 节点

在此示例中,remove-meta 命令从现有集群中删除 cluster-meta-node-02:8091 处的 Meta 节点。在示例中,我们对询问是否要从集群中删除 Meta 节点的提示响应是 (y)。

$ influxd-ctl remove-meta cluster-meta-node-02:8091

Remove cluster-meta-node-02:8091 from the cluster [y/N]: y

Removed meta node at cluster-meta-node-02:8091
从集群中强制删除无响应的 Meta 节点

在此示例中,remove-data 命令从集群中强制删除运行在 TCP 地址 cluster-meta-node-02:8089 和 HTTP 地址 cluster-meta-node-02:8091 的 Meta 节点。在示例中,我们对询问是否要从集群中强制删除 Meta 节点的提示响应是 (y)。请注意,如果 cluster-meta-node-02:8091 处的 Meta 节点重新启动,它可能会干扰集群。仅当节点不可访问且不可恢复时才强制删除 Meta 节点。

$ influxd-ctl remove-meta -force -tcpAddr cluster-meta-node-02:8089 cluster-meta-node-02:8091

Force remove cluster-meta-node-02:8091 from the cluster [y/N]: y

Removed meta node at cluster-meta-node-02:8091

remove-shard

Removes a shard from a data node. Removing a shard is an irrecoverable, destructive action; please be cautious with this command.

语法

influxd-ctl remove-shard <data-node-source-TCP-address> <shard-id>

相关资源: 重新平衡集群 / Rebalance InfluxDB Cluster clusters

示例

Remove a shard from a running data node

In this example, the remove-shard command removes shard 31 from the data node running at cluster-data-node-02:8088.

$ influxd-ctl remove-shard cluster-data-node-02:8088 31

Removed shard 31 from cluster-data-node-02:8088

show

显示属于集群的所有 Meta 节点和 Data 节点。

语法

influxd-ctl show

示例

显示集群中的所有元和 Data 节点

在此示例中,show 命令输出显示集群包括三个 Meta 节点和两个 Data 节点。

$ influxd-ctl show

Data Nodes
==========
ID  TCP Address         Version
4   192.168.0.100:8188  1.8.10-c1.1.2
5   192.168.0.100:8288  1.8.10-c1.1.2

Meta Nodes
==========
ID  TCP Address         Version
1   192.168.0.100:8191  1.8.10-c1.1.2
2   192.168.0.100:8291  1.8.10-c1.1.2
3   192.168.0.100:8391  1.8.10-c1.1.2

show-shards

Outputs details about existing shards of the cluster, including shard ID, database, retention policy, desired replicas, shard group, starting timestamp, ending timestamp, expiration timestamp, and data node owners.

语法

influxd-ctl show-shards

示例

Show the existing shards in a cluster

In this example, the show-shards output shows that there are two shards in the cluster. The first shard has an id of 51 and it’s in the telegraf database and the autogen retention policy. The desired number of copies for shard 51 is 2 and it belongs to shard group 37. The data in shard 51 cover the time range between 2017-03-13T00:00:00Z and 2017-03-20T00:00:00Z, and the shard has no expiry time; telegraf’s autogen retention policy has an infinite duration so the system never removes shard 51. Finally, shard 51 appears on two data nodes: cluster-data-node-01:8088 and cluster-data-node-03:8088.

$ influxd-ctl show-shards

Shards
==========
ID  Database             Retention Policy  Desired Replicas  Shard Group  Start                 End                              Expires               Owners
51  telegraf             autogen           2                 37           2017-03-13T00:00:00Z  2017-03-20T00:00:00Z                                   [{26 cluster-data-node-01:8088} {33 cluster-data-node-03:8088}]
52  telegraf             autogen           2                 37           2017-03-13T00:00:00Z  2017-03-20T00:00:00Z                                   [{5 cluster-data-node-02:8088} {26 cluster-data-node-01:8088}]
Use the verbose flag to view more shard owner detail

Use the verbose flag to show more detail about each shard owner, including the state (hot/cold), last modified date and time, and size on disk.

$ influxd-ctl  show-shards -v

Shards
==========
ID  Database             Retention Policy  Desired Replicas  Shard Group  Start                 End                              Expires                Owners
1   telegraf             autogen           2                 1            2020-04-27T00:00:00Z  2020-05-04T00:00:00Z                                   [{4 localhost:8188 hot 2020-04-28 13:59:50.022558549 -0400 EDT 1784222 <nil>} {5 localhost:8288 hot 2020-04-28 13:59:50.02605612 -0400 EDT 1785568 <nil>}]
2   stress               autogen           2                 2            2020-04-27T00:00:00Z  2020-05-04T00:00:00Z                                   [{4 localhost:8188 hot 2020-04-28 13:50:57.076073713 -0400 EDT 102637693 <nil>} {5 localhost:8288 hot 2020-04-28 13:50:57.136074013 -0400 EDT 102915477 <nil>}]
3   _internal            monitor           1                 3            2020-04-28T00:00:00Z  2020-04-29T00:00:00Z             2020-05-06T00:00:00Z  [{5 localhost:8288 hot 2020-04-28 13:59:50.017341511 -0400 EDT 627431 <nil>}]
4   _internal            monitor           1                 3            2020-04-28T00:00:00Z  2020-04-29T00:00:00Z             2020-05-06T00:00:00Z  [{4 localhost:8188 hot 2020-04-28 13:59:50.01737255 -0400 EDT 1014827 <nil>}]

update-data

更新元存储中 Data 节点的地址。

语法

influxd-ctl update-data <data-node-old-TCP-bind-address> <data-node-new-TCP-bind-address>

示例

更新 Data 节点主机名

在此示例中,update-data 命令将 Data 节点 26 的地址从 cluster-node-01:8088 更新为 cluster-data-node-01:8088

$ influxd-ctl update-data cluster-node-01:8088 cluster-data-node-01:8088

updated data node 26 to cluster-data-node-01:8088

token

Generates a signed JSON Web Token (JWT) token. The token argument only works when using JWT authentication in the cluster and when using the -auth-type jwt and -secret <shared-secret> arguments.

语法

influxd-ctl token [-exp <duration>]

参数

可选参数在括号中

[ -exp <duration> ]

Determines the time after which the token expires. By default, the token expires after one minute.

示例

Create a signed JWT token

In this example, the token command returns a signed JWT token.

$ influxd-ctl -auth-type jwt -secret oatclusters token

hereistokenisitgoodandsoareyoufriend.timingisaficklefriendbutwherewouldwebewithoutit.timingthentimeseriesgood-wevemadetheleap-nowletsgetdownanddataandqueryallourheartsout
Attempt to create a signed JWT token with basic authentication

In this example, the token command returns an error because the command doesn’t use JWT authentication.

$ influxd-ctl -auth-type basic -user admini -pwd mouse token

token: tokens can only be created when using bearer authentication

truncate-shards

Truncates hot shards, that is, shards that cover the time range that includes the current time (now()). The truncate-shards command creates a new shard and the system writes all new points to that shard.

语法

influxd-ctl truncate-shards [-delay <duration>]

参数

可选参数在括号中

[ -delay <duration> ]

Determines when to truncate shards after now(). By default, the tool sets the delay to one minute. The duration is an integer followed by a duration unit.

相关资源: 重新平衡集群 / Rebalance InfluxDB Cluster clusters

示例

Truncate shards with the default delay time

In this example, after running the truncate-shards command and waiting one minute, the output of the show-shards command shows that the system truncated shard 51 (truncated shards have an asterisk (*) on the timestamp in the End column) and created the new shard with the id 54.

$ influxd-ctl truncate-shards

Truncated shards.

$ influxd-ctl show-shards

Shards
==========
ID  Database             Retention Policy  Desired Replicas  Shard Group  Start                 End                              Expires               Owners
51  telegraf             autogen           2                 37           2017-03-13T00:00:00Z  2017-03-13T20:40:15.753443255Z*                        [{26 cluster-data-node-01:8088} {33 cluster-data-node-03:8088}]
54  telegraf             autogen           2                 38           2017-03-13T00:00:00Z  2017-03-20T00:00:00Z                                   [{26 cluster-data-node-01:8088} {33 cluster-data-node-03:8088}]
Truncate shards with a user-provided delay timestamp

In this example, after running the truncate-shards command and waiting three minutes, the output of the show-shards command shows that the system truncated shard 54 (truncated shards have an asterix (*) on the timestamp in the End column) and created the new shard with the id 58.

$ influxd-ctl truncate-shards -delay 3m

Truncated shards.

$ influxd-ctl show-shards

Shards
==========
ID  Database             Retention Policy  Desired Replicas  Shard Group  Start                 End                              Expires               Owners
54  telegraf             autogen           2                 38           2017-03-13T00:00:00Z  2017-03-13T20:59:14.665827038Z*                        [{26 cluster-data-node-01:8088} {33 cluster-data-node-03:8088}]
58  telegraf             autogen           2                 40           2017-03-13T00:00:00Z  2017-03-20T00:00:00Z                                   [{26 cluster-data-node-01:8088} {33 cluster-data-node-03:8088}]
Clone this wiki locally