一、拉取镜像

  1. docker pull elasticsearch

二、启动镜像

  1. docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 --name my_es elasticsearch

说明:

  • ES_JAVA_OPTS:指定 elasticsearch 的运行内存大小

    三、查看es信息

    浏览器访问 http://127.0.0.1:9200/
  1. {
  2. "name" : "TPL4Zd3",
  3. "cluster_name" : "elasticsearch",
  4. "cluster_uuid" : "4ylBfAE_SVmuIZQb3_v09w",
  5. "version" : {
  6. "number" : "5.6.12",
  7. "build_hash" : "cfe3d9f",
  8. "build_date" : "2018-09-10T20:12:43.732Z",
  9. "build_snapshot" : false,
  10. "lucene_version" : "6.6.1"
  11. },
  12. "tagline" : "You Know, for Search"
  13. }

说明 elasticsearch 安装成功

四、docker-compose 启动

  1. version: '3.1'
  2. services:
  3. my_es:
  4. image: elasticsearch
  5. ports:
  6. - 9200:9200
  7. - 9300:9300
  8. environment:
  9. ES_JAVA_OPTS: "-Xms256m -Xmx256m"

五、安装elasticsearch-head插件

  1. version: '3.1'
  2. services:
  3. my_es:
  4. image: elasticsearch
  5. ports:
  6. - 9200:9200
  7. - 9300:9300
  8. volumes:
  9. - D:/resource-docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
  10. environment:
  11. ES_JAVA_OPTS: "-Xms256m -Xmx256m"
  12. my_es_head:
  13. image: mobz/elasticsearch-head:5-alpine
  14. ports:
  15. - 9100:9100

elasticsearch.yml
主要是解决跨域的问题,不然elasticsearch-head访问不到elasticsearch

  1. http.host: 0.0.0.0
  2. # Uncomment the following lines for a production cluster deployment
  3. #transport.host: 0.0.0.0
  4. #discovery.zen.minimum_master_nodes: 1
  5. http.cors.enabled: true
  6. http.cors.allow-origin: "*"

完整的配置问文件

  1. # ======================== Elasticsearch Configuration =========================
  2. #
  3. # NOTE: Elasticsearch comes with reasonable defaults for most settings.
  4. # Before you set out to tweak and tune the configuration, make sure you
  5. # understand what are you trying to accomplish and the consequences.
  6. #
  7. # The primary way of configuring a node is via this file. This template lists
  8. # the most important settings you may want to configure for a production cluster.
  9. #
  10. # Please consult the documentation for further information on configuration options:
  11. # https://www.elastic.co/guide/en/elasticsearch/reference/index.html
  12. #
  13. # ---------------------------------- Cluster -----------------------------------
  14. #
  15. # Use a descriptive name for your cluster:
  16. #
  17. cluster.name: elastic
  18. #
  19. # ------------------------------------ Node ------------------------------------
  20. #
  21. # Use a descriptive name for the node:
  22. #
  23. node.name: node-1
  24. #
  25. # Add custom attributes to the node:
  26. #
  27. #node.attr.rack: r1
  28. #
  29. # ----------------------------------- Paths ------------------------------------
  30. #
  31. # Path to directory where to store the data (separate multiple locations by comma):
  32. #
  33. #path.data: /path/to/data
  34. #
  35. # Path to log files:
  36. #
  37. #path.logs: /path/to/logs
  38. #
  39. # ----------------------------------- Memory -----------------------------------
  40. #
  41. # Lock the memory on startup:
  42. #
  43. #bootstrap.memory_lock: true
  44. #
  45. # Make sure that the heap size is set to about half the memory available
  46. # on the system and that the owner of the process is allowed to use this
  47. # limit.
  48. #
  49. # Elasticsearch performs poorly when the system is swapping the memory.
  50. #
  51. # ---------------------------------- Network -----------------------------------
  52. #
  53. # Set the bind address to a specific IP (IPv4 or IPv6):
  54. #
  55. network.host: 0.0.0.0
  56. #
  57. # Set a custom port for HTTP:
  58. #
  59. http.port: 9200
  60. #
  61. # For more information, consult the network module documentation.
  62. #
  63. # --------------------------------- Discovery ----------------------------------
  64. #
  65. # Pass an initial list of hosts to perform discovery when new node is started:
  66. # The default list of hosts is ["127.0.0.1", "[::1]"]
  67. #
  68. #discovery.zen.ping.unicast.hosts: ["host1", "host2"]
  69. #
  70. # Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
  71. #
  72. #discovery.zen.minimum_master_nodes:
  73. #
  74. # For more information, consult the zen discovery module documentation.
  75. #
  76. # ---------------------------------- Gateway -----------------------------------
  77. #
  78. # Block initial recovery after a full cluster restart until N nodes are started:
  79. #
  80. #gateway.recover_after_nodes: 3
  81. #
  82. # For more information, consult the gateway module documentation.
  83. #
  84. # ---------------------------------- Various -----------------------------------
  85. #
  86. # Require explicit names when deleting indices:
  87. #
  88. #action.destructive_requires_name: true
  89. ————————————————
  90. # Uncomment the following lines for a production cluster deployment
  91. #transport.host: 0.0.0.0
  92. #discovery.zen.minimum_master_nodes: 1
  93. http.cors.enabled: true
  94. http.cors.allow-origin: "*"
  95. node.master: true
  96. node.data: true

六、安装kibana

version: '3.1'

services:
  my_es:
    image: elasticsearch
    ports:
      - 9200:9200
      - 9300:9300
    volumes:
      - D:/resource-docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - D:/resource-docker/elasticsearch/plugins:/usr/share/elasticsearch/plugins
    environment:
      ES_JAVA_OPTS: "-Xms256m -Xmx256m"
    networks:
      - esnet
  my_es_head:
    image: mobz/elasticsearch-head:5-alpine
    ports:
      - 9100:9100
  my_kibana:
    image: kibana
    ports:
      - 5601:5601
    environment:
      - ELASTICSEARCH_URL=http://my_es:9200
    networks:
      - esnet

networks:
   esnet: