Elastic:使用 escli 命令行工具来管理 Elastic 集群

escli 是一个 npm 的开源工具。它可以用来管理 Elastic 集群。目前这个包还在开发之中。现有的一些功能如下:

  • enable/;disable shard allocation
  • several simple list of ES objects
  • reallocate all shard from one node in the objective of kill it gracefully
  • open/close indexes

这个安装包的一些信息可以在地址 https://www.npmjs.com/package/escli 找到。它的源码位于 https://github.com/CleverCloud/escli

 

安装

这是一个 nodejs 的安装包。你在安装之前需要安装 nodejs。在这里就不赘述了。我们可以通过如下的命令来安装这个包:

npm install escli --global

一旦安装完毕,我们可以使用如下的命令来运行:

$ escli
Usage: escli
Simple elastic search management command line. Configure with Env variable, using ES_CLI_HOST and optionaly ES_CLI_USER and ES_CLI_PASSWORD

Options:
[--help, -?]          Display help about this program (default: false)
[--version, -V]       Display the version of this program (default: false)

Available Commands:
help                  display help about this program
shard_allocation      shards allocation management
list                  view list of various ES management data
nodes                 nodes operations
index                 act on indexes of the cluster

 

使用

对于一个配置了安全的 Elasticsearch 集群来说,我们需要配置环境变量 ES_CLI_HOST,ES_CLI_USER 及 ES_CLI_PASSWORD。我们在 terminal 中打入如下的命令:

export ES_CLI_HOST=localhost:9200
export ES_CLI_USER=elastic
export ES_CLI_PASSWORD=password

在上面我们填入 Elasticsearch 的地址,用户名及密码(如果已经配置安全)。我们必须注意的是:当我们配资 ES_CLI_HOST 时,千万不要添加 http 或者 https,否则会有错误发生。

我们可以使用如下的命令来得到帮助:

$ escli --help
Usage: escli
Simple elastic search management command line. Configure with Env variable, using ES_CLI_HOST and optionaly ES_CLI_USER and ES_CLI_PASSWORD

Options:
[--help, -?]          Display help about this program (default: false)
[--version, -V]       Display the version of this program (default: false)

Available Commands:
help                  display help about this program
shard_allocation      shards allocation management
list                  view list of various ES management data
nodes                 nodes operations
index                 act on indexes of the cluster

List 命令

我们可以使用 list 命令来进行查看:

$ escli list
Usage: escli list
view list of various ES management data

Options:
[--help, -?]        Display help about this program (default: false)
[--version, -V]     Display the version of this program (default: false)

Available Commands:
shards              view list of shards
indexes             view list of indexes
nodes               view list of nodes

上面显示,我们可以显示 shards, indexex 及 nodes。我们尝试一下:

$ escli list nodes
ip          heap.percent ram.percent cpu load_1m load_5m load_15m node.role  master name
192.168.0.3           36          91   5    1.53                  cdhilmrstw *      liuxg

我们查看一下 shards:

$ escli list nodes
ip          heap.percent ram.percent cpu load_1m load_5m load_15m node.role  master name
192.168.0.3           36          91   5    1.53                  cdhilmrstw *      liuxg

$ escli list shards
index                                                                                                                        shard prirep state        docs   store ip          node
date_to_day                                                                                                                  0     p      STARTED        10   4.5kb 192.168.0.3 liuxg
date_to_day                                                                                                                  0     r      UNASSIGNED    
...

显示 indexes:

$ escli list indexes
health status index                                                                                                                        uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   .ent-search-actastic-crawler_crawl_requests_v3                                                                               _ubNl_NGRXStKT1a1UzJSw   1   0          1            0      6.2kb          6.2kb
green  open   .ent-search-esqueues-me_queue_v1_index_adder                                                                                 xbacScvKSNS_xT6vBEx6wA   1   0          0            0       208b           208b
green  open   .ent-search-api-ecs-ilm-logs-production-2021.02.18-000001                                                                    WHccbDYkTLq86YuYrFt6bg   1   0        104            0    797.9kb        797.9kb
...

Index 命令

我们运行如下的命令:

$ escli index
Usage: escli index
act on indexes of the cluster

Options:
[--help, -?]        Display help about this program (default: false)
[--version, -V]     Display the version of this program (default: false)

Available Commands:
open                open <index-name> or all if not define
close               close <index-name> or all if not define

它显示,我们可以打开及关闭一个索引。一旦一个索引被关闭,它可以节省资源,但是它将不再被访问。我们可以参考文章 “开始使用Elasticsearch (1)” 了解 _open 和 _close 是如何操作的。在上面的 list indexes 命令中,我们可以看到一个叫做 date_to_day 的索引,我们可以通过如下的命令来进行操作:

$ escli index open date_to_day
{"acknowledged":true,"shards_acknowledged":true}

nodes 命令

$ escli nodes
Usage: escli nodes
nodes operations

Options:
[--help, -?]        Display help about this program (default: false)
[--version, -V]     Display the version of this program (default: false)

Available Commands:
empty_node          reasign shards out of this node
get_unasigned       get 20 unasigned shards on this node
move_shards         move [x] shards from node1 to node2

shards_allocation 命令

$ escli shard_allocation
Usage: escli shard_allocation
shards allocation management

Options:
[--help, -?]        Display help about this program (default: false)
[--version, -V]     Display the version of this program (default: false)

Available Commands:
enable              enable auto shards allocation
disable             disable auto shards allocation

 

已标记关键词 清除标记
相关推荐