elasticserch日常维护

days 1

elasticsearch 索引和数据操作

  • 查看索引

    1
    # curl -XGET 'http://127.0.0.1:9200/_cat/indices?v'
  • 删除索引

    1
    2
    3
    # curl -XGET 'http://127.0.0.1:9200/_cat/indices?v' |grep "red"|awk '{print $3}'|uniq >l

    # for i in `cat a`;do curl -XDELETE http://127.0.0.1:9200/${i};done
  • 查看shards

    1
    # curl -XGET http://127.0.0.1:9200/_cat/shards

        shards 有几种类型,这里说一下UNASSIGNED,es 集群里面的分片是分配在多台node上的,为的就是高可用,比如你的某台机器crash了,那么集群就会让其他副本顶上来,避免出现某个分片不能提供服务的情况,但是难免还是会出现 UNASSIGNED shards 的错误。

  • 删除shards UNASSIGNED
    1
    2
    3
    # curl -XGET 'http://127.0.0.1:9200/_cat/shards'|grep "UNASSIGNED"|awk '{print $1}'|uniq >l

    # for i in `cat l`;do curl -XDELETE http://127.0.0.1:9200/$i;done

elasticsearch验证集群

  • 集群相关API

    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
    $ curl http://127.0.0.1:9200/_cat
    =^.^=
    /_cat/allocation
    /_cat/shards
    /_cat/shards/{index}
    /_cat/master
    /_cat/nodes
    /_cat/tasks
    /_cat/indices
    /_cat/indices/{index}
    /_cat/segments
    /_cat/segments/{index}
    /_cat/count
    /_cat/count/{index}
    /_cat/recovery
    /_cat/recovery/{index}
    /_cat/health
    /_cat/pending_tasks
    /_cat/aliases
    /_cat/aliases/{alias}
    /_cat/thread_pool
    /_cat/thread_pool/{thread_pools}
    /_cat/plugins
    /_cat/fielddata
    /_cat/fielddata/{fields}
    /_cat/nodeattrs
    /_cat/repositories
    /_cat/snapshots/{repository}
    /_cat/templates
  • 查看集群名称等信息

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    $ curl http://127.0.0.1:9200
    {
    "name" : "elk_elasticsearch_data_2",
    "cluster_name" : "elk_elasticsearch",
    "cluster_uuid" : "T47wQwa6TT-6MHJVFM40Tw",
    "version" : {
    "number" : "6.4.0",
    "build_flavor" : "default",
    "build_type" : "rpm",
    "build_hash" : "595516e",
    "build_date" : "2018-08-17T23:18:47.308994Z",
    "build_snapshot" : false,
    "lucene_version" : "7.4.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
    },
    "tagline" : "You Know, for Search"
    }
  • 查看master节点信息

    1
    2
    3
    $ curl http://127.0.0.1:9200/_cat/master\?v             
    id host ip node
    HNc5BrMWQcummBeAskQc4A 172.21.1.12 172.21.1.12 elk_elasticsearch_data_3
  • 查看集群节点

    1
    2
    3
    4
    5
    $ curl http://127.0.0.1:9200/_cat/nodes?v
    ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
    172.21.1.10 29 85 0 0.10 0.04 0.05 mdi - elk_elasticsearch_data_2
    172.21.1.11 48 85 0 0.00 0.01 0.05 mdi * elk_elasticsearch_master
    172.21.1.12 25 86 0 0.08 0.03 0.05 mdi - elk_elasticsearch_data_3
  • 验证集群磁盘分配情况

    1
    2
    3
    4
    5
    $ curl http://127.0.0.1:9200/_cat/allocation?v
    shards disk.indices disk.used disk.avail disk.total disk.percent host ip node
    98 1gb 3.6gb 96.3gb 99.9gb 3 172.21.1.10 172.21.1.10 elk_elasticsearch_data_2
    99 887.1mb 4.5gb 95.4gb 99.9gb 4 172.21.1.11 172.21.1.11 elk_elasticsearch_master
    99 957mb 3.5gb 96.4gb 99.9gb 3 172.21.1.12 172.21.1.12 elk_elasticsearch_data_3
  • 验证集群健康状况

    1
    2
    3
    4
    5
    $ curl http://127.0.0.1:9200/_cat/health?v 
    epoch timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
    1571648406 17:00:06 elk_elasticsearch green 3 3 296 148 0 0 0 0 - 100.0%

    $
  • 查看每个数据节点上被fielddata所使用的堆内存大小。

    1
    2
    3
    4
    5
    6
    7
    $ curl http://127.0.0.1:9200/_cat/fielddata?v
    id host ip node field size
    VNcRqM30T3axzVjiPkDTmA 172.21.1.11 172.21.1.11 elk_elasticsearch_master event.resultCode.keyword 352b
    VNcRqM30T3axzVjiPkDTmA 172.21.1.11 172.21.1.11 elk_elasticsearch_master type 720b
    HNc5BrMWQcummBeAskQc4A 172.21.1.12 172.21.1.12 elk_elasticsearch_data_3 event.resultCode.keyword 704b
    z3zUA8KxTH6B7C8CmVRUIQ 172.21.1.10 172.21.1.10 elk_elasticsearch_data_2 type 720b
    z3zUA8KxTH6B7C8CmVRUIQ 172.21.1.10 172.21.1.10 elk_elasticsearch_data_2 event.resultCode.keyword 704b
  • 查询整个集群或单个索引的文档数量

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    $ curl http://127.0.0.1:9200/_cat/count\?v     
    epoch timestamp count
    1582186571 16:16:11 199934243

    $ curl http://127.0.0.1:9200/_cat/count/zxc-2020-02\?v
    epoch timestamp count
    1582186630 16:17:10 16051770
    ```

    - 查看索引信息
    ``` bash
    $ curl http://127.0.0.1:9200/_cat/indices\?v
    health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
    green open zxc-2020-02 nEMlX8DlSpCDRuLfTYDltA 5 1 16052200 0 10.9gb 5.3gb
    green open zxc-2019-12 xgsd_woRQbGMmJz53x8WNQ 5 1 36464829 0 22.1gb 11gb

    $ curl http://127.0.0.1:9200/_cat/indices/zxc-2020-02\?v
    health status index uuid pri rep docs.count docs.deleted store.size pri.store.size
    green open zxc-2020-02 nEMlX8DlSpCDRuLfTYDltA 5 1 16052235 0 10.9gb 5.3gb
坚持原创技术分享,您的支持将鼓励我继续创作!
0%