美文网首页
Docker compose安装Elasticsearch

Docker compose安装Elasticsearch

作者: gurlan | 来源:发表于2020-02-21 14:00 被阅读0次

1.编写docker-compose文件

version: '3'
services:
  elasticsearch:
    image:  elasticsearch:6.4.3
    container_name: elasticsearch
    restart: always
    volumes:
      - /data/projects/elasticsearch/data:/usr/share/elasticsearch/data:rw
      - /data/projects/elasticsearch/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
      - /data/projects/elasticsearch/conf/jvm.options:/usr/share/elasticsearch/config/jvm.options
      - /data/projects/elasticsearch/logs:/user/share/elasticsearch/logs:rw
    ports:
        - "9200:9200"
        - "9300:9300"
    environment:
        - discovery.type=single-node
  es-head:
    image: tobias74/elasticsearch-head:6
    container_name: es-head
    restart: always
    ports:
      - "9100:9100"

2 编写elasticsearch.yml文件

bootstrap.memory_lock: false
cluster.name: "es-server"
node.name: node-1
node.master: true
node.data: true
network.host: 0.0.0.0
http.port: 9200
path.logs: /usr/share/elasticsearch/logs
http.cors.enabled: true
http.cors.allow-origin: "*"
xpack.security.audit.enabled: true

3 编写jvm配置文件

-Djna.nosys=true

# turn off a JDK optimization that throws away stack traces for common
# exceptions because stack traces are important for debugging
-XX:-OmitStackTraceInFastThrow

# flags to configure Netty
-Dio.netty.noUnsafe=true
-Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0

# log4j 2
-Dlog4j.shutdownHookEnabled=false
-Dlog4j2.disable.jmx=true

-Djava.io.tmpdir=${ES_TMPDIR}

## heap dumps

# generate a heap dump when an allocation from the Java heap fails
# heap dumps are created in the working directory of the JVM
-XX:+HeapDumpOnOutOfMemoryError

# specify an alternative path for heap dumps; ensure the directory exists and
# has sufficient space
-XX:HeapDumpPath=data

# specify an alternative path for JVM fatal error logs
-XX:ErrorFile=logs/hs_err_pid%p.log

## JDK 8 GC logging

8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc.log
8:-XX:+UseGCLogFileRotation
8:-XX:NumberOfGCLogFiles=32
8:-XX:GCLogFileSize=64m

# JDK 9+ GC logging
9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m
# due to internationalization enhancements in JDK 9 Elasticsearch need to set the provider to COMPAT otherwise
# time/date parsing will break in an incompatible way for some date patterns and locals
9-:-Djava.locale.providers=COMPAT

# temporary workaround for C2 bug with JDK 10 on hardware with AVX-512
10-:-XX:UseAVX=2

4 启动

docker-compose up
image.png

如图就是安装成功

5 相关问题整理

** (1) 目录无限问题**

image

** 相关目录上执行 chown 1000:1000 data**

(2) 启动失败问题

image

** 对应机器上执行 **sudo sysctl -w vm.max_map_count=262144

相关文章

网友评论

      本文标题:Docker compose安装Elasticsearch

      本文链接:https://www.haomeiwen.com/subject/tyscqhtx.html