1.在/data/es-cluster/目录下(自定义的目录),创建两个目录,为node01和node02
2.在node01目录下,创建两个文件,elasticsearch.yml和jvm.options
elasticsearch.yml如下
#cluster.name集群名称
cluster.name: es-cluster
node.name: node01
#由于node01的master设置为true,故有机会成为master
node.master: true
node.data: true
network.host: 191.168.56.1
#不同的节点,需设置不同的端口号
http.port: 9201
discovery.zen.ping.unicast.hosts: ["191.168.56.1"]
#这个是最小支持成为master的节点数,官方定义为(n/2)+1,如有三个节点就是2
discovery.zen.minimum_master_nodes: 1
http.cors.enabled: true
http.cors.allow-origin: "*"
注意:
jvm.options如下(由于是自己实验使用,故-Xms128m设置为128m)
## 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
-Xms128m
-Xmx128m
################################################################
## 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=UTF-8
# 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
node02目录下也需创建这两个文件(jvm.options无需修改),只是对于elasticsearch.yml,需做改动
#cluster.name需和node01的保持一致
cluster.name: es-cluster
node.name: node02
#由于node01作为了master,故对于node02来说,这里得设置为false
node.master: false
node.data: true
network.host: 191.168.56.1
#不同的节点,需设置不同的端口号
http.port: 9202
discovery.zen.ping.unicast.hosts: ["191.168.56.1"]
#这个是最小支持成为master的节点数,官方定义为(n/2)+1,如有三个节点就是2
discovery.zen.minimum_master_nodes: 1
http.cors.enabled: true
http.cors.allow-origin: "*"
3.创建容器
以node02为例
sudo docker create --name es-node02 --net host -v /data/es-cluster/node02/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /data/es-cluster/node02/jvm.options:/usr/share/elasticsearch/config/jvm.options -v /data/es-cluster/node02/data:/usr/share/elasticsearch/data elasticsearch:6.5.4
原因是我们所在的 /data/es-cluster/node02/data是root才有权限修改的目录
所以修改该目录下的权限为777,并再次启动node02
node02节点启动成功了
注意:若启动后,报如下的错
Native controller process has stopped - no new native processes can be started
解决方法:sudo vim /etc/sysctl.conf文件,在最后一行添加 vm.max_map_count=655360