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"
}
}
}
}
'
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。