elasticsearch运维常用命令

elasticsearch内存设置:

  1. export ES_HEAP_SIZE=10g

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

启动进程:

./elasticsearch -d

查看es进程:

ps -ef | grep elastic

kill进程:

kill pid

cat系列

  1. _cat系列提供了一系列查询elasticsearch集群状态的接口,可以通过执行
  2. curl -XGET localhost:9200/_cat获取所有_cat系列的操作:
  3. /_cat/allocation
  4. /_cat/shards
  5. /_cat/shards/{index}
  6. /_cat/master
  7. /_cat/nodes
  8. /_cat/indices
  9. /_cat/indices/{index}
  10. /_cat/segments
  11. /_cat/segments/{index}
  12. /_cat/count
  13. /_cat/count/{index}
  14. /_cat/recovery
  15. /_cat/recovery/{index}
  16. /_cat/health
  17. /_cat/pending_tasks
  18. /_cat/aliases
  19. /_cat/aliases/{alias}
  20. /_cat/thread_pool
  21. /_cat/plugins
  22. /_cat/fielddata
  23. /_cat/fielddata/{fields}
  24. 可以后面加一个v,让输出内容表格显示表头,命令示例:
  25. 命令示例:
  26. 显示所有索引:
  27. curl '10.116.182.65:9200/_cat/indices?v'
  28. 显示线程信息:
  29. curl '10.110.79.24:9200/_cat/thread_pool?v'
  30. 显示结点:
  31. curl '10.110.79.24:9200/_cat/nodes'

cluster系列

  1. 1、查询设置集群状态
  2. curl -XGET localhost:9200/_cluster/health?pretty=true
  3. pretty=true 表示格式化输出
  4. level=indices 表示显示索引状态
  5. level=shards 表示显示分片信息
  6. 2curl -XGET 10.116.182.65:9200/_cluster/stats?pretty=true
  7. 显示集群系统信息,包括CPU JVM等等
  8. 3curl -XGET 10.116.182.65:9200/_cluster/state?pretty=true
  9. 集群的详细信息。包括节点、分片等
  10. 3curl -XGET 10.116.182.65:9200/_cluster/pending_tasks?pretty=true
  11. 获取集群堆积的任务
  12. 4、修改集群配置
  13. 举例:
  14. curl -XPUT localhost:9200/_cluster/settings -d '{
  15. "persistent" : {
  16. "discovery.zen.minimum_master_nodes" : 2
  17. }
  18. }'
  19. transient 表示临时的,persistent表示永久的
  20. 5curl -XPOST 'localhost:9200/_cluster/reroute' -d 'xxxxxx'
  21. shard的手动控制
  22. 6、关闭节点
  23. 关闭指定192.168.1.1节点
  24. curl -XPOST 'http://192.168.1.1:9200/_cluster/nodes/_local/_shutdown'
  25. curl -XPOST 'http://localhost:9200/_cluster/nodes/192.168.1.1/_shutdown'
  26. 关闭主节点
  27. curl -XPOST 'http://localhost:9200/_cluster/nodes/_master/_shutdown'
  28. 关闭整个集群
  29. curl -XPOST 'http://localhost:9200/_shutdown?delay=10s'
  30. curl -XPOST 'http://localhost:9200/_cluster/nodes/_shutdown'
  31. curl -XPOST 'http://localhost:9200/_cluster/nodes/_all/_shutdown'
  32. delay=10s表示延迟10秒关闭

nodes系列

  1. 1、查询节点的状态
  2. curl -XGET 'http://localhost:9200/_nodes/stats?pretty=true'
  3. curl -XGET 'http://localhost:9200/_nodes/192.168.1.2/stats?pretty=true'
  4. curl -XGET 'http://localhost:9200/_nodes/process'
  5. curl -XGET 'http://localhost:9200/_nodes/_all/process'
  6. curl -XGET 'http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/jvm,process'
  7. curl -XGET 'http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/info/jvm,process'
  8. curl -XGET 'http://localhost:9200/_nodes/192.168.1.2,192.168.1.3/_all
  9. curl -XGET 'http://localhost:9200/_nodes/hot_threads

