一 概述
最近做Elasticsearch优化,需要调整节点参数,重启,查看是否生效。线下测试集群一般使用head插件,方便。但head插件需要其所在节点能正常提供服务,且客户端浏览器网络可达。这种约束不适合线上运维,最直接方式还是使用Elasticsearch提供的Rest API,通过curl 在某个节点上直接查看。
本文从《Elasticsearch官方文档》,《ElasticSearch权威指南》中总结常用命令,用于维护使用,同时摘录了节点启动流程。
二 管理命令
(一)集群
(1)简单查看集群状态
主要用来查看系统状态是否正常,节点是否都在,以及所有可用的主分片,活跃分片。
命令:curl -X GET 'http://[host]:9200/_cluster/health?pretty=true'
结果分析:
{ "cluster_name": "test", "status": "green", "timed_out": false, "number_of_nodes": 3, --节点数量 "number_of_data_nodes": 3, --数据节点数量 "active_primary_shards": 16, --主分配数量 "active_shards": 36, --活跃分片数量 "relocating_shards": 0, "initializing_shards": 0, "unassigned_shards": 0, "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": 100.0 }
(2)查看集群静态信息
API返回基本索引度量(分片数量,存储大小,内存使用情况)以及有关当前构成集群的节点(数量,角色,操作系统,jvm版本,内存使用情况,cpu和安装的插件)的信息。这里是集群角度,好多参数汇总了。
命令:curl -XGET 'http://[host]:9200/_cluster/stats?pretty=true'
结果分析:
{ "timestamp" : 1523761069417, "cluster_name" : "test", "status" : "green", "indices" : { --索引情况 "count" : 12, --索引总数:不包括关闭的 "shards" : { "total" : 36, --分片总数:包括主分片和副本分片 "primaries" : 16, "replication" : 1.25, "index" : { "shards" : { "min" : 2, "max" : 10, "avg" : 3.0 }, "primaries" : { "min" : 1, "max" : 5, "avg" : 1.3333333333333333 }, "replication" : { "min" : 1.0, "max" : 2.0, "avg" : 1.3333333333333333 } } }, "docs" : { --文档信息 "count" : 6797, --当前索引的document总数 "deleted" : 1 --删除的数量 }, "store" : { --存储信息 "size_in_bytes" : 41453178, --占用空间大小 "throttle_time_in_millis" : 0 --限流时间,如果限流时间很大,那可能表明你的磁盘限流设置得过低 }, "fielddata" : { "memory_size_in_bytes" : 0, "evictions" : 0 }, "query_cache" : { --查询缓存信息 "memory_size_in_bytes" : 0, --内存使用大小 "total_count" : 585, --索引文档数 "hit_count" : 0, --命中数量 "miss_count" : 585, --未命中数量 "cache_size" : 0, --缓存大小 "cache_count" : 0, --缓存数量 "evictions" : 0 }, "completion" : { "size_in_bytes" : 0 }, "segments" : { --lucene segment信息, "count" : 92, --segment总数 "memory_in_bytes" : 1769262, --内存使用总大小 "terms_memory_in_bytes" : 851222, "stored_fields_memory_in_bytes" : 40024, "term_vectors_memory_in_bytes" : 0, "norms_memory_in_bytes" : 8896, "doc_values_memory_in_bytes" : 869120, "index_writer_memory_in_bytes" : 0, "index_writer_max_memory_in_bytes" : 18432000, "version_map_memory_in_bytes" : 0, "fixed_bit_set_memory_in_bytes" : 0 }, "percolate" : { "total" : 0, "time_in_millis" : 0, "current" : 0, "memory_size_in_bytes" : -1, "memory_size" : "-1b", "queries" : 0 } }, "nodes" : { --节点信息 "count" : { "total" : 3, --节点总数 "master_only" : 0, --只有master职能的节点数 "data_only" : 0, --只有data职能的节点数 "master_data" : 3, --既有master,又有data职能的节点数 "client" : 0 --client 已经废弃了,我这测的是2.4.2版本 }, "versions" : [ "2.4.2" ], -- es 版本 "os" : { --操作系统信息 "available_processors" : 32, --系统总核数 "allocated_processors" : 32, --分配核数 "mem" : { --内存系统 "total_in_bytes" : 2344828928 --内存总大小 }, "names" : [ { "name" : "Linux", "count" : 1 } ] }, "process" : { --进程信息 "cpu" : { "percent" : 0 --cpu使用率 }, "open_file_descriptors" : { -- 文件句柄信息 "min" : 831, "max" : 843, "avg" : 836 } }, "jvm" : { --jvm信息 "max_uptime_in_millis" : 24388094000, "versions" : [ { "version" : "1.7.0_65", "vm_name" : "OpenJDK 64-Bit Server VM", "vm_version" : "24.65-b04", "vm_vendor" : "Oracle Corporation", "count" : 3 } ], "mem" : { --jvm内存信息 "heap_used_in_bytes" : 3285903704, -- 当前堆使用大小 "heap_max_in_bytes" : 12455510016 -- 堆总大小 }, "threads" : 1059 --总线程数 }, "fs" : { --文件系统信息 "total_in_bytes" : 1647163199488, -- 文件系统大小 "free_in_bytes" : 849916973056, "available_in_bytes" : 766239141888, "spins" : "true" }, "plugins" : [ { -- 插件信息 "name" : "marvel-agent", "version" : "2.4.2", "description" : "Elasticsearch Marvel Agent", "jvm" : true, "classname" : "org.elasticsearch.marvel.MarvelPlugin", "isolated" : false, "site" : false }, { "name" : "license", "version" : "2.4.2", "description" : "Internal Elasticsearch Licensing Plugin", "jvm" : true, "classname" : "org.elasticsearch.license.plugin.LicensePlugin", "isolated" : false, "site" : false }, { "name" : "head", "version" : "master", "description" : "head - A web front end for an elastic search cluster", "url" : "/_plugin/head/", "jvm" : false, "site" : true } ] } }
(二)节点
(1)查看节点信息
可以用来验证集群配置修改是否生效。
命令:
(1)查看所有节点:curl -XGET 'http://[host]:9200/_nodes?pretty=true'
(2)查看单个节点:curl -XGET 'http://[host]:9200/_nodes/[node_name]?pretty=true'
结果分析:
{ "cluster_name" : "test", "nodes" : { --节点信息 "La0pzwQrQDK-r9B5JzNuIA" : { "name" : "node3", --节点名称 "transport_address" : "127.0.0.1:9300", "host" : "127.0.0.1", "ip" : "127.0.0.1", "version" : "2.4.2", "build" : "161c65a", "http_address" : "127.0.0.1:9200", "attributes" : { --是否是master "master" : "true" }, "settings" : { --节点配置 "index" : { "search" : { "slowlog" : { --慢查询配置 "threshold" : { "fetch" : { "trace" : "25ms" }, "query" : { "trace" : "25ms" } } } } }, "client" : { "type" : "node" }, "pidfile" : "/elasticsearch/2.4.2/node3.pid", "network" : { --网络监听情况 "host" : "0.0.0.0" }, "node" : { "data" : "true", "master" : "true", "name" : "node3" }, "marvel" : { --marvel监控地址 "agent" : { "exporters" : { "id1" : { "type" : "http", "host" : [ "http://127.0.0.1:9250" ] } } } }, "transport" : { --tcp 信息 "tcp" : { "port" : "9300" } }, "http" : { --http 信息 "port" : "9200" }, "name" : "node3", "path" : { --文件存储路径 "data" : "/elasticsearch/2.4.2/node3", "home" : "/opt/elasticsearch/2.4.2", "conf" : "/etc/elasticsearch/2.4.2/node3", "logs" : "/elasticsearch/2.4.2/logs/node3" }, "cluster" : { "name" : "test" }, "config" : { "ignore_system_properties" : "true" }, "discovery" : { --集群发现信息 "zen" : { "ping" : { "unicast" : { "hosts" : [ "127.0.0.1:9300", "127.0.0.1:9301", "127.0.0.1:9302" ] } } } }, "foreground" : "false" }, "os" : { --操作系统信息 "refresh_interval_in_millis" : 1000, "name" : "Linux", "arch" : "amd64", "version" : "2.6.32-504.el6.x86_64", "available_processors" : 32, "allocated_processors" : 32 }, "process" : { "refresh_interval_in_millis" : 1000, "id" : 3098, "mlockall" : false }, "jvm" : { --jvm信息 "pid" : 3098, "version" : "1.7.0_65", "vm_name" : "OpenJDK 64-Bit Server VM", "vm_version" : "24.65-b04", "vm_vendor" : "Oracle Corporation", "start_time_in_millis" : 1499372985298, "mem" : { "heap_init_in_bytes" : 4294967296, "heap_max_in_bytes" : 4151836672, "non_heap_init_in_bytes" : 24313856, "non_heap_max_in_bytes" : 224395264, "direct_max_in_bytes" : 4151836672 }, "gc_collectors" : [ "ParNew", "ConcurrentMarkSweep" ], "memory_pools" : [ "Code Cache", "Par Eden Space", "Par Survivor Space", "CMS Old Gen", "CMS Perm Gen" ], "using_compressed_ordinary_object_pointers" : "true" }, "thread_pool" : { --线程池信息 "generic" : { "type" : "cached", "keep_alive" : "30s", "queue_size" : -1 }, "index" : { --索引线程池 "type" : "fixed", --线程池类型,fixed是固定大小 "min" : 32, --最小线程数 "max" : 32, --最大线程数 "queue_size" : 200 --线程池大小 }, "fetch_shard_store" : { "type" : "scaling", "min" : 1, "max" : 64, "keep_alive" : "5m", "queue_size" : -1 }, "get" : { "type" : "fixed", "min" : 32, "max" : 32, "queue_size" : 1000 }, "snapshot" : { "type" : "scaling", "min" : 1, "max" : 5, "keep_alive" : "5m", "queue_size" : -1 }, "force_merge" : { "type" : "fixed", "min" : 1, "max" : 1, "queue_size" : -1 }, "suggest" : { "type" : "fixed", "min" : 32, "max" : 32, "queue_size" : 1000 }, "bulk" : { "type" : "fixed", "min" : 32, "max" : 32, "queue_size" : 50 }, "warmer" : { "type" : "scaling", "min" : 1, "max" : 5, "keep_alive" : "5m", "queue_size" : -1 }, "flush" : { "type" : "scaling", "min" : 1, "max" : 5, "keep_alive" : "5m", "queue_size" : -1 }, "search" : { "type" : "fixed", "min" : 49, "max" : 49, "queue_size" : 1000 }, "fetch_shard_started" : { "type" : "scaling", "min" : 1, "max" : 64, "keep_alive" : "5m", "queue_size" : -1 }, "listener" : { "type" : "fixed", "min" : 10, "max" : 10, "queue_size" : -1 }, "percolate" : { "type" : "fixed", "min" : 32, "max" : 32, "queue_size" : 1000 }, "refresh" : { "type" : "scaling", "min" : 1, "max" : 10, "keep_alive" : "5m", "queue_size" : -1 }, "management" : { "type" : "scaling", "min" : 1, "max" : 5, "keep_alive" : "5m", "queue_size" : -1 } }, "transport" : { --tcp 接受请求信息 "bound_address" : [ "[::]:9300" ], "publish_address" : "127.0.0.1:9300", "profiles" : { } }, "http" : { --http接受请求信息 "bound_address" : [ "[::]:9200" ], "publish_address" : "127.0.0.1:9200", "max_content_length_in_bytes" : 104857600 }, "plugins" : [ { --安装插件信息 "name" : "head", "version" : "master", "description" : "head - A web front end for an elastic search cluster", "url" : "/_plugin/head/", "jvm" : false, "site" : true }, { "name" : "license", "version" : "2.4.2", "description" : "Internal Elasticsearch Licensing Plugin", "jvm" : true, "classname" : "org.elasticsearch.license.plugin.LicensePlugin", "isolated" : false, "site" : false }, { "name" : "marvel-agent", "version" : "2.4.2", "description" : "Elasticsearch Marvel Agent", "jvm" : true, "classname" : "org.elasticsearch.marvel.MarvelPlugin", "isolated" : false, "site" : false } ], "modules" : [ { --模块信息,需要支持script时,需要安装响应的modules,是否安装可以在这查看 "name" : "lang-expression", "version" : "2.4.2", "description" : "Lucene expressions integration for Elasticsearch", "jvm" : true, "classname" : "org.elasticsearch.script.expression.ExpressionPlugin", "isolated" : true, "site" : false }, { "name" : "lang-groovy", "version" : "2.4.2", "description" : "Groovy scripting integration for Elasticsearch", "jvm" : true, "classname" : "org.elasticsearch.script.groovy.GroovyPlugin", "isolated" : true, "site" : false }, { "name" : "reindex", "version" : "2.4.2", "description" : "_reindex and _update_by_query APIs", "jvm" : true, "classname" : "org.elasticsearch.index.reindex.ReindexPlugin", "isolated" : true, "site" : false } ] }, 其他节点(略)。。。。。。 } }
(2)查看节点状态信息
可以用来查看系统当前状态,用来确定系统目前的处理情况。最好定时采集,以便日后分析使用。
命令:
(1)查看所有节点:curl -X GET 'http://[host]:9200/_nodes/stats?pretty=true'
(2)查看单个节点:curl -X GET 'http://[host]:9200/_nodes/[node_name]/stats?pretty=true'
结果分析:
{ "cluster_name" : "myapp", "nodes" : { "La0pzwQrQDK-r9B5JzNuIA" : { "timestamp" : 1523769963467, "name" : "node3", "transport_address" : "127.0.0.1:9302", "host" : "127.0.0.1", "ip" : [ "127.0.0.1:9302", "NONE" ], "attributes" : { "master" : "true" }, "indices" : { --索引信息 "docs" : { "count" : 5663, --document数量 "deleted" : 0 }, "store" : { "size_in_bytes" : 17227849, --存储空间大小 "throttle_time_in_millis" : 0 --限流时间,如果限流时间很大,那可能表明你的磁盘限流设置得过 }, "indexing" : { --索引信息 "index_total" : 289046, --索引数据 "index_time_in_millis" : 750592, --索引用时,可以除以索引数量,得到每次索引的平均时间 "index_current" : 0, "index_failed" : 25, "delete_total" : 1423, --删除数据 "delete_time_in_millis" : 382, --删除耗时 "delete_current" : 0, "noop_update_total" : 944, "is_throttled" : false, "throttle_time_in_millis" : 0 }, "get" : { "total" : 1018, "time_in_millis" : 221, "exists_total" : 954, "exists_time_in_millis" : 217, "missing_total" : 64, "missing_time_in_millis" : 4, "current" : 0 }, "search" : { --查询 "open_contexts" : 0, --活跃中的搜索数量 "query_total" : 593899, --query操作数量 "query_time_in_millis" : 980120, --query操作耗时,query_time_in_millis / query_total计算的比值,可以用来粗略的评价你的查询有多高效。比值越大,每个查询花费的时间越多,你应该要考虑调优了。 "query_current" : 0, "fetch_total" : 587866, --fatch数量 "fetch_time_in_millis" : 3692858, --fatch耗时,统计值展示了查询处理的后一半流程(query-then-fetch 里的 fetch),如果 fetch 耗时比 query 还多,说明磁盘较慢,或者获取了太多文档,或者可能搜索请求设置了太大的分页(比如, size: 10000 ) "fetch_current" : 0, "scroll_total" : 0, "scroll_time_in_millis" : 0, "scroll_current" : 0 }, "merges" : { --段合并信息 "current" : 0, --目前运行几个合并 "current_docs" : 0, "current_size_in_bytes" : 0, "total" : 325, --合并次数 "total_time_in_millis" : 65894, --合并操作消耗总时间 "total_docs" : 200942, --合并设计的文档数 "total_size_in_bytes" : 441791060, --合并的段的总大小 "total_stopped_time_in_millis" : 0, "total_throttled_time_in_millis" : 0, "total_auto_throttle_in_bytes" : 18853396480 }, "refresh" : { "total" : 44804, "total_time_in_millis" : 131391 }, "flush" : { "total" : 2239, "total_time_in_millis" : 27722 }, "warmer" : { "current" : 0, "total" : 120, "total_time_in_millis" : 4 }, "query_cache" : { --查询缓存使用情况 "memory_size_in_bytes" : 0, --缓存文档数量 "total_count" : 2, "hit_count" : 0, --命中数量 "miss_count" : 2, --未命中数量 "cache_size" : 0, "cache_count" : 0, "evictions" : 0 }, "fielddata" : { "memory_size_in_bytes" : 0, "evictions" : 0 }, "percolate" : { "total" : 0, "time_in_millis" : 0, "current" : 0, "memory_size_in_bytes" : -1, "memory_size" : "-1b", "queries" : 0 }, "completion" : { "size_in_bytes" : 0 }, "segments" : { --段信息 "count" : 30, "memory_in_bytes" : 717948, --segment内存总大小 "terms_memory_in_bytes" : 332996, "stored_fields_memory_in_bytes" : 14080, "term_vectors_memory_in_bytes" : 0, "norms_memory_in_bytes" : 2304, "doc_values_memory_in_bytes" : 368568, "index_writer_memory_in_bytes" : 0, "index_writer_max_memory_in_bytes" : 6144000, "version_map_memory_in_bytes" : 0, "fixed_bit_set_memory_in_bytes" : 0 }, "translog" : { "operations" : 0, "size_in_bytes" : 516 }, "suggest" : { "total" : 0, "time_in_millis" : 0, "current" : 0 }, "request_cache" : { "memory_size_in_bytes" : 0, "evictions" : 0, "hit_count" : 0, "miss_count" : 0 }, "recovery" : { "current_as_source" : 0, "current_as_target" : 0, "throttle_time_in_millis" : 599 } }, "os" : { --操作系统信息 "timestamp" : 1523769963475, "cpu_percent" : 16, --cpu使用率 "load_average" : 2.89, --负载 "mem" : { --内存信息 "total_in_bytes" : 135282704384, --内存总大小 "free_in_bytes" : 1091211264, --空闲内存大小 "used_in_bytes" : 134191493120, --使用内存大小 "free_percent" : 1, --空闲半分比 "used_percent" : 99 --使用内存百分比 }, "swap" : { --swap信息 "total_in_bytes" : 17179865088, --swap总大小 "free_in_bytes" : 1044086784, --swap空闲大小 "used_in_bytes" : 16135778304 --swap使用大小 } }, "process" : { "timestamp" : 1523769963476, "open_file_descriptors" : 835, --打开的文件句柄数 "max_file_descriptors" : 102400, --最大文件句柄数 "cpu" : { "percent" : 0, "total_in_millis" : 269254050 --cpm使用时间 }, "mem" : { "total_virtual_in_bytes" : 22376689664 } }, "jvm" : { --jvm信息 "timestamp" : 1523769963478, "uptime_in_millis" : 24396978180, "mem" : { "heap_used_in_bytes" : 1420965384, --堆使用大小 "heap_used_percent" : 34, --堆使用率 "heap_committed_in_bytes" : 4151836672, "heap_max_in_bytes" : 4151836672, --堆总大小 "non_heap_used_in_bytes" : 62671016, "non_heap_committed_in_bytes" : 63045632, "pools" : { "young" : { --新生代 "used_in_bytes" : 850822912, "max_in_bytes" : 1145372672, "peak_used_in_bytes" : 1145372672, "peak_max_in_bytes" : 1145372672 }, "survivor" : { --幸存者区 "used_in_bytes" : 5660696, "max_in_bytes" : 143130624, "peak_used_in_bytes" : 96813656, "peak_max_in_bytes" : 143130624 }, "old" : { --老年代 "used_in_bytes" : 564481776, "max_in_bytes" : 2863333376, "peak_used_in_bytes" : 564481776, "peak_max_in_bytes" : 2863333376 } } }, "threads" : { --线程 "count" : 342, --线程总数 "peak_count" : 348 --峰值 }, "gc" : { "collectors" : { "young" : { --young gc "collection_count" : 1718, "collection_time_in_millis" : 49102 }, "old" : { --old gc "collection_count" : 0, "collection_time_in_millis" : 0 } } }, "buffer_pools" : { "direct" : { "count" : 494, "used_in_bytes" : 70016422, "total_capacity_in_bytes" : 70016422 }, "mapped" : { "count" : 15, "used_in_bytes" : 3549927, "total_capacity_in_bytes" : 3549927 } } }, "thread_pool" : { --线程池情况 "bulk" : { "threads" : 32, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 32, "completed" : 287583 }, "fetch_shard_started" : { "threads" : 1, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 1, "completed" : 1 }, "fetch_shard_store" : { "threads" : 1, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 10, "completed" : 11 }, "flush" : { "threads" : 1, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 5, "completed" : 4521 }, "force_merge" : { "threads" : 1, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 1, "completed" : 1 }, "generic" : { "threads" : 1, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 20, "completed" : 26875520 }, "get" : { "threads" : 10, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 10, "completed" : 10 }, "index" : { "threads" : 23, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 23, "completed" : 23 }, "listener" : { "threads" : 10, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 10, "completed" : 20150413 }, "management" : { "threads" : 5, "queue" : 0, "active" : 1, "rejected" : 0, "largest" : 5, "completed" : 1629062 }, "percolate" : { "threads" : 0, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 0, "completed" : 0 }, "refresh" : { "threads" : 1, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 10, "completed" : 44804 }, "search" : { --查询 "threads" : 49, --查询线程数 "queue" : 0, --查询队列长度 "active" : 0, --正在处理的请求数 "rejected" : 0, --拒绝的查询请求数量:rejected 受threadpool.search.queue_size: 限制,如果处理能力达到了极限,poo满,就会拒绝。 "largest" : 49, "completed" : 703061 }, "snapshot" : { "threads" : 0, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 0, "completed" : 0 }, "suggest" : { "threads" : 0, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 0, "completed" : 0 }, "warmer" : { "threads" : 1, "queue" : 0, "active" : 0, "rejected" : 0, "largest" : 2, "completed" : 5735 } }, "fs" : { --文件系统 "timestamp" : 1523769963478, "total" : { "total_in_bytes" : 1647163199488, --文件系统总大小 "free_in_bytes" : 848772972544, --空闲大小 "available_in_bytes" : 765095141376, "spins" : "true" }, "data" : [ { "path" : "/elasticsearch/2.4.2/node3/myapp/nodes/0", "mount" : " (/dev/sda7)", "type" : "ext4", "total_in_bytes" : 1647163199488, "free_in_bytes" : 848772972544, "available_in_bytes" : 765095141376, "spins" : "true" } ] }, "transport" : { --tcp信息 "server_open" : 91, "rx_count" : 72012076, "rx_size_in_bytes" : 9420555589, "tx_count" : 72006544, "tx_size_in_bytes" : 29520860012 }, "http" : { --http信息:如果你看到 total_opened 数很大而且还在一直上涨,这是一个明确信号,说明你的 HTTP 客户端里有没启用 keep-alive 长连接的。持续的 keep-alive 长连接对性能很重要,因为连接、断开套接字是很昂贵的(而且浪费文件描述符)。请确认你的客户端都配置正确。 "current_open" : 0, "total_opened" : 0 }, "breakers" : { --断路器 "in_flight_requests" : { "limit_size_in_bytes" : 4151836672, "limit_size" : "3.8gb", "estimated_size_in_bytes" : 123, "estimated_size" : "123b", "overhead" : 1.0, "tripped" : 0 }, "fielddata" : { "limit_size_in_bytes" : 2491102003, "limit_size" : "2.3gb", "estimated_size_in_bytes" : 0, "estimated_size" : "0b", "overhead" : 1.03, "tripped" : 0 }, "request" : { "limit_size_in_bytes" : 1660734668, "limit_size" : "1.5gb", "estimated_size_in_bytes" : 0, "estimated_size" : "0b", "overhead" : 1.0, "tripped" : 0 }, "parent" : { "limit_size_in_bytes" : 2906285670, "limit_size" : "2.7gb", "estimated_size_in_bytes" : 123, "estimated_size" : "123b", "overhead" : 1.0, "tripped" : 0 } }, "script" : { "compilations" : 0, "cache_evictions" : 0 } }, 其他节点(略) 。。。。。。 } }
(三)索引
(1)查看索引库健康情况
命令: curl -X GET 'http://[host]:9200/_cluster/health/[indics_name]?pretty=true'
结果分析:
{ "cluster_name" : "test", "status" : "green", "timed_out" : false, "number_of_nodes" : 3, --节点数 "number_of_data_nodes" : 3, --数据节点数 "active_primary_shards" : 5, --该索引主分片数 "active_shards" : 10, --活跃分片数 "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 0, "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" : 100.0 }
(2)查看索引状态信息
命令:curl -X GET 'http://[host]:9200/[indics_name]/_stats?pretty=true'
结果分析:结果字段和集群状态,节点状态类似,只是限制到某个索引级别,不在赘述。
(3)查看索引settings,mappings
命令:curl -X GET 'http://10.168.100.151:9200/[indics_name]?pretty=true'
结果分析:
{ "testdb" : { "aliases" : { }, "mappings" : { "type" : { "properties" : { "id" : { "type" : "string" }, "key" : { "type" : "string" }, "value" : { "type" : "string" } } } }, "settings" : { "index" : { "creation_date" : "1523604202297", "uuid" : "nnEit2ITQBGI9vMO5N1M3w", "number_of_replicas" : "1", "number_of_shards" : "5", "version" : { "created" : "2040299" } } }, "warmers" : { } } }
三 重启流程
摘自《Elasticsearch: 权威指南——滚动重启》:
步骤1:可能的话,停止索引新的数据。虽然不是每次都能真的做到,但是这一步可以帮助提高恢复速度。
步骤2:禁止分片分配。这一步阻止 Elasticsearch 再平衡缺失的分片,直到你告诉它可以进行了。如果你知道维护窗口会很短,这个主意棒极了。你可以像下面这样禁止分配:
curl -XPUT 'http://[host]:9200/_cluster/settings' -d ' { "transient" : { "cluster.routing.allocation.enable" : "none" } }'
步骤3:关闭单个节点。
步骤4:执行维护/升级。
步骤5:重启节点,然后确认它加入到集群了。
步骤6:用如下命令重启分片分配:
curl -XPUT 'http://[host]:9200/_cluster/settings' -d ' { "transient" : { "cluster.routing.allocation.enable" : "all" } }'
分片再平衡会花一些时间。一直等到集群变成 绿色 状态后再继续。
步骤7:重复第 2 到 6 步操作剩余节点。
步骤8:到这步你可以安全的恢复索引了(如果你之前停止了的话),不过等待集群完全均衡后再恢复索引,也会有助于提高处理速度。