在日常运维ELK的过程中,总结了一些常用的api ,方便工作中查看。

一、cat APIS
1.查看分配在每个数据节点的shard数量,和节点的磁盘空间
curl "10.0.0.100:9200/_cat/allocation?v"
2.查看单个索引和集群中所有索引的文档数
curl "10.0.0.100:9200/_cat/count"
curl "10.0.0.100:9200/_cat/count/index-name"
3.查看集群的健康状态
curl "10.0.0.100:9200/_cat/health"
while true; do curl localhost:9200/_cat/health; sleep 120; done
4.查看集群索引的详细信息
curl "10.0.0.100:9200/_cat/indices"
5.查看集群master节点的id,绑定的ip和主机名
curl "10.0.0.100:9200/_cat/master"
6.查看node节点的自定义属性
curl "10.0.0.100:9200/_cat/nodeattrs"
7.查看集群的node信息
curl "10.0.0.100:9200/_cat/nodes"
8.查看集群中一直没有执行的任务
curl "10.0.0.100:9200/_cat/pending_tasks"
9.查看正在运行和完成的分片恢复
curl "10.0.0.100:9200/_cat/recovery"
10.查看集群的快照仓库
curl "10.0.0.100:9200/_cat/repositories"
11.查看集群中每个node节点的线程池数据
curl "10.0.0.100:9200/_cat/thread_pool"
12.查看node包含哪些shards,是主分片还是副本分片,文档的数量和占用的磁盘大小,以及node节点的位置
curl "10.0.0.100:9200/_cat/shards"
curl "10.0.0.100:9200/_cat/shards/"
13.查看集群索引模板信息,你能使用索引模板去设置索引settings和mappings ,应用到新创建的索引上
curl "10.0.0.100:9200/_cat/templates"
curl "10.0.0.100:9200/_cat/templates/"

二、cluster APIs
1.查看集群中shard的分配
curl "10.0.0.100:9200/_cluster/allocation/explain"
2.查看集群的settings信息
curl "10.0.0.100:9200/_cluster/settings"
3.查看集群的健康状态
curl "10.0.0.100:9200/_cluster/health/"
4.改变集群的shards的分配
curl -XPOST "10.0.0.100:9200/_cluster/reroute"
5.查看集群的统计数据
curl "10.0.0.100:9200/_cluster/stats"
6.更新集群的设置信息
curl -XPUT "10.0.0.100:9200/_cluster/settings"
7.查看集群中每个node节点的hot threads
curl "10.0.0.100:9200/_nodes/hot_threads"r"
8.查看集群的node信息
curl "10.0.0.100:9200/_nodes"
9.查看集群node的统计信息
curl "10.0.0.100:9200/_nodes/stats"
10.查看集群中一直没有执行的任务
curl "10.0.0.100:9200/_cluster/pending_task"

三、index API

四、curl
curl -s http://es-host:9200/_cat/indices > indices.txt
curl -s http://es-host:9200/_cat/shards > shards.txt

五、ES集群性能优化及维护
1.ES集群设置删除性操作不允许使用_all及通配符设置
curl -XPUT 10.0.0.100:9200 /_cluster/settings
{
"persistent": {
"action.destructive_requires_name": true
}
}

2.ES集群总分片数不足,每台机器最大分片数设置
ES7.0.0版本以上,默认只允许1000个分片。
查询ES集群节点分片数: _cat/allocation?v
1)配置文件 elasticsearch.yml
增加配置项: cluster.max_shards_per_node: 2000
2)动态修改该配置项:
_cluster/settings GET、PUT请求
{
"transient": {
"cluster": {
"max_shards_per_node":2000
}
}
}
恢复之前默认:
_cluster/settings GET、PUT请求
{
"transient": {
"cluster": {
"max_shards_per_node":null
}
}
}
3..ES节点禁用分片转移-临时重启操作
PUT _cluster/settings
{
"transient": {
"cluster.routing.allocation.enable": "none"
}
}
恢复分片转移:
PUT _cluster/settings
{
"transient": {
"cluster.routing.allocation.enable": "all"
}
}
4.当es磁盘使用率过高,是es默认会改为只读模式,清理完数据需要恢复写入状态
curl ${ES_URL}/_settings -X PUT -H "Content-Type:application/json" -H "Accept:application/json" -d '{
"index": {
"blocks": {
"read_only_allow_delete": "false"
}
}
}'