索引操作

  1. 创建索引:
  2. curl -XPUT 'http://10.202.153.58:9200/fvp~oncarsummary/oncarsummary'
  3. curl -XPUT 'http://10.202.153.58:9200/fvp~onaviationtasksummary/onaviationtasksummary'
  4. 查看所有索引
  5. curl '10.202.34.211:9200/_cat/indices?v'
  6. 索引数据
  7. curl -XPOST 'http://localhost:9200/{index}/{type}/{id}' -d'{"a":"avalue","b":"bvalue"}'
  8. curl -XPUT 'http://localhost:9200/{index}/{type}/{id}' -d'{"a":"avalue","b":"bvalue"}'
  9. 查询索引:
  10. curl -XGET '10.202.34.211:9200/fvp~onaviationtasksummary/fvp/_search?q=*&pretty'
  11. curl -XGET '10.202.34.211:9200/fvp~oncarsummary/fvp/_search?q=*&pretty'
  12. GET /megacorp/employee/_search //查询全部员工
  13. GET /megacorp/employee/_search?q=last_name:Smith //查询last_name为Smith的员工
  14. 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 '{
  15. "query": {
  16. "match": {
  17. "@message": "b241defa715b52fa56bca5fd0d81530e"
  18. }
  19. }
  20. }'
  21. 删除索引
  22. curl -XDELETE 'http://localhost:9200/{index}/{type}/{id}'
  23. 获取mapping
  24. curl -XGET http://localhost:9200/{index}/{type}/_mapping?pretty
  25. 刷新索引:
  26. curl -XPOST 'http://localhost:9200/kimchy,elasticsearch/_refresh'
  27. curl -XPOST 'http://localhost:9200/_refresh'
  28. 设置mapping:
  29. curl -XPOST "http://127.0.0.1:9200/productindex/product/_mapping?pretty" -d '
  30. {
  31. "product": {
  32. "properties": {
  33. "title": {
  34. "type": "string",
  35. "store": "yes"
  36. },
  37. "description": {
  38. "type": "string",
  39. "index": "not_analyzed"
  40. },
  41. "price": {
  42. "type": "double"
  43. },
  44. "onSale": {
  45. "type": "boolean"
  46. },
  47. "type": {
  48. "type": "integer"
  49. },
  50. "createDate": {
  51. "type": "date"
  52. }
  53. }
  54. }
  55. }
  56. '

模板操作

  1. 统计ES某个索引数据量:
  2. curl -XGET '10.110.79.22:9200/_cat/count/new-sgs-rbil-core-system-dds-next-tcs-server-core-dcn-2017-06-27'
  3. 查看模板:
  4. curl -XGET 10.116.182.65:9200/_template/fvp_waybillnewstatus_template
  5. 设置模板:
  6. curl -XPUT http://10.116.182.65:9200/_template/fvp_waybillnewstatus_template?pretty -d '
  7. {
  8. "order" : 1,
  9. "template" : "fvp~waybillnewstatus*",
  10. "mappings" : {
  11. "record" : {
  12. "properties" : {
  13. "barOpDeptCode" : {
  14. "type" : "string",
  15. "index" : "not_analyzed"
  16. },
  17. "barScanTime" : {
  18. "type" : "date"
  19. },
  20. "containerNo" : {
  21. "type" : "string",
  22. "index" : "not_analyzed"
  23. },
  24. "deliveryCityCode" : {
  25. "type" : "string",
  26. "index" : "not_analyzed"
  27. },
  28. "deliveryDeptCode" : {
  29. "type" : "string",
  30. "index" : "not_analyzed"
  31. },
  32. "intermediateContrNo" : {
  33. "type" : "string",
  34. "index" : "not_analyzed"
  35. },
  36. "meterageWeightQty" : {
  37. "type" : "double",
  38. "index" : "not_analyzed"
  39. },
  40. "opCode" : {
  41. "type" : "string",
  42. "index" : "not_analyzed"
  43. },
  44. "pickupCityCode" : {
  45. "type" : "string",
  46. "index" : "not_analyzed"
  47. },
  48. "pickupDeptCode" : {
  49. "type" : "string",
  50. "index" : "not_analyzed"
  51. },
  52. "productType" : {
  53. "type" : "string",
  54. "index" : "not_analyzed"
  55. },
  56. "quantity" : {
  57. "type" : "long"
  58. },
  59. "taskId" : {
  60. "type" : "string",
  61. "index" : "not_analyzed"
  62. },
  63. "@timestamp" : {
  64. "type" : "date",
  65. "format" : "strict_date_optional_time||epoch_millis"
  66. },
  67. "timestamp" : {
  68. "type" : "date",
  69. "format" : "strict_date_optional_time||epoch_millis"
  70. },
  71. "transportStatus" : {
  72. "type" : "string",
  73. "index" : "not_analyzed"
  74. },
  75. "waybillNo" : {
  76. "type" : "string",
  77. "index" : "not_analyzed"
  78. }
  79. }
  80. }
  81. }
  82. }'
  83. 删除模板
  84. curl -XDELETE localhost:9200/_template/template_1
  85. 设置threadpool:
  86. threadpool:
  87. bulk:
  88. type: fixed
  89. size: 60
  90. queue_size: 1000

ES慢日志设置:

  1. index.search.slowlog.level: TRACE
  2. index.search.slowlog.threshold.query.warn: 10s
  3. index.search.slowlog.threshold.query.info: 5s
  4. index.search.slowlog.threshold.query.debug: 2s
  5. index.search.slowlog.threshold.query.trace: 500ms
  6. index.search.slowlog.threshold.fetch.warn: 1s
  7. index.search.slowlog.threshold.fetch.info: 800ms
  8. index.search.slowlog.threshold.fetch.debug:500ms
  9. index.search.slowlog.threshold.fetch.trace: 200ms

zen设置:

  1. discovery.zen.ping.timeout: 100s
  2. discovery.zen.ping.multicast.enabled: false
  3. 设置是否打开多播发现节点,默认是true
文档更新时间: 2021-05-19 11:24   作者:张尚