Docker中部署ElasticSearch集群

10 篇文章 1 订阅

搭建Elasticsearch

1.拉取境像

	docker pull elasticsearch:6.5.4

2.修改单个进程中的最大线程数

	vim /etc/sysctl.conf
	vm.max_map_count=262144

3.令修改的配置立即生效

	/sbin/sysctl -p

4.创建文件夹,并创建jvm.options文件,并将jvm.options文件复制到其他文件夹中

	mkdir /docker/es-cluster/node01 -p
	mkdir /docker/es-cluster/node02 -p
	mkdir /docker/es-cluster/node03 -p
			
	vim /docker/es-cluster/node01/jvm.options


		-Xms128m
		-Xmx128m
		-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
		8:-XX:NumberOfGCLogFiles=32
		8:-XX:GCLogFileSize=64m
		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
		
		
	cp /docker/es-cluster/node01/jvm.options /docker/es-cluster/node02
	cp /docker/es-cluster/node01/jvm.options /docker/es-cluster/node03

5.在node01目录下,创建elasticsearch.yml文件,并输入如下内容:

	cd /docker/es-cluster/node01
	vim elasticsearch.yml
		
		
	cluster.name: es-cluster
	node.name: node01
	node.master: true
	node.data: true
	network.host: 192.168.168.130
	http.port: 9200
	discovery.zen.ping.unicast.hosts: ["192.168.168.130"]
	discovery.zen.minimum_master_nodes: 2
	http.cors.enabled: true
	http.cors.allow-origin: "*"

6.在node02目录下,创建elasticsearch.yml文件,并输入如下内容:

	cluster.name: es-cluster
	node.name: node02
	node.master: true
	node.data: true
	network.host: 192.168.168.130
	http.port: 9201
	discovery.zen.ping.unicast.hosts: ["192.168.168.130"]
	discovery.zen.minimum_master_nodes: 2
	http.cors.enabled: true
	http.cors.allow-origin: "*"

7.在node03目录下,创建elasticsearch.yml文件,并输入如下内容:

	cluster.name: es-cluster
	node.name: node03
	node.master: true
	node.data: true
	network.host: 192.168.168.130
	http.port: 9202
	discovery.zen.ping.unicast.hosts: ["192.168.168.130"]
	discovery.zen.minimum_master_nodes: 2
	http.cors.enabled: true
	http.cors.allow-origin: "*"

8.创建容器

	docker create --restart=always --name es-cluster-node01 --net host -v /docker/es-cluster/node01/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /docker/es-cluster/node01/jvm.options:/usr/share/elasticsearch/config/jvm.options -v es-node01-data:/usr/share/elasticsearch/data elasticsearch:6.5.4
	
	docker create --restart=always --name es-cluster-node02 --net host -v /docker/es-cluster/node02/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /docker/es-cluster/node02/jvm.options:/usr/share/elasticsearch/config/jvm.options -v es-node02-data:/usr/share/elasticsearch/data elasticsearch:6.5.4
	
	docker create --restart=always --name es-cluster-node03 --net host -v /docker/es-cluster/node03/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /docker/es-cluster/node03/jvm.options:/usr/share/elasticsearch/config/jvm.options -v es-node03-data:/usr/share/elasticsearch/data elasticsearch:6.5.4

9.启动容器

	docker start es-cluster-node01 es-cluster-node02 es-cluster-node03

10.或单个启动并查看日志

	docker start es-cluster-node01 && docker logs -f es-cluster-node01
	docker start es-cluster-node02 && docker logs -f es-cluster-node02
	docker start es-cluster-node03 && docker logs -f es-cluster-node03

安装IK分词器

es-cluster-node01 容器安装ik:
1.进入容器:

	docker exec -it es-cluster-node01 /bin/bash

2.创建ik目录:

	mkdir /usr/share/elasticsearch/plugins/ik

3.退出容器:

	exit

4.上传ik分词器并将分词器copy到容器中:

	docker cp /docker/es-cluster/elasticsearch-analysis-ik-6.5.4.zip es-cluster-node01:/usr/share/elasticsearch/plugins/ik/

5.重新进入容器

	docker exec -it es-cluster-node01 /bin/bash

6.进入ik目录

	cd /usr/share/elasticsearch/plugins/ik

7.解压并删除压缩包

	unzip elasticsearch-analysis-ik-6.5.4.zip 
	rm -rf elasticsearch-analysis-ik-6.5.4.zip 

8.退出容器并重启容器

	exit
	docker restart es-cluster-node01

es-cluster-node02 容器安装ik:
1.进入容器:

	docker exec -it es-cluster-node02 /bin/bash

2.创建ik目录:

	mkdir /usr/share/elasticsearch/plugins/ik

3.退出容器:

	exit

4.上传ik分词器并将分词器copy到容器中:

	docker cp /docker/es-cluster/elasticsearch-analysis-ik-6.5.4.zip es-cluster-node02:/usr/share/elasticsearch/plugins/ik/

5.重新进入容器

	docker exec -it es-cluster-node02 /bin/bash

6.进入ik目录

	cd /usr/share/elasticsearch/plugins/ik

7.解压并删除压缩包

	unzip elasticsearch-analysis-ik-6.5.4.zip 
	rm -rf elasticsearch-analysis-ik-6.5.4.zip 

8.退出容器并重启容器

	exit
	docker restart es-cluster-node02

es-cluster-node03 容器安装ik:
1,进入容器:

	docker exec -it es-cluster-node03 /bin/bash

2,创建ik目录:

	mkdir /usr/share/elasticsearch/plugins/ik

3,退出容器:

	exit

4.上传ik分词器并将分词器copy到容器中:

	docker cp /docker/es-cluster/elasticsearch-analysis-ik-6.5.4.zip es-cluster-node03:/usr/share/elasticsearch/plugins/ik/

5, 重新进入容器

	docker exec -it es-cluster-node03 /bin/bash

6,进入ik目录

	cd /usr/share/elasticsearch/plugins/ik

7,解压并删除压缩包

	unzip elasticsearch-analysis-ik-6.5.4.zip 
	rm -rf elasticsearch-analysis-ik-6.5.4.zip

8,退出容器并重启容器

	exit
	docker restart es-cluster-node03
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值