docker安装elasticsearch

一. 搜索elasticsearch镜像

docker search elasticsearch

二. 拉取elasticsearch镜像

docker pull elasticsearch:6.6.0

三. 编写docker-compose.yaml文件

version: '3'
services:
  elasticsearch:
    restart: always
    image: elasticsearch:6.6.0
    deploy:
      replicas: 1
      update_config:
        parallelism: 2
        delay: 10s
      restart_policy:
        condition: on-failure
        delay: 5s
        max_attempts: 3
        window: 120s
      resources:
        limits:
          cpus: '0.5'
          memory: 1024M
        reservations:
          cpus: '1'
          memory: 2408M
    volumes:
      - /opt/data/elasticsearch:/opt/data/elasticsearch
      - /opt/logs/elasticsearch:/opt/logs/elasticsearch
    ports:
      - "9200:9200"
      - "9300:9300"
    container_name: "elasticsearch"
    networks:
      - back-up
networks:
  back-up:
    driver: bridge

四. docker-compose 启动

docker-compose -f docker-compose.yaml up -d

五. 进入docker容器,修改elasticsearch.yml文件

docker exec -it elasticsearch /bin/bash

elasticsearch.yml文件内容

# ======================== 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: elasticsearch
#
# ------------------------------------ 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: /opt/data/elasticsearch

#
# Path to log files:
#
path.logs: /opt/logs/elasticsearch

http.cors.enabled: true
http.cors.allow-origin: "*"
#
# ----------------------------------- 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

六. 重启docker容器

docker restart elasticsearch

七. 测试elasticsearch启动情况

访问http://192.168.2.225:9200/

出现内容:

{
  "name" : "node-1",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "4wlqfphKQuG4lpqHqW7BTg",
  "version" : {
    "number" : "6.6.0",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "a9861f4",
    "build_date" : "2019-01-24T11:27:09.439740Z",
    "build_snapshot" : false,
    "lucene_version" : "7.6.0",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

八. 安装ElasticSearch-head插件

拉取docker镜像

 docker pull mobz/elasticsearch-head:5

创建容器

docker run -it -d --name elasticsearch-head -v /opt/elasticsearch-head/:/opt/elasticsearch-head/ --net=bridge --restart=always -p 9100:9100 mobz/elasticsearch-head:5 /bin/bash

进入容器内部:

/usr/src/app

修改Gruntfile.js文件

connect: {
			server: {
				options: {
					port: 9100,
					base: '.',
					keepalive: true,
					hostname:'*'
				}
			}
		}

启动服务:

grunt server &

 

 

注意:

elasticsearch启动时遇到的错误 max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

问题翻译过来就是:elasticsearch用户拥有的内存权限太小,至少需要262144;

 

解决:

切换到root用户

执行命令:

sysctl -w vm.max_map_count=262144

查看结果:

sysctl -a|grep vm.max_map_count

显示:

vm.max_map_count = 262144

上述方法修改之后,如果重启虚拟机将失效,所以:

解决办法:

在   /etc/sysctl.conf文件最后添加一行

vm.max_map_count=262144

即可永久修改

你可能感兴趣的:(docker安装elasticsearch)