Elasticsearch常用命令收集

Elasticsearch常用運維命令收集
原創cm_chenmin 最後發佈於2017-07-06 15:41:34 閱讀數 3719  收藏
展開
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。
————————————————
版權聲明:本文爲CSDN博主「cm_chenmin」的原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/cm_chenmin/article/details/74557230

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