docker pull elasticsearch:7.14.0

mkdir -p /usr/local/elasticsearch/config
chmod 777 -R /usr/local/elasticsearch/
echo "cluster.name: "docker-cluster" >> /usr/local/elasticsearch/config/elasticesearch.yml
echo "network.host: 0.0.0.0" >> /usr/local/elasticsearch/config/elasticesearch.yml
echo "discovery.zen.minimum_master_nodes: 1" >> /usr/local/elasticsearch/config/elasticesearch.yml
echo "discovery.type: single-node" >> /usr/local/elasticsearch/config/elasticesearch.yml
docker run --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e ES_JAVA_OPTS="-Xms64m -Xmx128m" -v /usr/local/elasticsearch/config/elasticesearch.yml:/usr/local/elasticsearch/config/elasticesearch.yml -d elasticsearch:7.14.0
http://10.1.1.197:9200

版本:kibana:7.14.0 需要和ES版本对应
Kibana 是一个免费且开放的用户界面,能够让您对 Elasticsearch 数据进行可视化。
docker pull kibana:7.14.0

docker run -d --name kibana714 -e ELASTICSEARCH_HOSTS="http://10.1.1.74:9200" -p 5601:5601 kibana:7.14.0
访问UI界面:http://10.1.1.197:5601/

#创建目录
mkdir -p /home/es-kibana/config
mkdir -p /home/es-kibana/data
mkdir -p /home/es-kibana/plugins
#给挂载目录授权
chmod 777 -R /home/es-kibana/config
chmod 777 /home/es-kibana/es-data/data
chmod 777 /home/es-kibana/es-data/logs
chmod 777 /home/es-kibana/es-data/plugins
cluster.name: "docker-cluster"
network.host: 0.0.0.0discovery.zen.minimum_master_nodes: 1
discovery.type: single-node

- ## JVM configuration
-
- ################################################################
- ## IMPORTANT: JVM heap size
- ################################################################
- ##
- ## You should always set the min and max JVM heap
- ## size to the same value. For example, to set
- ## the heap to 4 GB, set:
- ##
- ## -Xms4g
- ## -Xmx4g
- ##
- ## See https://www.elastic.co/guide/en/elasticsearch/reference/current/heap-size.html
- ## for more information
- ##
- ################################################################
-
- # Xms represents the initial size of total heap space
- # Xmx represents the maximum size of total heap space
-
- -Xms1g
- -Xmx1g
- -XX:+IgnoreUnrecognizedVMOptions
- ################################################################
- ## Expert settings
- ################################################################
- ##
- ## All settings below this section are considered
- ## expert settings. Don't tamper with them unless
- ## you understand what you are doing
- ##
- ################################################################
-
- ## GC configuration
- -XX:+UseConcMarkSweepGC
- -XX:CMSInitiatingOccupancyFraction=75
- -XX:+UseCMSInitiatingOccupancyOnly
-
- ## G1GC Configuration
- # NOTE: G1GC is only supported on JDK version 10 or later.
- # To use G1GC uncomment the lines below.
- # 10-:-XX:-UseConcMarkSweepGC
- # 10-:-XX:-UseCMSInitiatingOccupancyOnly
- # 10-:-XX:+UseG1GC
- # 10-:-XX:InitiatingHeapOccupancyPercent=75
-
- ## optimizations
-
- # pre-touch memory pages used by the JVM during initialization
- -XX:+AlwaysPreTouch
-
- ## basic
-
- # explicitly set the stack size
- -Xss1m
-
- # set to headless, just in case
- -Djava.awt.headless=true
-
- # ensure UTF-8 encoding by default (e.g. filenames)
- -Dfile.encoding=GBK
-
- # use our provided JNA always versus the system one
- -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
主要是这3个配置项

- version: '3'
-
- services:
- elasticsearch:
- image: elasticsearch:7.14.0
- container_name: es7-14
- restart: unless-stopped
- volumes:
- - ./es-data/data:/usr/share/elasticsearch/data
- - ./es-data/logs:/usr/share/elasticsearch/logs
- # 挂载分词器的目录
- #- ./es-data/plugins:/usr/share/elasticsearch/plugins
- - ./config/jvm.options:/usr/share/elasticsearch/config/jvm.options
- - ./config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- ports:
- - "9100:9100"
- - "9200:9200"
-
- networks:
- - es
- kibana:
- image: kibana:7.14.0
- container_name: kibana7-14
- ports:
- - "5601:5601"
- environment:
- - "ELASTICSEARCH_HOSTS=http://10.1.1.197:9200"
- depends_on:
- - elasticsearch
- networks:
- - es
-
- networks:
- es:
- driver: bridge
3、#自我检测自己写的有没有语法上的问题
docker-compose config -q
docker-compose up -d
docker-compose down

重启
docker-compose restart 容器id
docker logs 容器id
问题:docker以挂载配置文件启动elasticsearch的时候会报如下错误:java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes...
看错误我们会以为是es容器里的/usr/share/elasticsearch/data/nodes文件夹目录没有读写权限,其实给提示误导了,实际是挂载的目录没有读写权限。比如我们宿主主机的配置目录为:/home/es-kibana/es-data/data,那么我们需要赋予它读写权限:
解决:授权挂载目录的权限
chmod 777 /home/es-kibana/es-data/data
解决办法:在jvm. options文件中加上-XX:+IgnoreUnrecognizedVMOptions
