Elasticsearch分片状态
新建、索引和删除请求都是写(write)操作,它们必须在主分片上成功完成才能复制到相关的复制分片上,下面我们罗列在主分片和复制分片上成功新建、索引或删除一个文档必要的顺序步骤:
-> 客户端给Node 1发送新建、索引或删除请求。
-> 节点使用文档的_id确定文档属于分片0。它转发请求到Node 3,分片0位于这个节点上。
-> Node 3在主分片上执行请求,如果成功,它转发请求到相应的位于Node 1和Node 2的复制节点上。当所有的复制节点报告成功,Node 3报告成功到请求的节点,请求的节点再报告给客户端。 客户端接收到成功响应的时候,文档的修改已经被应用于主分片和所有的复制分片。你的修改生效了
- 查看分片状态
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[root@elk-node03 ~] # curl -X GET 'http://10.0.8.47:9200/_cluster/health?pretty' { "cluster_name" : "kevin-elk" , "status" : "green" , "timed_out" : false , "number_of_nodes" : 3, "number_of_data_nodes" : 3, "active_primary_shards" : 2214, "active_shards" : 4428, "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 } |
这里需要注意: 如下是单点单节点部署Elasticsearch, 集群状态可能为yellow, 因为单点部署Elasticsearch, 默认的分片副本数目配置为1,而相同的分片不能在一个节点上,所以就存在副本分片指定不明确的问题,所以显示为yellow,可以通过在Elasticsearch集群上添加一个节点来解决问题,如果不想这么做,可以删除那些指定不明确的副本分片(当然这不是一个好办法)但是作为测试和解决办法还是可以尝试的,下面试一下删除副本分片的办法:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
[root@elk-server ~] # curl -X GET 'http://localhost:9200/_cluster/health?pretty' { "cluster_name" : "elasticsearch" , "status" : "yellow" , "timed_out" : false , "number_of_nodes" : 1, "number_of_data_nodes" : 1, "active_primary_shards" : 931, "active_shards" : 931, "relocating_shards" : 0, "initializing_shards" : 0, "unassigned_shards" : 930, "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" : 50.02686727565825 } [root@elk-server ~] # curl -XPUT "http://localhost:9200/_settings" -d' { "number_of_replicas" : 0 } ' { "acknowledged" : true } 这个时候再次查看集群的状态状态变成了green [root@elk-server ~] # curl -X GET 'http://localhost:9200/_cluster/health?pretty' { "cluster_name" : "elasticsearch" , "status" : "green" , "timed_out" : false , "number_of_nodes" : 1, "number_of_data_nodes" : 1, "active_primary_shards" : 931, "active_shards" : 931, "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 } |