Docker安装Elasticsearch集群,并添加ik分词器和pinyin分词器

Docker安装Elasticsearch集群,并添加ik分词器和pinyin分词器

环境准备:需要Linux环境并安装docker

1. 拉取镜像

# elasticsearch版本6.5.4
docker pull elasticsearch:6.5.4

Docker安装Elasticsearch集群,并添加ik分词器和pinyin分词器_第1张图片

查看镜像

docker images

Docker安装Elasticsearch集群,并添加ik分词器和pinyin分词器_第2张图片

2. 创建容器

创建配置文件

# 新建es-cluster文件夹
mkdir es-cluster
cd es-cluster
# 新建两个节点的文件夹
mkdir node01
mkdir node02

# 在 node01中创建配置文件elasticsearch.yml、jvm.options文件,添加以下内容
# node01中elasticsearch.yml文件的配置:
cluster.name: es-cluster
node.name: node01
node.master: true
node.data: true
network.host: 192.168.241.130
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.168.241.130"]
discovery.zen.minimum_master_nodes: 1
http.cors.enabled: true
http.cors.allow-origin: "*"

# node02中elasticsearch.yml文件的配置:
cluster.name: es-cluster
node.name: node02
node.master: true
node.data: true
network.host: 192.168.241.130
http.port: 9201
discovery.zen.ping.unicast.hosts: ["192.168.241.130"]
discovery.zen.minimum_master_nodes: 1
http.cors.enabled: true
http.cors.allow-origin: "*"

# node01和node02中jvm.options文件的配置:
-Xms256m
-Xmx256m
-XX:+UseConcMarkSweepGC
-XX:CMSInitiatingOccupancyFraction=75
-XX:+UseCMSInitiatingOccupancyOnly
-XX:+AlwaysPreTouch
-Xss1m
-Djava.awt.headless=true
-Dfile.encoding=UTF-8
-Djna.nosys=true
-XX:-OmitStackTraceInFastThrow
-Dio.netty.noUnsafe=true
-Dio.netty.noKeySetOptimization=true
-Dio.netty.recycler.maxCapacityPerThread=0
-Dlog4j.shutdownHookEnabled=false
-Dlog4j2.disable.jmx=true
-Djava.io.tmpdir=${ES_TMPDIR}
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=data
-XX:ErrorFile=logs/hs_err_pid%p.log
8:-XX:+PrintGCDetails
8:-XX:+PrintGCDateStamps
8:-XX:+PrintTenuringDistribution
8:-XX:+PrintGCApplicationStoppedTime
8:-Xloggc:logs/gc.log
8:-XX:+UseGCLogFileRotation
9-:-Xlog:gc*,gc+age=trace,safepoint:file=logs/gc.log:utctime,pid,tags:filecount=32,filesize=64m
9-:-Djava.locale.providers=COMPAT
10-:-XX:UseAVX=2

下载ik分词器和pinyin分词器插件

ik分词器插件安装包下载:

https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.5.4/elasticsearch-analysis-ik-6.5.4.zip

pinyin分词器插件安装包下载:

https://github.com/medcl/elasticsearch-analysis-pinyin/releases/download/v6.5.4/elasticsearch-analysis-pinyin-6.5.4.zip

在es-cluster文件下新建两个文件夹

mkdir ik
mkdir pinyin

# 将ik插件解压到ik目录下
tar -zxvf elasticsearch-analysis-ik-6.5.4.zip ik/

# 将pinyin插件解压到pinyin目录下
tar -zxvf elasticsearch-analysis-pinyin-6.5.4 pinyin/

创建容器

# 创建es节点01
docker create --name es-node01 --net host -v /es-cluster/node01/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /es-cluster/node01/jvm.options:/usr/share/elasticsearch/config/jvm.options -v /es-cluster/ik:/usr/share/elasticsearch/plugins/ik -v /es-cluster/pinyin:/usr/share/elasticsearch/plugins/pinyin -v /es-cluster/node01/data:/usr/share/elasticsearch/data elasticsearch:6.5.4

# 创建es节点02
docker create --name es-node02 --net host -v /es-cluster/node02/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /es-cluster/node02/jvm.options:/usr/share/elasticsearch/config/jvm.options -v /es-cluster/ik:/usr/share/elasticsearch/plugins/ik -v /es-cluster/pinyin:/usr/share/elasticsearch/plugins/pinyin -v /es-cluster/node02/data:/usr/share/elasticsearch/data elasticsearch:6.5.4

参数:
–name:容器名字
–net 网络类型
-v 目录挂载
elasticsearch:6.5.4 es的镜像

特别注意 -v 目录挂载,需要映射到自己创建的目录文件

3. 启动容器

# 启动
docker start es-node01 es-node02
# 查看日志
docker logs -f es-node01

Docker安装Elasticsearch集群,并添加ik分词器和pinyin分词器_第3张图片
可以看到,已经加载ik分词和pinyin分词插件,启动成功!

你可能感兴趣的:(docker,elasticsearch,容器)