做了近半年的公司ES集群维护及开发,开始转入别的项目组,所有对曾经的这段技术使用 做个总结,主要是一些运维经验,还有常用命令!
常见问题(FAQ)
1、集群Red
首先查看集群所在机器进程是否还在(jps),如果不存在则启动所有进程,如果存在则查看日志是否存在GC事件过长导致集群不可用
2、集群存在未分配shard,手动执行命令触发分片移动
参考:https://www.jianshu.com/p/2bb42eb49515
3、集群节点cpu 使用率过高
参考:https://www.jianshu.com/p/a930fa53764d
4、微服务 sql 查询出错
首先查看插件是否安装 http://ip:port/_plugin/sql,如果看不到sql 查询界面说明么有安装插件不支持sql 查询,如果存在则直接执行sql查看执行结果
5、根据时间范围查不出数据
首先查看日志是否有报错信息,然后根据查询字段时间格式与mapping 中定义格式是否一致
ES 涉及集群问题 看日志!看日志!看日志 三遍
常用命令(请替换自定义端口)
1、查看集群健康状态
curl -XGET hostname -i:9200/_cluster/health?pretty
curl -XGET hostname -i:9200/_cat/health?v
curl -XGET hostname -i:9200/_cluster/health?pretty
2、查看索引级别健康状态
curl -XGET hostname -i:9200/_cluster/health?level=indices
3、查看集群设置
curl -XGET hostname -i:9200/_settings
curl -XGET hostname -i:9200/_cluster/settings
4、查看节点信息
curl -XGET hostname -i:9200/_cat/nodes?v
curl -XGET hostname -i:9200/_cluster/health?level=shards'
curl -XGET hostname -i:9200/_cat/allocation?v
5、创建索引指定分片副本
curl -XPUT hostname -i -H 'Content-Type: application/json' -d'
{
"settings" : {
"number_of_shards" : 3,
"number_of_replicas" : 1
}
}
'
6、删除索引
curl -XDELETE hostname -i:9200/test
7、索引文档
curl -XPUT hostname -i:9200/test/article/10 -H 'Content-Type: application/json' -d'
{
"first_name" : "simon",
"last_name" : "Smith",
"age" : 23,
"hello" : "world",
"note" : "2018-12-12",
"about" : "洪荒之力",
"interests": [ "sports", "music" ]
}
'
8、修改副本分片
curl -XPUT hostname -i:9200/test/_settings -H 'Content-Type: application/json' -d'
{
"number_of_replicas": 0
}'
9、查看索引设置
curl -XGET hostname -i:9200/blogs/_settings?pretty
10、查看索引下所有文档
curl -XGET hostname -i:9200/blogs/_search
curl -XPOST hostname -i:9200/bank/_search?pretty -d '
{
"query": { "match_all": {} }
}
'
11、修改集群exclude节点,persistent 重启后仍生效
curl -XPUT hostname -i:9200/_cluster/settings -H 'Content-Type: application/json' -d'
{
"persistent": {
"cluster.routing.allocation.exclude._name":"node-name"
}
}'
12、修改集群exclude节点,transient 立即生效,重启失效
curl -XPUT hostname -i:9200/_cluster/settings -H 'Content-Type: application/json' -d'
{
"transient": {
"cluster.routing.allocation.exclude._name":"node-name"
}
}'
13、修改集群exclude IP
curl -XPUT hostname -i:9200/_cluster/settings -H 'Content-Type: application/json' -d'
{
"transient": {
"cluster.routing.allocation.exclude._ip":"your_ip"
}
}'
14、查询并删除es5.x 后版本支持
curl -XPOST hostname -i:9200/blogs/_delete_by_query -H 'Content-Type: application/json' -d'
{
"query":{
"term": {
"age": {
"value": 22
}
}
}
}'
15、查看所有模板
curl -XGET hostname -i:9200/_template
16、查看特定模板
curl -XGET hostname -i:9200/_template/template_1
17、删除特定模板
curl -XDELETE hostname -i:9200/_template/template_1
18、创建特定模板
curl -XPUT hostname -i:9200/_template/template_1 -d '
{
"template" : "zhouls*",
"order" : 0,
"settings" : {
"number_of_shards" : 1
},
"mappings" : {
"type1" : {
"_source" : { "enabled" : false }
}
}
}
'
19、清除缓存索引
curl -XPOST hostname -i:9200/test/_cache/clear
20、查询索引别名
curl -XGET hostname -i:9200/_cat/aliases
21、新建索引别名
curl -XPOST hostname -i:9200/_aliases -H 'Content-Type: application/json' -d'
{
"actions": [
{
"add": {
"index": "search4policy_health_20181220000000",
"alias": "search4policy_health_current_reader"
}
}
]
}'
22、删除别名
curl -XPOSThostname -i:9200/_aliases -d '
{
"actions": [
{"remove": {"index": "test1", "alias": "alias1"}}
]
}'
23、获取未分配分片
curl -XGET hostname -i:9200/_cat/shards?h=index,shard,prirep,state,unassigned.reason | grep UNASSIGNED
24、设置索引刷新间隔
curl -XPUT hostname -i:9200/blogs/_settings -H 'Content-Type: application/json' -d'
{
"refresh_interval": "30s"
}'
25、关闭索引
curl -XPOST hostname -i:9200/zipkin-2019*/_close
26、打开索引
curl -XPOST hostname -i:9200/subao-benefit*/_open
27、查看进行中的任务
curl -XGET hostname -i:9200/_cat/pending_tasks
28、查看线程池执行状态
curl -XGET hostname -i:9200/_cat/thread_pool?v&h=ip,bulk.rejected,search.rejected
29、查看安装插件
curl -XGET hostname -i:9200/_cat/plugins
30、执行sql 语句
curl -XPOST hostname -i:9200/_sql -d 'SELECT * FROM audit'
31、查看 es 节点连接数
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
32、查看集群 mlockall 参数设置
curl -X GET `hostname -i`:9200/_nodes?filter_path=**.mlockall&pretty
33、查看集群file_descriptor
curl -X GET `hostname -i`:9200/_nodes/stats/process?filter_path=**.max_file_descriptors&pretty