目录
查看ES集群的健康状况
查看ES的设置
动态设置参数
查看ES在线的节点
查看ES的主节点
查看所有索引
查看具体某个索引
查看yellow的索引
查看red的索引
查看yellow索引的恢复情况
关闭所有yellow索引
查询索引的分片情况
查询指定索引的分片情况
查看不能分配的分片
查看所有分片的恢复情况
查看某个具体索引的分片恢复情况
查看segments内存占用情况
查看线程池
查看ES集群线程池状态
查看segment数量
查看节点情况
打开指定索引
关闭指定索引
设置total_shards_per_node
设置集群recovery数量
将副本数设置为0
将索引的shard里的多个段合并成1个段,段越少,占用的资源越少,有利于提高查询速度
使用_cat/nodes?v查看节点信息,区分哪个是当前的master,然后使用_cat/master对比. 带*的是master
以组名或姓名为前缀,创建 "前缀-1"索引,"前缀-2"索引,不加任何设置。
以组名或姓名为前缀,创建 "前缀-3"索引,3个分片,每个分片0个副本
向"前缀-2"的索引中添加一个doc,内容为{“name”:“任意”,“something”:“任意”}
查看指定索引的mapping和setting
删除"前缀-1"索引, 关闭"前缀-2"索引, 打开"前缀-2"索引
"前缀-3"动态修改副本数量为1
修改"前缀-3"索引的total_shards_per_node参数为1,查看索引setting,以及状态
curl localhost:9200/_cluster/health?pretty
{
"cluster_name" : "es",
"status" : "yellow", 当前集群状态
"timed_out" : false,
"number_of_nodes" : 3, 当前集群在线的节点个数为3
"number_of_data_nodes" : 3, 在线的数据节点数
"active_primary_shards" : 16055, 活跃的主分片数量
"active_shards" : 32107, 活跃的分片数量,包括主分片和副本。
"relocating_shards" : 0, 正在移动的分片数量
"initializing_shards" : 0, 正初初始化的分片个数为:0
"unassigned_shards" : 3, 未分配的分片个数为:3
"delayed_unassigned_shards" : 0, 由于节点离线导致延迟分配的分片数量
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 99.99065711616318 所有活跃分片/打开的所有索引的分片总数
}
curl localhost:9200/_cluster/settings?pretty
{
"persistent" : {
// 永久设置,重启仍然有效
"action" : {
"auto_create_index" : ".security,.monitoring-*,.watch*,.triggered_watches,.quota,noah*,basp*",
"destructive_requires_name" : "false"
}
},
"transient" : {
} // 临时设置,重启失效
}
临时生效:transient修改方法为:curl -XPUT 'http://localhost:9200/_cluster/settings?pretty' -d '{"transient":{"dynamic.parma":"value"}}'
永久生效:persistent修改方法为:curl -XPUT 'http://localhost:9200/_cluster/settings?pretty' -d '{"persistent":{"dynamic.parma":"value"}}'
curl localhost:9200/_cat/nodes?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
10.xx.xxx.xxx 97 99 22 18.64 11.75 9.88 mdi * es.wjl.cn.0
10.xx.xxx.xxx 94 98 37 7.25 7.59 7.74 mdi - es.ejl.cn.0
10.xx.xxx.xxx 93 88 14 8.13 9.16 9.17 mdi - es.wjl.cn.0
存在节点缺失的情况可用该命令查看缺失节点为哪些
curl localhost:9200/_cat/master
curl localhost:9200/_cat/master?v // 加上 ?v 将显示字段名.
es.www.cn.0 temp1002.qqq.cn 10.xx.xxx.xxx es.wjl.cn.0
curl localhost:9200/_cat/indices
curl localhost:9200/_cat/indices?v // 加上 ?v 将显示字段名.
yellow open index06 QCVD7Cudbc3cqNlG0g 5 1 1 0 5.1kb 5.1kb
green open index200 UXEe4IEOos8BMccZXw 3 0 4 0 16kb 16kb
yellow open index01 ewNasSrnSjiqnQPWAA 3 1 1 0 5.4kb 5.4kb
curl localhost:9200/_cat/indices/{
index}
curl localhost:9200/_cat/indices/{
index}?v // 加上 ?v 将显示字段名.
curl -sXGET localhost:9200/_cat/indices/wjl*?v // 查询前缀是wjl的所有索引
curl -sXGET "http://localhost:9200/_cat/indices?v" | grep -v close | grep yellow
curl -sXGET "http://localhost:9200/_cat/indices?v" | grep -v close | grep red
curl -sXGET "http://localhost:9200/_cat/recovery?v" | grep -v done
curl -sXGET "http://localhost:9200/_cat/indices" | grep -v close | grep "yellow " | awk '{print $3}' | while read line; do curl -XPOST "http://localhost:9200/$line/_close" ;done
curl localhost:9200/_cat/shards?v
index_name 2 p STARTED 0 159b 10.95.134.147 es.wjl.cn.0
index_name 2 r STARTED 0 159b 10.95.134.149 es.wjl.cn.0
index_name 3 r STARTED 1 16.4kb 10.95.134.145 es.wjl.cn.0
curl localhost:9200/_cat/shards/{
index}?v
curl -sXGET "http://localhost:9200/_cat/shards?v" | grep UNASSIGNED
curl localhost:9200/_cat/recovery
index06 0 68ms existing_store done n/a n/a 172.16.144.80 node-1 n/a n/a 0 0 100.0% 1 0 0 100.0% 261 0 0 100.0%
index06 1 59ms existing_store done n/a n/a 172.16.144.80 node-1 n/a n/a 0 0 100.0% 1 0 0 100.0% 261 0 0 100.0%
index06 2 72ms existing_store done n/a n/a 172.16.144.80 node-1 n/a n/a 0 0 100.0% 1 0 0 100.0% 261 0 0 100.0%
curl localhost:9200/_cat/recovery/{
index}
可使用该命令查看initializing分片的恢复进度
curl -sXGET "http://localhost:9200/_cat/nodes?h=name,segments.memory,heap.max&v"
name(es节点名) segments.memory heap.max
es.***.0 5.4gb 29.9gb
es.***.1 5.2gb 29.9gb
关注:segments.memory的使用是否超过堆内存的30%
curl -sXGET "http://localhost:9200/_cat/thread_pool?v"
node_name name active queue rejected
es.wjl.cn.0 index 0 0 0
es.wjl.cn.0 listener 0 0 0
curl -sXGET "http://localhost:9200/_cat/thread_pool/bulk?v"
node_name name active queue rejected
es.***.1 bulk 2 0 1749
es.***.0 bulk 0 0 1197
es.***.0 bulk 0 0 209
如果集群存在入库有延迟的情况,执行thread_poolAPI,如果reject>0,说明集群的处理能力低于入库请求,请求业务方降低入库速率。
curl -sXGET "http://localhost:9200/_cat/thread_pool/search?v"
node_name name active queue rejected
es.***.0 search 4 0 0
es.***.0 search 61 977 4326
es.***.1 search 61 495 3497
如果reject>0,说明集群的处理能力低于查询请求,需要降低查询速率。
curl -sXGET "http://localhost:9200/_cat/indices?h=index,segments.count&v"
index segments.count
seye-file-2019.08.20 0
seye-udpflow-2019.08.16 0
seye-file-2019.08.18 0
curl -sXGET "http://localhost:9200/_cat/nodes?h=name,uptime,segments.memory&v"
name(ES节点名) uptime(节点启动时长) segments.memory(segment占用内存)
es.wjl.cn.0 66.7d 93.8mb
es.wjl.cn.0 66.7d 82.3mb
es.wjl.cn.0 61.8d 112.1mb
curl -XPOST "http://localhost:9200/{index}/_open"
curl -XPOST "http://localhost:9200/{index}/_close"
curl -XPUT "http://localhost:9200/{index}/_settings" -d '{"index":{"routing.allocation.total_shards_per_node":"1"}}'
curl -sXPUT "http://localhost:9200/_cluster/settings" -d '{"transient":{"cluster.routing.allocation.node_concurrent_recoveries":"60"}}'
curl -sXPUT "http://localhost:9200/{index}/_settings" -H 'Content-Type: application/json' -d '{"index.number_of_replicas":0}'
curl -XPOST 'http://localhost:9200/netops-syslog2018.07.19/_forcemerge?max_num_segments=1'
_cat/nodes?v
查看节点信息,区分哪个是当前的master,然后使用_cat/master对比. 带*的是master
curl -sXGET localhost:9200/_cat/nodes?v
curl -sXGET localhost:9200/_cat/master?v
curl -sXPUT localhost:9200/wjl-1
curl -sXPUT localhost:9200/wjl-2?pretty // ?pretty: 美化输出.
[esuser@king bin]$ curl -sXPUT localhost:9200/wjl-2?pretty
{
"acknowledged" : true,
"shards_acknowledged" : true,
"index" : "wjl-2"
}
curl -sXPUT "localhost:9200/wjl-3?pretty" -H 'Context-Type: application/json' -d'
{
"settings" :{
"number_of_shards" :3,
"number_of_replicas" :0
}
}'
curl -XPOST "http://localhost:9200/fengxiaoqing-2/content" -d '{
"name":"wjl",
"something":"This is a doc from wjl-2,叫做something"
}'
curl -sXGET 'localhost:9200/{index}?pretty'
curl -sXDELETE localhost:9200/wjl-1
curl -sXPOST localhost:9200/wjl-2/_close
curl -sXPOST localhost:9200/wjl-2/_open
curl -sXPUT localhost:29200/wjl-3/_settings -d '{"index.number_of_replicas":1}'
total_shards_per_node
参数为1,查看索引setting,以及状态curl -sXPUT "http://localhost:9200/wjl-3/_settings" -d '{"index.routing.allocation.total_shards_per_node":1}'
total_shards_per_node是索引级别的setting.
curl -sXGET http://localhost:9200/_cat/allocation
curl -sXGET http://localhost:9200/_cat/plugins
curl -sXGET http://localhost:9200/_cat/nodes
curl -sXGET http://localhost:9200/_cat/indices_simple
curl -sXGET http://localhost:9200/_cat/indices_simple/{
index}
curl -sXGET http://localhost:9200/_cat/fielddata
curl -sXGET http://localhost:9200/_cat/fielddata/{
fields}
curl -sXGET http://localhost:9200/_cat/count
curl -sXGET http://localhost:9200/_cat/count/{
index}
curl -sXGET http://localhost:9200/_cat/recovery
curl -sXGET http://localhost:9200/_cat/recovery/{
index}
curl -sXGET http://localhost:9200/_cat/repositories
curl -sXGET http://localhost:9200/_cat/thread_pool
curl -sXGET http://localhost:9200/_cat/thread_pool/{
thread_pools}/_cat/master
curl -sXGET http://localhost:9200/_cat/health
curl -sXGET http://localhost:9200/_cat/indices
curl -sXGET http://localhost:9200/_cat/indices/{
index}
curl -sXGET http://localhost:9200/_cat/indices_ext
curl -sXGET http://localhost:9200/_cat/indices_ext/{
index}
curl -sXGET http://localhost:9200/_cat/nodeattrs
curl -sXGET http://localhost:9200/_cat/tasks
curl -sXGET http://localhost:9200/_cat/segments
curl -sXGET http://localhost:9200/_cat/segments/{
index}
curl -sXGET http://localhost:9200/_cat/pending_tasks
curl -sXGET http://localhost:9200/_cat/shards
curl -sXGET http://localhost:9200/_cat/shards/{
index}
curl -sXGET http://localhost:9200/_cat/snapshots/{
repository}
curl -sXGET http://localhost:9200/_cat/aliases
curl -sXGET http://localhost:9200/_cat/aliases/{
alias}
每个命令后边跟"?help"参数,可以显示列头的含义。重点关注nodes, count, recovery, health, indices, pending_tasks, shards, alias, 需要掌握这几个api具体能查到什么信息。在定位集群问题时,会经常使用。