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

参考:

Logo

开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!

更多推荐