es 集羣 number_of_shards、number_of_replicas

os: centos 7.4.1708
es: 7.6.2

三節點的es,參考<<es 集羣三節點安裝>>

192.168.56.121  n1
192.168.56.122  n2
192.168.56.123  n3

number_of_shards 是指索引要做多少個分片,只能在創建索引時指定,後期無法修改。
number_of_replicas 是指每個分片有多少個副本,後期可以動態修改

primary shard:主分片,每個文檔都存儲在一個分片中,當你存儲一個文檔的時候,系統會首先存儲在主分片中,然後會複製到不同的副本中。默認情況下,一個索引有5個主分片。你可以在事先制定分片的數量,當分片一旦建立,分片的數量則不能修改。

replica shard:副本分片,每一個分片有零個或多個副本。副本主要是主分片的複製,可以 增加高可用性,提高性能。
默認情況下,一個主分配有一個副本,但副本的數量可以在後面動態的配置增加。
副本必須部署在不同的節點上,不能部署在和主分片相同的節點上。

es 集羣基本信息

# su - es
$ curl -X GET 'http://192.168.56.121:9200/_cat/nodes?v'
ip             heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.56.121           14          99   0    0.00    0.02     0.05 dilm      -      node-1
192.168.56.123           30          99  14    0.67    0.23     0.11 dilm      -      node-3
192.168.56.122           32          99   0    0.06    0.03     0.05 dilm      *      node-2

$ curl -XGET http://192.168.56.121:9200/_license
{
  "license" : {
    "status" : "active",
    "uid" : "bfa9bde9-4b68-45a7-92c9-8c5ac7f122f7",
    "type" : "basic",
    "issue_date" : "2020-05-18T11:57:49.475Z",
    "issue_date_in_millis" : 1589803069475,
    "max_nodes" : 1000,
    "issued_to" : "my-cluster",
    "issuer" : "elasticsearch",
    "start_date_in_millis" : -1
  }
}

$ curl -XGET 'http://192.168.56.123:9200/_cluster/health?pretty'  
{
  "cluster_name" : "my-cluster",
  "status" : "green",
  "timed_out" : false,
  "number_of_nodes" : 3,
  "number_of_data_nodes" : 3,
  "active_primary_shards" : 0,
  "active_shards" : 0,
  "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
}

number_of_shards

number_of_shards 只能在創建 index 指定,後期無法修改

創建 testindex

curl -XPUT 'http://192.168.56.121:9200/testindex' -H 'Content-Type: application/json' -d ' 
{
    "settings": {
     "number_of_shards": 10,
	 "number_of_replicas" : 1
    }
}
'

查看 testindex 索引

curl -XGET 'http://192.168.56.121:9200/testindex/_settings?pretty'
{
  "testindex" : {
    "settings" : {
      "index" : {
        "creation_date" : "1589862851550",
        "number_of_shards" : "10",
        "number_of_replicas" : "1",
        "uuid" : "WimYHgHmTQCL0iniMg-Ybw",
        "version" : {
          "created" : "7060299"
        },
        "provided_name" : "testindex"
      }
    }
  }
}

number_of_replicas

number_of_replicas 可以在線修改

curl -XPUT 'http://192.168.56.121:9200/testindex/_settings' -H 'Content-Type: application/json' -d ' 
{
    "index" : {
        "number_of_replicas" : 2
    }
}
'

也可以修改模板

curl -X PUT "http://192.168.56.121:9200/filebeat*/_settings" -H 'Content-Type: application/json' -d'
{
    "index" : {
        "number_of_replicas" : 2
    }
}
'

或者創建新的模板

curl -X PUT "http://192.168.56.121:9200/_template/template_log" -H 'Content-Type: application/json' -d'
{
    "index_patterns" : ["filebeat*"],
    "order" : 0,
    "settings" : {
        "number_of_replicas" : 2
    }
}
'

刪除 index

查看

$ curl -XGET 'http://192.168.56.121:9200/_cat/indices?v'

health status index     uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green  open   testindex WimYHgHmTQCL0iniMg-Ybw  10   2          0            0      8.2kb          2.7kb

刪除測試用的 index

$ curl -XDELETE  http://192.168.56.121:9200/testindex

參考:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章