一、拉取镜像
docker pull elasticsearch
二、启动镜像
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/
{"name" : "TPL4Zd3","cluster_name" : "elasticsearch","cluster_uuid" : "4ylBfAE_SVmuIZQb3_v09w","version" : {"number" : "5.6.12","build_hash" : "cfe3d9f","build_date" : "2018-09-10T20:12:43.732Z","build_snapshot" : false,"lucene_version" : "6.6.1"},"tagline" : "You Know, for Search"}
说明 elasticsearch 安装成功
四、docker-compose 启动
version: '3.1'services:my_es:image: elasticsearchports:- 9200:9200- 9300:9300environment:ES_JAVA_OPTS: "-Xms256m -Xmx256m"
五、安装elasticsearch-head插件
version: '3.1'services:my_es:image: elasticsearchports:- 9200:9200- 9300:9300volumes:- D:/resource-docker/elasticsearch/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.ymlenvironment:ES_JAVA_OPTS: "-Xms256m -Xmx256m"my_es_head:image: mobz/elasticsearch-head:5-alpineports:- 9100:9100
elasticsearch.yml
主要是解决跨域的问题,不然elasticsearch-head访问不到elasticsearch
http.host: 0.0.0.0# Uncomment the following lines for a production cluster deployment#transport.host: 0.0.0.0#discovery.zen.minimum_master_nodes: 1http.cors.enabled: truehttp.cors.allow-origin: "*"
完整的配置问文件
# ======================== Elasticsearch Configuration =========================## NOTE: Elasticsearch comes with reasonable defaults for most settings.# Before you set out to tweak and tune the configuration, make sure you# understand what are you trying to accomplish and the consequences.## The primary way of configuring a node is via this file. This template lists# the most important settings you may want to configure for a production cluster.## Please consult the documentation for further information on configuration options:# https://www.elastic.co/guide/en/elasticsearch/reference/index.html## ---------------------------------- Cluster -----------------------------------## Use a descriptive name for your cluster:#cluster.name: elastic## ------------------------------------ Node ------------------------------------## Use a descriptive name for the node:#node.name: node-1## Add custom attributes to the node:##node.attr.rack: r1## ----------------------------------- Paths ------------------------------------## Path to directory where to store the data (separate multiple locations by comma):##path.data: /path/to/data## Path to log files:##path.logs: /path/to/logs## ----------------------------------- Memory -----------------------------------## Lock the memory on startup:##bootstrap.memory_lock: true## Make sure that the heap size is set to about half the memory available# on the system and that the owner of the process is allowed to use this# limit.## Elasticsearch performs poorly when the system is swapping the memory.## ---------------------------------- Network -----------------------------------## Set the bind address to a specific IP (IPv4 or IPv6):#network.host: 0.0.0.0## Set a custom port for HTTP:#http.port: 9200## For more information, consult the network module documentation.## --------------------------------- Discovery ----------------------------------## Pass an initial list of hosts to perform discovery when new node is started:# The default list of hosts is ["127.0.0.1", "[::1]"]##discovery.zen.ping.unicast.hosts: ["host1", "host2"]## Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):##discovery.zen.minimum_master_nodes:## For more information, consult the zen discovery module documentation.## ---------------------------------- Gateway -----------------------------------## Block initial recovery after a full cluster restart until N nodes are started:##gateway.recover_after_nodes: 3## For more information, consult the gateway module documentation.## ---------------------------------- Various -----------------------------------## Require explicit names when deleting indices:##action.destructive_requires_name: true————————————————# Uncomment the following lines for a production cluster deployment#transport.host: 0.0.0.0#discovery.zen.minimum_master_nodes: 1http.cors.enabled: truehttp.cors.allow-origin: "*"node.master: truenode.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:
