Elasticsearch常用运维命令收集

来源:互联网 发布:苏联经济数据 编辑:程序博客网 时间:2024/06/07 03:51
elasticsearch运维常用命令

elasticsearch内存设置:
export ES_HEAP_SIZE=10g

或者启动的时候设置参数,确保Xmx和Xms大小相等:
./bin/elasticsearch -Xmx10g -Xms10g

启动进程:
./elasticsearch -d

查看es进程:
ps -ef | grep elastic

kill进程:
kill pid

cat系列
_cat系列提供了一系列查询elasticsearch集群状态的接口,可以通过执行
curl -XGET localhost:9200/_cat获取所有_cat系列的操作:
/_cat/allocation
/_cat/shards
/_cat/shards/{index}
/_cat/master
/_cat/nodes
/_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/plugins
/_cat/fielddata
/_cat/fielddata/{fields}
可以后面加一个v,让输出内容表格显示表头,命令示例:
命令示例:
显示所有索引:
curl '10.116.182.65:9200/_cat/indices?v'   
显示线程信息:
curl '10.110.79.24:9200/_cat/thread_pool?v'
显示结点:
curl '10.110.79.24:9200/_cat/nodes'

cluster系列
1、查询设置集群状态
curl -XGET localhost:9200/_cluster/health?pretty=true
pretty=true 表示格式化输出
level=indices 表示显示索引状态
level=shards 表示显示分片信息

2、curl -XGET 10.116.182.65:9200/_cluster/stats?pretty=true
显示集群系统信息,包括CPU JVM等等

3、curl -XGET 10.116.182.65:9200/_cluster/state?pretty=true
集群的详细信息。包括节点、分片等

3、curl -XGET 10.116.182.65:9200/_cluster/pending_tasks?pretty=true
获取集群堆积的任务

3、修改集群配置
举例:
curl -XPUT localhost:9200/_cluster/settings -d '{
    "persistent" : {
        "discovery.zen.minimum_master_nodes" : 2
    }
}'
transient 表示临时的,persistent表示永久的

4、curl -XPOST 'localhost:9200/_cluster/reroute' -d 'xxxxxx'
对shard的手动控制

5、关闭节点
关闭指定192.168.1.1节点
curl -XPOST 'http://192.168.1.1:9200/_cluster/nodes/_local/_shutdown'
curl -XPOST 'http://localhost:9200/_cluster/nodes/192.168.1.1/_shutdown'
关闭主节点
curl -XPOST 'http://localhost:9200/_cluster/nodes/_master/_shutdown'
关闭整个集群
curl -XPOST 'http://localhost:9200/_shutdown?delay=10s'
curl -XPOST 'http://localhost:9200/_cluster/nodes/_shutdown'
curl -XPOST 'http://localhost:9200/_cluster/nodes/_all/_shutdown'
delay=10s表示延迟10秒关闭

nodes系列
1、查询节点的状态
curl -XGET 'http://localhost:9200/_nodes/stats?pretty=true'
curl -XGET 'http://localhost:9200/_nodes/192.168.1.2/stats?pretty=true'
curl -XGET 'http://localhost:9200/_nodes/process'
curl -XGET 'http://localhost:9200/_nodes/_all/process'
curl -XGET 'http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/jvm,process'
curl -XGET 'http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/info/jvm,process'
curl -XGET 'http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/_all
curl -XGET 'http://localhost:9200/_nodes/hot_threads

索引操作
创建索引:
curl -XPUT 'http://10.202.153.58:9200/fvp~oncarsummary/oncarsummary'
curl -XPUT 'http://10.202.153.58:9200/fvp~onaviationtasksummary/onaviationtasksummary'

查看所有索引 :
curl '10.202.34.211:9200/_cat/indices?v'  
 
索引数据
curl -XPOST 'http://localhost:9200/{index}/{type}/{id}' -d'{"a":"avalue","b":"bvalue"}'
curl -XPUT 'http://localhost:9200/{index}/{type}/{id}' -d'{"a":"avalue","b":"bvalue"}'

查询索引:
curl -XGET '10.202.34.211:9200/fvp~onaviationtasksummary/fvp/_search?q=*&pretty'
curl -XGET '10.202.34.211:9200/fvp~oncarsummary/fvp/_search?q=*&pretty'

GET /megacorp/employee/_search //查询全部员工
GET /megacorp/employee/_search?q=last_name:Smith //查询last_name为Smith的员工
curl -XGET http://10.110.79.22:9200/new-sgs-rbil-core-system-dds-next-tcs-server-core-dcn-2017-06-27/record/_search?pretty -d '{
    "query": {
        "match": {
            "@message": "b241defa715b52fa56bca5fd0d81530e"
        }
    }
}'

删除索引
curl -XDELETE 'http://localhost:9200/{index}/{type}/{id}'


获取mapping
curl -XGET http://localhost:9200/{index}/{type}/_mapping?pretty

刷新索引:
curl -XPOST 'http://localhost:9200/kimchy,elasticsearch/_refresh'
curl -XPOST 'http://localhost:9200/_refresh'

设置mapping:
curl -XPOST "http://127.0.0.1:9200/productindex/product/_mapping?pretty" -d ' 
{
    "product": {
            "properties": {
                "title": {
                    "type": "string",
                    "store": "yes"
                },
                "description": {
                    "type": "string",
                    "index": "not_analyzed"
                },
                "price": {
                    "type": "double"
                },
                "onSale": {
                    "type": "boolean"
                },
                "type": {
                    "type": "integer"
                },
                "createDate": {
                    "type": "date"
                }
            }
        }
  }

'


统计ES某个索引数据量:
curl -XGET '10.110.79.22:9200/_cat/count/new-sgs-rbil-core-system-dds-next-tcs-server-core-dcn-2017-06-27'

查看模板:
curl -XGET 10.116.182.65:9200/_template/fvp_waybillnewstatus_template

设置模板:
curl -XPUT http://10.116.182.65:9200/_template/fvp_waybillnewstatus_template?pretty -d ' 
{
    "order" : 1,
    "template" : "fvp~waybillnewstatus*",
    "mappings" : {
      "record" : {
        "properties" : {
          "barOpDeptCode" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "barScanTime" : {
            "type" : "date"
          },
          "containerNo" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "deliveryCityCode" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "deliveryDeptCode" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "intermediateContrNo" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "meterageWeightQty" : {
            "type" : "double",
            "index" : "not_analyzed"
          },
          "opCode" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "pickupCityCode" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "pickupDeptCode" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "productType" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "quantity" : {
            "type" : "long"
          },
          "taskId" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "@timestamp" : {
            "type" : "date",
            "format" : "strict_date_optional_time||epoch_millis"
          },
 "timestamp" : {
            "type" : "date",
            "format" : "strict_date_optional_time||epoch_millis"
          },
          "transportStatus" : {
            "type" : "string",
            "index" : "not_analyzed"
          },
          "waybillNo" : {
            "type" : "string",
            "index" : "not_analyzed"
          }
        }
      }
    }
}'

删除模板
curl -XDELETE localhost:9200/_template/template_1 

设置threadpool:
threadpool:
    bulk:
        type: fixed
        size: 60
        queue_size: 1000

ES慢日志设置:
index.search.slowlog.level: TRACE
index.search.slowlog.threshold.query.warn: 10s
index.search.slowlog.threshold.query.info: 5s
index.search.slowlog.threshold.query.debug: 2s
index.search.slowlog.threshold.query.trace: 500ms
index.search.slowlog.threshold.fetch.warn: 1s
index.search.slowlog.threshold.fetch.info: 800ms
index.search.slowlog.threshold.fetch.debug:500ms
index.search.slowlog.threshold.fetch.trace: 200ms

zen设置:
discovery.zen.ping.timeout: 100s
discovery.zen.ping.multicast.enabled: false
设置是否打开多播发现节点,默认是true。
原创粉丝点击