基于Docker搭建Elasticsearch集群

一、环境搭建

SpringBoot整合es时使用的集群环境,如果不搭建集群使用SpringBoot整合时会报错:None of the configured nodes are available

我们只需要在一台虚拟机上面搭建多个docker容器即可。
建立相应的文件夹

cd /usr/local
## 配置文件,用于挂载
mkdir -p es/config
cd es
mkdir data1
mkdir data2
mkdir data3
firewall-cmd --add-port=9300/tcp
firewall-cmd --add-port=9301/tcp
mkdir  plugins1
mkdir  plugins2

然后在/es/config目录下分别放入es1.yml、es2.yml
vi es1.yml

# 集群名称
cluster.name: elasticsearch-cluster
# 节点名称
node.name: es-node1
# 设置绑定的ip地址,可以使ipv4或者ipv6
network.bind_host: 0.0.0.0
# 设置其他节点和该节点交互的ip地址
network.publish_host: 192.168.112.150
# 设置对外服务的http端口,默认为9200
http.port: 9200
# 设置节点之间的tcp端口,默认是9300
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true 
node.data: true 
discovery.zen.ping.unicast.hosts: ["192.168.112.150:9300","192.168.112.150:9301"]
discovery.zen.minimum_master_nodes: 1

vi es2.yml

cluster.name: elasticsearch-cluster
node.name: es-node2
network.bind_host: 0.0.0.0
network.publish_host: 192.168.112.150
http.port: 9201
transport.tcp.port: 9301
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true 
node.data: true  
discovery.zen.ping.unicast.hosts: ["192.168.112.150:9300","192.168.112.150:9301"]
discovery.zen.minimum_master_nodes: 1

调高JVM线程数限制数量
1、修改sysctl.conf文件

vim /etc/sysctl.conf

2、在最下面加入内容

vm.max_map_count=262144 

3、启用配置

sysctl -p

启动容器:
es01:

docker run -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -d  -p 9200:9200 -p 9300:9300 -p 5601:5601 -v /usr/local/es/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml  -v /usr/local/es/plugins1:/usr/share/elasticsearch/plugins    -v /usr/local/es/data1:/usr/share/elasticsearch/data --name ES01 elasticsearch

es02:

docker run -e ES_JAVA_OPTS="-Xms512m -Xmx512m" -d -p 9201:9201 -p 9301:9301 -v /usr/local/es/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml  -v /usr/local/es/plugins2:/usr/share/elasticsearch/plugins    -v /usr/local/es/data2:/usr/share/elasticsearch/data --name ES02 elasticsearch

测试:http://192.168.112.150:9200/_cat/nodes?pretty
在这里插入图片描述

Kibana连接ES集群:

docker run -it -d -e ELASTICSEARCH_URL=http://127.0.0.1:9200 --name kibana --network=container:ES01 kibana

访问:http://192.168.112.150:5601/
基于Docker搭建Elasticsearch集群_第1张图片

你可能感兴趣的:(Docker,ELK,Linux,docker安装es集群)