一、Docker安装ES7.14.0
1、下载镜像
docker pull elasticsearch:7.14.0
2、docker安装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
- -e "cluster.name=es-docker-cluster":设置集群名称
- -e "http.host=0.0.0.0":监听的地址,可以外网访问
- -e "ES_JAVA_OPTS=-Xms64m -Xmx128m":内存大小
- -e "discovery.type=single-node":非集群模式
- -v es-data:/usr/share/elasticsearch/data:目录映射,绑定elasticsearch的数据目录
- -v es-logs:/usr/share/elasticsearch/logs:目录映射,绑定elasticsearch的日志目录
- -v es-plugins:/usr/share/elasticsearch/plugins:目录映射,绑定elasticsearch的插件目录
- -p 9200:9200:端口映射配置
3、访问
http://10.1.1.197:9200
二、Docker安装kibana:7.14.0
1、下载镜像
版本:kibana:7.14.0 需要和ES版本对应
Kibana 是一个免费且开放的用户界面,能够让您对 Elasticsearch 数据进行可视化。
docker pull kibana:7.14.0
2、安装kibana
docker run -d --name kibana714 -e ELASTICSEARCH_HOSTS="http://10.1.1.74:9200" -p 5601:5601 kibana:7.14.0
- -e ELASTICSEARCH_HOSTS ES地址:注意不要使用127.0.0.1
访问UI界面:http://10.1.1.197:5601/
三、Docker-compose安装ES和kibana
1、创建配置文件目录和文件
#创建目录
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
1.1、配置文件elasticesearch.yml
cluster.name: "docker-cluster"
network.host: 0.0.0.0discovery.zen.minimum_master_nodes: 1
discovery.type: single-node
1.2、配置文件jvm.options
## 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个配置项
2、#创建docker-compose.yml文件(重要)
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
4、#启动和停止
docker-compose up -d
docker-compose down
重启
docker-compose restart 容器id
docker-compose安装时遇到问题:
docker logs 容器id
1、docker启动es报错java.nio.file.AccessDeniedException: /usr/share/elasticsearch/data/nodes...
问题: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
2、docker启动es出现此异常Unrecognized VM option 'UseConcMarkSweepGC'
解决办法:在jvm. options文件中加上-XX:+IgnoreUnrecognizedVMOptions