Docker搭建ES集群
Spring Boot连接ES,spring-boot-starter-data-elasticsearch。 必须为集群方式!否则报错!
报错:
None of the configured nodes are available
安装步骤: 进入 cd /home
1.mkdir -p es/config
2.cd es
3.mkdir data1
4.mkdir data2
5.mkdir data3
6.firewall-cmd --add-port=9300/tcp
7.firewall-cmd --add-port=9301/tcp
8.mkdir plugins1
9.mkdir plugins2
步骤解析:
1. 目录文件: 是用来挂载用的,同步配置文件。容器的和外部的同步。
3. 4. 5. 表示两个es外部挂载目录
6. 7. 防火墙设置
8. 9 存放分词插件
es1.yml
cluster.name: elasticsearch-cluster
node.name: es-node1
network.bind_host: 0.0.0.0
network.publish_host: 192.168.91.66
http.port: 9200
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.91.66:9300","192.168.91.66:9301"]
discovery.zen.minimum_master_nodes: 1
es2.yml:
cluster.name: elasticsearch-cluster
node.name: es-node2
network.bind_host: 0.0.0.0
network.publish_host: 192.168.91.66
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.91.66:9300","192.168.91.66:9301"]
discovery.zen.minimum_master_nodes: 1
步骤解析:
node.name: es-node1 集群中保证唯一
discovery.zen.minimum_master_nodes: 1 master节点有1个
伪集群的方式,两个配置文件这里是不一样的: 通过端口号区别不同的ES
http.port: 9200
transport.tcp.port: 9300
将上述两个配置文件放入到:es/config
启动:
容器1:
便于看:
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 -p 5601:5601
-v /home/es/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml
-v /home/es/plugins1:/usr/share/elasticsearch/plugins
-v /home/es/data1:/usr/share/elasticsearch/data --name ES01 elasticsearch
应该这样运行: 格式化
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9200:9200 -p 9300:9300 -p 5601:5601 -v /home/es/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /home/es/plugins1:/usr/share/elasticsearch/plugins -v /home/es/data1:/usr/share/elasticsearch/data --name ES01 elasticsearch
解析: 设置jvm内存 端口号 挂载
容器2:
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9201:9201 -p 9301:9301
-v /home/es/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml
-v /home/es/plugins2:/usr/share/elasticsearch/plugins
-v /home/es/data2:/usr/share/elasticsearch/data --name ES02 elasticsearch
格式化指令:
docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9201:9201 -p 9301:9301 -v /home/es/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /home/es/plugins2:/usr/share/elasticsearch/plugins -v /home/es/data2:/usr/share/elasticsearch/data --name ES02 elasticsearch
注:如果ELK选的6.X版本的,那么需将data1 data2 data3 开启777权限=> chmod 777 data1 data2 data3
设置:
3.调高JVM线程数限制数量
在centos窗口中,修改配置sysctl.conf
vim /etc/sysctl.conf
加入如下内容:
vm.max_map_count=262144
启用配置:
sysctl -p
如果没有启动成功:
访问:
http://192.168.91.66:9200/_cat/nodes?pretty
可以参考:https://blog.csdn.net/belonghuang157405/article/details/83301937