es集群笔记

ぐ巨炮叔叔 提交于 2020-08-10 07:25:12
es 集群的默认配置是当集群中的某个节点磁盘达到使用率为 85% 的时候, 就不会在该节点进行创建副本, 当磁盘使用率达到 90% 的时候, 尝试将该节点的副本重分配到其他节点. 当磁盘使用率达到 95% 的时候, 当前节点的所有索引将被设置为只读索引.
 
检查ES集群状态:
curl -XGET localhost:9200/_cluster/health?pretty
curl -u root:changeme -XGET http://ip:9200/_cluster/health?pretty
 
查看索引状态,比如有没有red情况
curl -XGET localhost:9200/_cat/indices?v
 
查看分片的状态
[root @node1 bin]# curl -s -XGET localhost:9200/_cat/shards?v
 
节点是否正常运行
curl -XGET http://127.0.0.1:9200/_cat/nodes?v
 
health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
 
index:索引名
status:是否启用
rep:副本数
storesize:总大小(包含副本)
pristoresize:不包含副本的大小
 
返回的结果从左到右依次包括:pri(主分片数)、rep(副分片数)、docs.count(索引现有文档数)、docs.deleted(索引删除文档数)、store.size(索引总大小)、pri.store.size(索引主分片大小)。
 
也可以单独查询某一个索引下信息,如:想要查询索引test的相关信息:
 
GET _cat/indices/test?v
 
则此时响应结果只包含test的索引信息。
 
统计索引pristoresize
curl http://localhost:9200/_cat/indices?v |grep open > /tmp/es.index.collect
awk '{print $NF}' /tmp/es.index.collect > /tmp/es.index.collect.2
awk '{a+=/tb/?$0*1024:(/mb/?$0/1024:(/kb/?$0/(1024^2):$0))}END{print "total_index_size",a"G"}' /tmp/es.index.collect.2
 
取几条日志出来
curl -u root:changeme -XGET ip:9200/xx-xx-xx-xx@2020-06-12/_search?pretty -d'{"size":10}'
 
ES出现unassigned_shards
1)查看健康状态信息
curl -XGET http://localhost:9200/_cluster/health\?pretty
2)找到未分片的索引
curl -XGET http://localhost:9200/_cat/shards | grep UNASSIGNED
3)执行reroute 
curl -XPOST 'ip:9200/_cluster/reroute' -d '{ "commands" : [ { "allocate" : { "index" : "logstash-2018.07.20", "shard" : 3, "node" : "_0WmGRqVQ4WlQuEncqvOBw", "allow_primary" : true } }
4)实在不行就删除该索引
curl -XDELETE 'localhost:9200/xx-xx-xx-xx@2019-09-19/'
 
命令参数
1.Verbose(问号后面有个v)
打印出更详情
curl 'http://localhost:9200/_cat/master'
DfawFNOXRAauX60Q4LPIPg 10.122.64.9 10.122.64.9 1547098665000000509
curl 'http://localhost:9200/_cat/master?v'
id host ip node
DfawFNOXRAauX60Q4LPIPg 10.122.64.9 10.122.64.9 1547098665000000509
2.Help(问号后面有个help)
打印出可用字段
id | | node id
host | h | host name
ip | | ip address
node | n | node name
3.Headers(看上面字段)
每个命令都接受一个查询字符串参数h,该参数只强制显示这些列。
curl 'http://localhost:9200/_cat/master?h=id,ip'
DfawFNOXRAauX60Q4LPIPg 10.122.64.9
也可以
curl 'http://localhost:9200/_cat/master?h=i*'
DfawFNOXRAauX60Q4LPIPg 10.122.64.9
4.Numeric formats
第10列排序,可以改变time,size,byte
curl 'http://localhost:9200/_cat/indices?bytes=g' |sort -nrk10
第3列
curl 'http://localhost:9200/_cat/indices?bytes=g' |sort -nrk3
5.Response as text,json,smile,yaml,cbor
curl 'http://localhost:9200/_cat/master?format=json&pretty'
[
{
"id" : "DfawFNOXRAauX60Q4LPIPg",
"host" : "10.122.64.9",
"ip" : "10.122.64.9",
"node" : "1547098665000000509"
}
]
6.sort
字段排序
curl 'http://localhost:9200/_cat/templates?v&s=name'
curl 'http://localhost:9200/_cat/templates?v&s=name:desc'
 
allocation提供了一个快照,显示每个数据节点分配了多少碎片以及它们使用了多少磁盘空间。
GET _cat/allocation?help
GET _cat/allocation?v
curl http://localhost:9200/_cat/allocation?v
shards disk.indices disk.used disk.avail disk.total disk.percent host ip node
2258 584.1gb 602.1gb 232.8gb 834.9gb 72 10.122.64.11 10.122.64.11 1547098665000000709
2259 587.3gb 606.1gb 228.8gb 834.9gb 72 10.122.64.9 10.122.64.9 1547098665000000509
2259 585.5gb 603.5gb 231.4gb 834.9gb 72 10.122.64.10 10.122.64.10 1547098665000000609
 
文档计数指示活动文档的数量,不包括尚未由合并进程清理的已删除文档
curl 'http://localhost:9200/_cat/count?v'
epoch timestamp count
1582593605 09:20:05 23929092717
fielddata显示集群中每个数据节点上的fielddata当前使用了多少堆内存
curl 'http://10.122.64.9:9200/_cat/fielddata?v'
id host ip node field size
 
curl 'http://10.122.64.9:9200/_cat/health?v'
epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1582595442 09:50:42 gq_cluster green 3 3 6776 3388 0 0 0 0 - 100.0%
 
 
查看 _cat 所有支持参数
/_cat/count
/_cat/count/{index}
/_cat/recovery
/_cat/recovery/{index}
/_cat/health
/_cat/pending_tasks
/_cat/aliases
/_cat/aliases/{alias}
/_cat/thread_pool
/_cat/thread_pool/{thread_pools}
/_cat/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
/_cat/nodeattrs
/_cat/repositories
/_cat/snapshots/{repository}
/_cat/templates
 
查看节点 使用情况
curl -s 'localhost:9200/_cat/nodes?h=name,fm,fcm,sm,qcm,im&v'
name fm sm qcm
1547098665000000509 0b 2.5gb 1.2mb
1547098665000000709 0b 2.5gb 2.3mb
1547098665000000609 0b 2.5gb 2.1mb
fielddata.memory_size (fm), // 字段缓存占用内存
segments.memory (sm) // 每个分片包含的断 占用内存
filter_cache.memory_size (qcm) // 过滤语句缓存占用内存
curl http://10.122.64.9:9200/_cat/nodes?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
10.122.64.9 56 97 1 1.23 0.59 0.42 mdi * 1547098665000000509
10.122.64.11 58 97 1 0.34 0.32 0.40 mdi - 1547098665000000709
10.122.64.10 59 96 0 0.13 0.23 0.30 mdi - 1547098665000000609
 
查看集群
curl localhost:5100/search/clusters | python -m json.tool
查看集群名
curl localhost:5100/search/clusters | python -m json.tool | grep cluster_name
查看剩余容量
curl localhost:5100/search/machines | python -m json.tool
 
 
 
 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!